Search in sources :

Example 1 with TOPIC

use of com.rabbitmq.client.BuiltinExchangeType.TOPIC in project quarkus-quickstarts by quarkusio.

the class QuoteProcessorTest method testProcessor.

@Test
void testProcessor() throws Exception {
    String quoteId = UUID.randomUUID().toString();
    Channel channel = getChannel();
    channel.exchangeDeclare("quotes", TOPIC, true, false, Map.of());
    String queue = channel.queueDeclare("quotes", true, false, false, Map.of()).getQueue();
    channel.queueBind(queue, "quotes", "#");
    AtomicReference<Quote> receivedQuote = new AtomicReference<>(null);
    DeliverCallback deliverCallback = (consumerTag, message) -> {
        Quote quote = objectMapper.readValue(message.getBody(), Quote.class);
        if (!Objects.equals(quote.id, quoteId)) {
            return;
        }
        receivedQuote.set(quote);
    };
    String consumerTag = channel.basicConsume(queue, true, deliverCallback, tag -> {
    });
    AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().contentType("text/plain").build();
    channel.basicPublish("quote-requests", quoteId, props, quoteId.getBytes(UTF_8));
    await().atMost(3, SECONDS).untilAtomic(receivedQuote, notNullValue());
    channel.basicCancel(consumerTag);
}
Also used : Quote(org.acme.rabbitmq.model.Quote) Awaitility.await(org.awaitility.Awaitility.await) DeliverCallback(com.rabbitmq.client.DeliverCallback) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TOPIC(com.rabbitmq.client.BuiltinExchangeType.TOPIC) UUID(java.util.UUID) Connection(com.rabbitmq.client.Connection) AtomicReference(java.util.concurrent.atomic.AtomicReference) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Map(java.util.Map) Channel(com.rabbitmq.client.Channel) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Quote(org.acme.rabbitmq.model.Quote) AMQP(com.rabbitmq.client.AMQP) AMQP(com.rabbitmq.client.AMQP) Channel(com.rabbitmq.client.Channel) AtomicReference(java.util.concurrent.atomic.AtomicReference) DeliverCallback(com.rabbitmq.client.DeliverCallback) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AMQP (com.rabbitmq.client.AMQP)1 TOPIC (com.rabbitmq.client.BuiltinExchangeType.TOPIC)1 Channel (com.rabbitmq.client.Channel)1 Connection (com.rabbitmq.client.Connection)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 DeliverCallback (com.rabbitmq.client.DeliverCallback)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Map (java.util.Map)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Quote (org.acme.rabbitmq.model.Quote)1 Awaitility.await (org.awaitility.Awaitility.await)1 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)1 Test (org.junit.jupiter.api.Test)1