Example usage for com.rabbitmq.client Consumer handleDelivery

List of usage examples for com.rabbitmq.client Consumer handleDelivery

Introduction

In this page you can find the example usage for com.rabbitmq.client Consumer handleDelivery.

Prototype

void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
        throws IOException;

Source Link

Document

Called when a basic.deliver is received for this consumer.

Usage

From source file:com.streamsets.pipeline.stage.origin.rabbitmq.TestStreamSetsMessageConsumer.java

License:Apache License

@Test
public void testConsumerSingleMessage() throws Exception {
    TransferQueue<RabbitMessage> messages = new LinkedTransferQueue<>();

    DataParserFactory parserFactory = new DataParserFactoryBuilder(context, DataParserFormat.JSON)
            .setCharset(StandardCharsets.UTF_8).setMode(JsonMode.MULTIPLE_OBJECTS).setMaxDataLen(-1).build();

    Channel channel = mock(Channel.class);

    final Consumer consumer = new StreamSetsMessageConsumer(channel, messages);
    final Envelope envelope = new Envelope(1L, false, EXCHANGE_NAME, QUEUE_NAME);

    executor.submit(new Runnable() {
        @Override//from  w w  w  .j av a 2s. c o m
        public void run() {
            try {
                consumer.handleDelivery("consumerTag", envelope, null, TEST_MESSAGE_1.getBytes());
            } catch (IOException ignored) {
                // no op
            }
        }
    });

    RabbitMessage message = messages.take();
    assertEquals(TEST_MESSAGE_1, new String(message.getBody(), StandardCharsets.UTF_8));
}