Package com.mayam.wf.mq
Interface Mq
public interface Mq
Message queue abstraction with retry and replay functionality.
mq.attachListener(MqDestination.of("queue://mayam.task.test"), new Mq.Listener() { public void onMessage(MqMessage message) throws InvalidMessageException { final AttributeMap subject = message.getSubject(); final Long taskId = subject.getAttribute(Attribute.TASK_ID); ... } }); while (isRunning()) { mq.listen(ListenIntensity.RELAXED); } mq.shutdownConsumers();NOTE: Only one listener per destination is currently fully supported. Acknowledge messages are sent as soon a related listener has successfully processed (and possibly ignored) a message.
- Author:
- Markus MÃ¥rtensson
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Returned byattachListener(MqDestination, Listener)
, itsMq.Detachable.detach()
method allows a callback to be removed.static interface
Callback for use withattachListener(MqDestination, Listener)
.static enum
The intensity with which listening should be performed. -
Method Summary
Modifier and TypeMethodDescriptionattachListener
(MqDestination source, Mq.Listener callback) Attach a listener to a specified queue or topic.void
listen()
Listen for messages using default intensity, passing them to all registeredMq.Listener
callbacks.void
listen
(Mq.ListenIntensity intensity) Listen for messages using specified intensity, passing them to all registeredMq.Listener
callbacks.void
ping()
Sends a ping message to Mq to make sure it's alivevoid
send
(MqDestination destination, MqMessage msg) Send aMqMessage
to a given queue or topic.void
sendVolatile
(MqDestination destination, MqMessage msg) Send aMqMessage
to a given queue or topic.void
Shuts down connection and cleans up any objects related to receiving messages within the current thread.void
Shuts down connection and cleans up any objects related to sending messages within the current thread.
-
Method Details
-
send
Send aMqMessage
to a given queue or topic. If the message could not be sent, it will be made available via theReplayStore
.- Parameters:
destination
- queue or topic to use as destination.msg
- the message to be sent.- Throws:
MqException
- if the message could not be sent.
-
sendVolatile
Send aMqMessage
to a given queue or topic. If the message could not be sent, it will be discarded and no exception will be thrown.- Parameters:
destination
- queue or topic to use as destination.msg
- the message to be sent.
-
listen
void listen()Listen for messages using default intensity, passing them to all registeredMq.Listener
callbacks. -
listen
Listen for messages using specified intensity, passing them to all registeredMq.Listener
callbacks.- Parameters:
intensity
-
-
attachListener
Attach a listener to a specified queue or topic.- Parameters:
source
- queue or topic to listen to.callback
- called by listen() when a matching message is found.- Returns:
- a
Mq.Detachable
object allowing the listener to detach itself.
-
shutdownProducers
void shutdownProducers()Shuts down connection and cleans up any objects related to sending messages within the current thread. -
shutdownConsumers
void shutdownConsumers()Shuts down connection and cleans up any objects related to receiving messages within the current thread. -
ping
Sends a ping message to Mq to make sure it's alive- Throws:
MqException
-