T - the type of object that is expected by the update(java.lang.String, T, com.diffusiondata.gateway.framework.TopicProperties) method.
This should match the type that is output by the
payload converter in use for the
service.public interface SinkHandler<T> extends ServiceHandler
A sink handler receives updates from the framework via its update method. A sink handler will only receive updates when the service is
in an ACTIVE state.
A sink handler will not receive updates until the start method has been called. It will also not receive updates if the
pause method has been called and updates will
not resume until the resume method is called.
An object that implements this interface must be returned when the
GatewayApplication.addSink method is
called. A different object must be returned for each different service. The
object must implement the update method to publish any
update(s) received from the framework to the back end sink.
The handler may also optionally return service
specific properties via its getSinkServiceProperties() method. If it
does not then defaults will be assumed.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
SinkHandler.SinkServiceProperties
The service properties that apply to the sink service.
|
static class |
SinkHandler.UnsubscriptionReason
The reason for an unsubscription from a Diffusion topic.
|
ServiceHandler.PauseReason, ServiceHandler.ResumeReason| Modifier and Type | Method and Description |
|---|---|
default SinkHandler.SinkServiceProperties |
getSinkServiceProperties()
This is used to set topic-specific properties for topics consumed by this
service.
|
default CompletableFuture<?> |
onSubscription(String topicPath,
TopicProperties topicProperties)
Called when the sink service is subscribed to a Diffusion topic.
|
default CompletableFuture<?> |
onUnsubscription(String topicPath,
TopicProperties topicProperties,
SinkHandler.UnsubscriptionReason reason)
Called when the sink service is unsubscribed from a Diffusion topic.
|
CompletableFuture<?> |
update(String path,
T value,
TopicProperties topicProperties)
Called by the framework to publish a new value received from Diffusion to
the sink.
|
Class<T> |
valueType()
Class of the value expected by this handler.
|
pause, resume, start, stopdefault SinkHandler.SinkServiceProperties getSinkServiceProperties() throws InvalidConfigurationException
Properties can be built using a
builder which can be created using
DiffusionGatewayFramework.newSinkServicePropertiesBuilder().
The default implementation returns null, which means that all defaults
are assumed for service properties. See the methods of
SinkHandler.SinkServiceProperties.Builder for details about defaults.
InvalidConfigurationException - possibly thrown by
SinkHandler.SinkServiceProperties.BuilderCompletableFuture<?> update(String path, T value, TopicProperties topicProperties)
One or more payload converters defined for the service
will have been applied to the Diffusion value received from the topic to produce the sink
specific value.
path - the path of the Diffusion topic from where the value has been
receivedvalue - the final value to publish to the sink. This value could
be of different type from the type of the Diffusion topic
as it could have been converted using a convertertopicProperties - the properties of the Diffusion topic from which the
value has been receivedIf the update completes successfully, the CompletableFuture result should be null. The result type is any rather than Void to provide forward compatibility with future iterations of this API that may provide a non-null result with a more specific result type.
If the future completes exceptionally or the future fails to
complete within the timeout specified in the configuration, the
framework will pause the service. If
the method throws an exception, it will be logged but the service
will not be paused.
default CompletableFuture<?> onSubscription(String topicPath, TopicProperties topicProperties)
This can be used to perform any required operations when a subscription to a Diffusion topic occurs.
topicPath - the Diffusion topic pathtopicProperties - the Diffusion topic propertiesIf it completes successfully, the CompletableFuture result should be null. The result type is any rather than Void to provide forward compatibility with future iterations of this API that may provide a non-null result with a more specific result type.
If the future completes exceptionally or throws an exception, it will be logged by the framework.
default CompletableFuture<?> onUnsubscription(String topicPath, TopicProperties topicProperties, SinkHandler.UnsubscriptionReason reason)
This can be used to perform any required operations when an unsubscription from a Diffusion topic occurs.
topicPath - the Diffusion topic pathtopicProperties - the Diffusion topic propertiesreason - the reason for unsubscriptionIf it completes successfully, the CompletableFuture result should be null. The result type is any rather than Void to provide forward compatibility with future iterations of this API that may provide a non-null result with a more specific result type.
If the future completes exceptionally or throws an exception, it will be logged by the framework.
Copyright © 2025 DiffusionData Limited. All rights reserved.