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 Summary
ConstructorsConstructorDescriptionRabbitConsumer
(int pollPeriod, BlockingQueue<Event<T>> events, T consumerImpl) Create a new RabbitConsumer. -
Method Summary
Modifier and TypeMethodDescriptiongetDeliverEvent
(com.rabbitmq.client.Envelope envelope, byte[] data, Map<String, Object> headers) Get a new delivery event for internal handling of new messagesvoid
handleCancel
(String consumerTag) void
handleCancelOk
(String consumerTag) void
handleConsumeOk
(String consumerTag) final void
handleDelivery
(String consumerTag, com.rabbitmq.client.Envelope envelope, com.rabbitmq.client.AMQP.BasicProperties properties, byte[] body) void
handleRecoverOk
(String consumerTag) void
handleShutdownSignal
(String consumerTag, com.rabbitmq.client.ShutdownSignalException sig) Methods inherited from class com.github.workerframework.util.rabbitmq.EventPoller
getEventQueue, run, shutdown
-
Constructor Details
-
RabbitConsumer
Create a new RabbitConsumer.- Parameters:
pollPeriod
- the polling period to look for eventsevents
- the object to use for storing and polling eventsconsumerImpl
- 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 interfacecom.rabbitmq.client.Consumer
-
handleCancel
- Specified by:
handleCancel
in interfacecom.rabbitmq.client.Consumer
- Throws:
IOException
-
handleCancelOk
- Specified by:
handleCancelOk
in interfacecom.rabbitmq.client.Consumer
-
handleConsumeOk
- Specified by:
handleConsumeOk
in interfacecom.rabbitmq.client.Consumer
-
handleRecoverOk
- Specified by:
handleRecoverOk
in interfacecom.rabbitmq.client.Consumer
-
handleShutdownSignal
public void handleShutdownSignal(String consumerTag, com.rabbitmq.client.ShutdownSignalException sig) - Specified by:
handleShutdownSignal
in interfacecom.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 deliverydata
- the actual message deliveryheaders
- the message headers- Returns:
- an instance of this implementation's QueueEvent indicating a delivery
-