Example usage for com.rabbitmq.client Consumer handleConsumeOk

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

Introduction

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

Prototype

void handleConsumeOk(String consumerTag);

Source Link

Document

Called when the consumer is registered by a call to any of the Channel#basicConsume methods.

Usage

From source file:com.github.larsq.spring.embeddedamqp.SimpleAmqpMessageContainer.java

License:Open Source License

public String subscribe(SimpleAmqpConnectionFactory.ChannelImpl impl, String consumerTag, String queue,
        Consumer callback) throws IOException {
    LOG.debug("subscribe impl={}, tag={}, queue={}", impl, consumerTag, queue);

    Queue q = queue(queue).orElseThrow(Exception.queueNotFound(queue));

    String tag = Optional.ofNullable(consumerTag).filter(isEqual("").negate())
            .orElse(UUID.randomUUID().toString());

    unsubscribe(consumerTag);//from w  w w .jav a  2s . co m

    List<AbstractSubscription<Consumer>> subscriptions = consumers.computeIfAbsent(q, __ -> new ArrayList<>());

    ConsumerSubscription subscription = new ConsumerSubscription(ChannelWrapper.wrap(impl), tag, callback);
    subscriptions.add(subscription);

    callback.handleConsumeOk(consumerTag);

    return tag;
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerTests.java

License:Apache License

@SuppressWarnings("unchecked")
protected void setupMockConsume(Channel channel, final List<Consumer> consumers,
        final AtomicInteger consumerTag, final CountDownLatch latch) throws IOException {
    doAnswer(new Answer<Object>() {

        @Override/*from   w  w  w . ja va  2 s . c o m*/
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Consumer cons = (Consumer) invocation.getArguments()[6];
            consumers.add(cons);
            cons.handleConsumeOk(String.valueOf(consumerTag.getAndIncrement()));
            latch.countDown();
            return null;
        }
    }).when(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(),
            any(Consumer.class));
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainerTests.java

License:Apache License

private Answer<Object> messageToConsumer(final Channel mockChannel,
        final SimpleMessageListenerContainer container, final boolean cancel, final CountDownLatch latch) {
    return new Answer<Object>() {

        @Override/*from ww w .j  a va  2 s. com*/
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Set<?> consumers = TestUtils.getPropertyValue(container, "consumers", Map.class).keySet();
            for (Object consumer : consumers) {
                ChannelProxy channel = TestUtils.getPropertyValue(consumer, "channel", ChannelProxy.class);
                if (channel != null && channel.getTargetChannel() == mockChannel) {
                    Consumer rabbitConsumer = TestUtils.getPropertyValue(consumer, "consumer", Consumer.class);
                    if (cancel) {
                        rabbitConsumer.handleCancelOk((String) invocation.getArguments()[0]);
                    } else {
                        rabbitConsumer.handleConsumeOk("foo");
                    }
                    latch.countDown();
                }
            }
            return null;
        }
    };

}