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
  • Method Details

    • send

      void send(MqDestination destination, MqMessage msg) throws MqException
      Send a MqMessage to a given queue or topic. If the message could not be sent, it will be made available via the ReplayStore.
      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

      void sendVolatile(MqDestination destination, MqMessage msg)
      Send a MqMessage 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 registered Mq.Listener callbacks.
    • listen

      void listen(Mq.ListenIntensity intensity)
      Listen for messages using specified intensity, passing them to all registered Mq.Listener callbacks.
      Parameters:
      intensity -
    • attachListener

      Mq.Detachable attachListener(MqDestination source, Mq.Listener callback)
      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

      void ping() throws MqException
      Sends a ping message to Mq to make sure it's alive
      Throws:
      MqException