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 messagesvoidhandleCancel(String consumerTag) voidhandleCancelOk(String consumerTag) voidhandleConsumeOk(String consumerTag) final voidhandleDelivery(String consumerTag, com.rabbitmq.client.Envelope envelope, com.rabbitmq.client.AMQP.BasicProperties properties, byte[] body) voidhandleRecoverOk(String consumerTag) voidhandleShutdownSignal(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:
handleDeliveryin interfacecom.rabbitmq.client.Consumer
-
handleCancel
- Specified by:
handleCancelin interfacecom.rabbitmq.client.Consumer- Throws:
IOException
-
handleCancelOk
- Specified by:
handleCancelOkin interfacecom.rabbitmq.client.Consumer
-
handleConsumeOk
- Specified by:
handleConsumeOkin interfacecom.rabbitmq.client.Consumer
-
handleRecoverOk
- Specified by:
handleRecoverOkin interfacecom.rabbitmq.client.Consumer
-
handleShutdownSignal
public void handleShutdownSignal(String consumerTag, com.rabbitmq.client.ShutdownSignalException sig) - Specified by:
handleShutdownSignalin 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
-