Search in sources :

Example 41 with Message

use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.

the class AMQPObservableQueueTest method testPublishMessagesToExchangeAndDefaultConfiguration.

private void testPublishMessagesToExchangeAndDefaultConfiguration(Channel channel, Connection connection, boolean exists, boolean useWorkingChannel) throws IOException, TimeoutException {
    final Random random = new Random();
    final String name = RandomStringUtils.randomAlphabetic(30), type = "topic", queueName = RandomStringUtils.randomAlphabetic(30), routingKey = RandomStringUtils.randomAlphabetic(30);
    final AMQPSettings settings = new AMQPSettings(configuration).fromURI("amqp_exchange:" + name + "?exchangeType=" + type + "&routingKey=" + routingKey + "&deliveryMode=2&durable=true&exclusive=false&autoDelete=true");
    assertEquals(true, settings.isDurable());
    assertEquals(false, settings.isExclusive());
    assertEquals(true, settings.autoDelete());
    assertEquals(2, settings.getDeliveryMode());
    assertEquals(name, settings.getQueueOrExchangeName());
    assertEquals(type, settings.getExchangeType());
    assertEquals(routingKey, settings.getRoutingKey());
    List<GetResponse> queue = buildQueue(random, batchSize);
    channel = mockChannelForExchange(channel, useWorkingChannel, exists, queueName, name, type, routingKey, queue);
    AMQPObservableQueue observableQueue = new AMQPObservableQueue(mockConnectionFactory(connection), addresses, true, settings, batchSize, pollTimeMs);
    assertArrayEquals(addresses, observableQueue.getAddresses());
    assertEquals(AMQPConstants.AMQP_EXCHANGE_TYPE, observableQueue.getType());
    assertEquals(AMQPConstants.AMQP_EXCHANGE_TYPE + ":" + name + "?exchangeType=" + type + "&routingKey=" + routingKey + "&deliveryMode=2&durable=true&exclusive=false&autoDelete=true", observableQueue.getName());
    assertEquals(name, observableQueue.getURI());
    assertEquals(batchSize, observableQueue.getBatchSize());
    assertEquals(pollTimeMs, observableQueue.getPollTimeInMS());
    assertEquals(queue.size(), observableQueue.size());
    List<Message> messages = new LinkedList<>();
    Observable.range(0, batchSize).forEach((Integer x) -> messages.add(new Message("" + x, "payload: " + x, null)));
    assertEquals(batchSize, messages.size());
    observableQueue.publish(messages);
    if (useWorkingChannel) {
        verify(channel, times(batchSize)).basicPublish(eq(name), eq(routingKey), any(AMQP.BasicProperties.class), any(byte[].class));
    }
}
Also used : Random(java.util.Random) Message(com.netflix.conductor.core.events.queue.Message) GetResponse(com.rabbitmq.client.GetResponse) LinkedList(java.util.LinkedList)

Example 42 with Message

use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.

the class AMQPObservableQueueTest method testAck.

@Test
public void testAck() throws IOException, TimeoutException {
    // Mock channel and connection
    Channel channel = mockBaseChannel();
    Connection connection = mockGoodConnection(channel);
    final Random random = new Random();
    final String name = RandomStringUtils.randomAlphabetic(30), type = "topic", routingKey = RandomStringUtils.randomAlphabetic(30);
    final AMQPSettings settings = new AMQPSettings(configuration).fromURI("amqp_exchange:" + name + "?exchangeType=" + type + "&routingKey=" + routingKey);
    AMQPObservableQueue observableQueue = new AMQPObservableQueue(mockConnectionFactory(connection), addresses, true, settings, batchSize, pollTimeMs);
    List<Message> messages = new LinkedList<>();
    Message msg = new Message();
    msg.setId("0e3eef8f-ebb1-4244-9665-759ab5bdf433");
    msg.setPayload("Payload");
    msg.setReceipt("1");
    messages.add(msg);
    List<String> deliveredTags = observableQueue.ack(messages);
    assertNotNull(deliveredTags);
}
Also used : Random(java.util.Random) Message(com.netflix.conductor.core.events.queue.Message) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Message (com.netflix.conductor.core.events.queue.Message)42 ArrayList (java.util.ArrayList)18 Test (org.junit.Test)16 LinkedList (java.util.LinkedList)12 List (java.util.List)11 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)10 HashMap (java.util.HashMap)10 Collections (java.util.Collections)9 Map (java.util.Map)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Connection (java.sql.Connection)7 Executors (java.util.concurrent.Executors)7 Task (com.netflix.conductor.common.metadata.tasks.Task)6 TimeUnit (java.util.concurrent.TimeUnit)6 Workflow (com.netflix.conductor.common.run.Workflow)5 QueueDAO (com.netflix.conductor.dao.QueueDAO)5 Collectors (java.util.stream.Collectors)5 SearchHit (org.elasticsearch.search.SearchHit)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5