Class RabbitConsumer<T>

java.lang.Object
com.github.workerframework.util.rabbitmq.EventPoller<T>
com.github.workerframework.util.rabbitmq.RabbitConsumer<T>
All Implemented Interfaces:
com.rabbitmq.client.Consumer, Runnable
Direct Known Subclasses:
DefaultRabbitConsumer

public abstract class RabbitConsumer<T> extends EventPoller<T> implements com.rabbitmq.client.Consumer
A basic framework for handling consumption of messages from a RabbitMQ queue. It decouples the RabbitMQ client threads delivering messages from the handling and dispatching of these messages.
  • Constructor Details

    • RabbitConsumer

      public RabbitConsumer(int pollPeriod, BlockingQueue<Event<T>> events, T consumerImpl)
      Create a new RabbitConsumer.
      Parameters:
      pollPeriod - the polling period to look for events
      events - the object to use for storing and polling events
      consumerImpl - the event handler implementation
  • Method Details

    • handleDelivery

      public final void handleDelivery(String consumerTag, com.rabbitmq.client.Envelope envelope, com.rabbitmq.client.AMQP.BasicProperties properties, byte[] body)
      Specified by:
      handleDelivery in interface com.rabbitmq.client.Consumer
    • handleCancel

      public void handleCancel(String consumerTag) throws IOException
      Specified by:
      handleCancel in interface com.rabbitmq.client.Consumer
      Throws:
      IOException
    • handleCancelOk

      public void handleCancelOk(String consumerTag)
      Specified by:
      handleCancelOk in interface com.rabbitmq.client.Consumer
    • handleConsumeOk

      public void handleConsumeOk(String consumerTag)
      Specified by:
      handleConsumeOk in interface com.rabbitmq.client.Consumer
    • handleRecoverOk

      public void handleRecoverOk(String consumerTag)
      Specified by:
      handleRecoverOk in interface com.rabbitmq.client.Consumer
    • handleShutdownSignal

      public void handleShutdownSignal(String consumerTag, com.rabbitmq.client.ShutdownSignalException sig)
      Specified by:
      handleShutdownSignal in interface com.rabbitmq.client.Consumer
    • getDeliverEvent

      protected abstract Event<T> getDeliverEvent(com.rabbitmq.client.Envelope envelope, byte[] data, Map<String,Object> headers)
      Get a new delivery event for internal handling of new messages
      Parameters:
      envelope - the envelope, containing metadata about the message delivery
      data - the actual message delivery
      headers - the message headers
      Returns:
      an instance of this implementation's QueueEvent indicating a delivery