Class DelegateMessageQueueReceiverEndpoint
- java.lang.Object
-
- de.otto.synapse.endpoint.receiver.DelegateMessageQueueReceiverEndpoint
-
- All Implemented Interfaces:
MessageEndpoint,MessageQueueReceiverEndpoint,MessageReceiverEndpoint
public class DelegateMessageQueueReceiverEndpoint extends java.lang.Object implements MessageQueueReceiverEndpoint
-
-
Constructor Summary
Constructors Constructor Description DelegateMessageQueueReceiverEndpoint(java.lang.String channelName, MessageQueueReceiverEndpointFactory messageQueueReceiverEndpointFactory)
-
Method Summary
Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Void>consume()Takes zero or more messages from the channel, callsMessageEndpoint.intercept(TextMessage)for every message, and notifies the registered consumers with the intercepted message, or drops the message, ifinterceptreturns null.java.lang.StringgetChannelName()Returns the name of the channel.EndpointTypegetEndpointType()InterceptorChaingetInterceptorChain()Returns theInterceptorChainof theMessageEndpoint.MessageDispatchergetMessageDispatcher()Returns the MessageDispatcher that is used to dispatch messages.TextMessageintercept(TextMessage message)Intercepts a message using all registered interceptors and returns the resulting message.voidregister(MessageConsumer<?> messageConsumer)Registers a MessageConsumer at the receiver endpoint.voidstop()Stops consumption of messages and shuts down theMessageQueueReceiverEndpoint.
-
-
-
Constructor Detail
-
DelegateMessageQueueReceiverEndpoint
public DelegateMessageQueueReceiverEndpoint(@Nonnull java.lang.String channelName, @Nonnull MessageQueueReceiverEndpointFactory messageQueueReceiverEndpointFactory)
-
-
Method Detail
-
consume
public java.util.concurrent.CompletableFuture<java.lang.Void> consume()
Description copied from interface:MessageQueueReceiverEndpointTakes zero or more messages from the channel, callsMessageEndpoint.intercept(TextMessage)for every message, and notifies the registered consumers with the intercepted message, or drops the message, ifinterceptreturns null.Consumption starts with the earliest available and not-yet-consumed message and finishes when either the
stopConditionis met, or the application is shutting down.The
registeredconsumersare used as a callback for consumed messages. AMessageDispatchercan be used as a consumer, if multiple consumers, or consumers withmessage payloadsother thanStringare required.- Specified by:
consumein interfaceMessageQueueReceiverEndpoint- Returns:
- completable future that can be used to
waituntil the endpoint has stopped message consumption.
-
stop
public void stop()
Description copied from interface:MessageQueueReceiverEndpointStops consumption of messages and shuts down theMessageQueueReceiverEndpoint.- Specified by:
stopin interfaceMessageQueueReceiverEndpoint
-
register
public void register(MessageConsumer<?> messageConsumer)
Description copied from interface:MessageReceiverEndpointRegisters a MessageConsumer at the receiver endpoint.consumershave to be thread safe as they might be called from multiple threads in parallel (e.g. for kinesis streams there is one thread per shard).- Specified by:
registerin interfaceMessageReceiverEndpoint- Parameters:
messageConsumer- registered EventConsumer
-
getMessageDispatcher
@Nonnull public MessageDispatcher getMessageDispatcher()
Description copied from interface:MessageReceiverEndpointReturns the MessageDispatcher that is used to dispatch messages.- Specified by:
getMessageDispatcherin interfaceMessageReceiverEndpoint- Returns:
- MessageDispatcher
-
getChannelName
@Nonnull public java.lang.String getChannelName()
Description copied from interface:MessageEndpointReturns the name of the channel.The channel name corresponds to the name of the underlying stream, queue or message log.
- Specified by:
getChannelNamein interfaceMessageEndpoint- Returns:
- name of the channel
-
getInterceptorChain
@Nonnull public InterceptorChain getInterceptorChain()
Description copied from interface:MessageEndpointReturns theInterceptorChainof theMessageEndpoint.- Specified by:
getInterceptorChainin interfaceMessageEndpoint- Returns:
- InterceptorChain
-
getEndpointType
@Nonnull public EndpointType getEndpointType()
Description copied from interface:MessageEndpoint- Specified by:
getEndpointTypein interfaceMessageEndpoint- Returns:
- EndpointType
-
intercept
@Nullable public TextMessage intercept(@Nonnull TextMessage message)
Description copied from interface:MessageEndpointIntercepts a message using all registered interceptors and returns the resulting message.The interceptors are called in order. The result of one interceptor is propagated to the next interceptor in the chain, until the end of the chain is reached, or one interceptor has returned null.
If
nullis returned, the message must be dropped by theAbstractMessageEndpoint.Every interceptor may transform the message, or may take additional actions like, for example, logging, monitoring or other things.
- Specified by:
interceptin interfaceMessageEndpoint- Parameters:
message- the message to intercept- Returns:
- the (possibly modified) message, or null if the message should be dropped.
-
-