@ProviderType public interface DirectMessageReceiver extends MessageReceiver, ReceiverSubscriptions, AsyncReceiverSubscriptions
Note: A caller of any of blocking message receiving methods without the 'async' suffix, such
as receiveMessage()
will receive a new message for each call in a sequence.
Warning:
Co-usage of asynchronous and blocking message receiving methods on a single instance of receiver can have unexpected side-effects and must be avoided.
Asynchronous (Async*
) methods must not be called multiple times or in combination
with blocking, message receiving method on a same instance of a MessageReceiver
to avoid
unexpected side-effects.
MessageReceiver.FailedReceiveEvent, MessageReceiver.InboundMessageSupplier, MessageReceiver.MessageHandler, MessageReceiver.ReceiveFailureListener
LifecycleControl.TerminationEvent, LifecycleControl.TerminationNotificationListener
ManageableReceiver.DirectReceiverInfo, ManageableReceiver.PersistentReceiverInfo
AsyncReceiverSubscriptions.SubscriptionChangeListener
Modifier and Type | Method and Description |
---|---|
void |
receiveAsync(MessageReceiver.MessageHandler messageHandler)
Request to register an async message handler.
|
void |
receiveAsync(MessageReceiver.MessageHandler messageHandler,
ExecutorService executorService)
Request to register an asynchronous message handler using supplied thread executor for
callbacks.
|
InboundMessage |
receiveMessage()
Receive the next message.
|
InboundMessage |
receiveMessage(long timeOut)
Receive the next message.
|
InboundMessage |
receiveOrElse(MessageReceiver.InboundMessageSupplier supplierOfAlternativeResponse)
Request to receive a next message, when no message available, the specified supplier is used to
generate a response.
|
ManageableReceiver.DirectReceiverInfo |
receiverInfo()
Provides access to the receiver information.
|
DirectMessageReceiver |
start()
Enables service regular duties.
|
<DirectMessageReceiver> |
startAsync()
Asynchronously starts service for consuming/publishing operations.
|
<DirectMessageReceiver> |
startAsync(CompletionListener<DirectMessageReceiver> startListener)
Asynchronously starts service for consuming/publishing operations using a callback for
completion notification.
|
setReceiveFailureListener
isRunning, isTerminated, isTerminating, setTerminationNotificationListener, terminate
terminateAsync, terminateAsync
addSubscription, removeSubscription
addSubscriptionAsync, removeSubscriptionAsync
void receiveAsync(MessageReceiver.MessageHandler messageHandler) throws PubSubPlusClientException
This method represents push- based non blocking interface. Callback method of a message handler will be executed on an internal API thread.
Note: usage of receiveAsync
method is CURRENTLY mutually exclusive with a non async
methods receiveMessage
and can be used once only
messageHandler
- the message handler, to handle an ordered sequence of inbound messagesPubSubPlusClientException
- is thrown when messages handler can't be registeredvoid receiveAsync(MessageReceiver.MessageHandler messageHandler, ExecutorService executorService) throws PubSubPlusClientException
Note: usage of receiveAsync
method is CURRENTLY mutually exclusive with a non async
methods receiveMessage
and can be used once only
messageHandler
- the message handler to handle the sequence of inbound messagesexecutorService
- the user-provided instance of thread executor for message scheduling and
MessageReceiver.MessageHandler.onMessage(InboundMessage)
execution
Important:
The shutdown of the Executor service or any another maintenance work is the responsibility of the developer
When the order of the messages needs to be preserved, a single thread-based executor is required
PubSubPlusClientException
- if the messages handler cannot be registeredInboundMessage receiveMessage() throws PubSubPlusClientException, PubSubPlusClientException.RequestInterruptedException
PubSubPlusClientException
- if the message could not be receivedPubSubPlusClientException.RequestInterruptedException
- if the thread is interrupted while waiting for the next
message; an interrupted flag is expected to be set on the
thread in this caseInboundMessage receiveMessage(long timeOut) throws PubSubPlusClientException, PubSubPlusClientException.RequestInterruptedException
timeOut
- the timeout (in milliseconds) after the blocking receive exits, values > 0 are expected, use receiveOrElse (..)
method when the immediate
response is requirednull
, when no new message could be received and a
timeout occurredPubSubPlusClientException
- if the message could not be receivedPubSubPlusClientException.RequestInterruptedException
- if the thread was interrupted while waiting for the next
message; an interrupted flag is expected to be set on the
thread in this caseInboundMessage receiveOrElse(MessageReceiver.InboundMessageSupplier supplierOfAlternativeResponse)
supplierOfAlternativeResponse
- the alternative response if no new message is availableManageableReceiver.DirectReceiverInfo receiverInfo()
ManageableReceiver
receiverInfo
in interface ManageableReceiver
ReceiverInfo
object that represents message receiver manageability.DirectMessageReceiver start() throws PubSubPlusClientException, IllegalStateException
LifecycleControl
start
in interface LifecycleControl
start
in interface MessageReceiver
PubSubPlusClientException
- if the instance fails to start for some internal reasonIllegalStateException
- if the instance was previously terminated, being terminated,
or the method has been invoked at an illegal or at an
inappropriate time for some another reason<DirectMessageReceiver> CompletableFuture<DirectMessageReceiver> startAsync() throws PubSubPlusClientException, IllegalStateException
AsyncLifecycleControl
This method is an idempotent operation when no another connect/disconnect operation is ongoing.
startAsync
in interface AsyncLifecycleControl
startAsync
in interface MessageReceiver
PubSubPlusClientException
- if the messaging service will not start in the futureIllegalStateException
- if the method has been invoked at an illegal or inappropriate
time<DirectMessageReceiver> void startAsync(CompletionListener<DirectMessageReceiver> startListener) throws PubSubPlusClientException, IllegalStateException
AsyncLifecycleControl
startAsync
in interface AsyncLifecycleControl
DirectMessageReceiver
- the type of response returned on a successful start operationstartListener
- the callback for future notifications about the completion of the start
processPubSubPlusClientException
- if the messaging service will not start in the futureIllegalStateException
- if the method has been invoked at an illegal or inappropriate
timeCopyright 2019-2024 Solace Corporation. All rights reserved.