E
- topic event typepublic interface ReliableMessageListener<E> extends MessageListener<E>
MessageListener
to better integrate with the reliable topic.
If a regular MessageListener is registered on a reliable topic, the message listener works fine, but it can't do much more than listen to messages.
If a ReliableMessageListener is registered on a normal topic, only the
MessageListener
methods will be called.
isTerminal(Throwable)
method.
If a plain MessageListener is used, then it won't terminate on exceptions
and it will keep on running. But in some cases it is better to stop running.
isLossTolerant()
.
retrieveInitialSequence()
returns the stored
sequence, then an at-least-once delivery is implemented since the same
item is now being processed twice. To implement an at-most-once delivery
guarantee, add 1 to the stored sequence when the
retrieveInitialSequence()
is called.Modifier and Type | Method and Description |
---|---|
boolean |
isLossTolerant()
Checks if this ReliableMessageListener is able to deal with message loss.
|
boolean |
isTerminal(Throwable failure)
Checks if the ReliableMessageListener should be terminated based on an
exception thrown while calling
MessageListener.onMessage(Message) . |
long |
retrieveInitialSequence()
Retrieves the initial sequence from which this ReliableMessageListener
should start.
|
void |
storeSequence(long sequence)
Informs the ReliableMessageListener that it should store the sequence.
|
onMessage
long retrieveInitialSequence()
Return -1
if there is no initial sequence and you want to start
from the next published message.
If you intend to create a durable subscriber so you continue from where you stopped the previous time, load the previous sequence and add 1. If you don't add one, then you will be receiving the same message twice.
void storeSequence(long sequence)
sequence
- the sequenceboolean isLossTolerant()
If the ReliableMessageListener is not loss tolerant and the topic detects that there are missing messages, it will terminate the ReliableMessageListener.
true
if the ReliableMessageListener is tolerant towards losing messages.boolean isTerminal(Throwable failure)
MessageListener.onMessage(Message)
.failure
- the exception thrown while calling
MessageListener.onMessage(Message)
.true
if the ReliableMessageListener should terminate itself,
false
if it should keep on running.Copyright © 2023 Hazelcast, Inc.. All rights reserved.