Search in sources :

Example 6 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.

the class MessageOperationExecutorTest method shouldRetrieveMessageFromQueueAndPerformFunctionWhenChecksumMatches.

@Test
public void shouldRetrieveMessageFromQueueAndPerformFunctionWhenChecksumMatches() throws Exception {
    GetResponse response = mockDefaultGetResponse();
    when(channel.basicGet(DEFAULT_QUEUE_NAME, false)).thenReturn(response);
    sut.consumeMessageApplyFunctionAndAckknowlegeOnSuccess(DEFAULT_BROKER_NAME, DEFAULT_QUEUE_NAME, DEFAULT_CHECKSUM, function);
    verify(function).apply(channel, response);
    verify(channel).basicAck(DEFAULT_DELIVERY_TAG, false);
}
Also used : GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 7 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.

the class MessageOperationExecutorTest method shouldThrowExceptionWhenAckCannotBeSentAfterSuccessfulFunctionExecution.

@Test
public void shouldThrowExceptionWhenAckCannotBeSentAfterSuccessfulFunctionExecution() throws Exception {
    GetResponse getResponse = mockDefaultGetResponse();
    when(channel.basicGet(DEFAULT_QUEUE_NAME, false)).thenReturn(getResponse);
    when(messageChecksum.createFor(DEFAULT_BASIC_PROPERTIES, DEFAULT_PAYLOAD)).thenReturn(DEFAULT_CHECKSUM);
    IOException expectedException = new IOException();
    doThrow(expectedException).when(channel).basicAck(DEFAULT_DELIVERY_TAG, false);
    try {
        sut.consumeMessageApplyFunctionAndAckknowlegeOnSuccess(DEFAULT_BROKER_NAME, DEFAULT_QUEUE_NAME, DEFAULT_CHECKSUM, function);
    } catch (MessageOperationFailedException e) {
        assertSame(expectedException, e.getCause());
    }
    verify(messageChecksum).createFor(DEFAULT_BASIC_PROPERTIES, DEFAULT_PAYLOAD);
    verify(channel).basicGet(DEFAULT_QUEUE_NAME, false);
    verify(function).apply(channel, getResponse);
    verify(channel).basicAck(DEFAULT_DELIVERY_TAG, false);
    verifyNoMoreInteractions(channel);
}
Also used : IOException(java.io.IOException) GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 8 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-queue-management by gessnerfl.

the class MessageMapperTest method shouldMapAmqpBasicProperties.

@Test
public void shouldMapAmqpBasicProperties() {
    String contentType = "contentType";
    String contentEncoding = "contentEncoding";
    String headerKey = "headerKey";
    String headerValue = "headerValue";
    Map<String, Object> headers = new HashMap<>();
    headers.put(headerKey, headerValue);
    Integer deliveryMode = 12;
    Integer priority = 13;
    String correlationId = "correlationId";
    String replyTo = "replyTo";
    String expiration = "expiration";
    String messageId = "messageId";
    Date timestamp = new Date();
    String type = "type";
    String userId = "userId";
    String appId = "appId";
    String clusterId = "clusterId";
    AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
    when(basicProperties.getContentType()).thenReturn(contentType);
    when(basicProperties.getContentEncoding()).thenReturn(contentEncoding);
    when(basicProperties.getHeaders()).thenReturn(headers);
    when(basicProperties.getDeliveryMode()).thenReturn(deliveryMode);
    when(basicProperties.getPriority()).thenReturn(priority);
    when(basicProperties.getCorrelationId()).thenReturn(correlationId);
    when(basicProperties.getReplyTo()).thenReturn(replyTo);
    when(basicProperties.getExpiration()).thenReturn(expiration);
    when(basicProperties.getMessageId()).thenReturn(messageId);
    when(basicProperties.getTimestamp()).thenReturn(timestamp);
    when(basicProperties.getType()).thenReturn(type);
    when(basicProperties.getUserId()).thenReturn(userId);
    when(basicProperties.getAppId()).thenReturn(appId);
    when(basicProperties.getClusterId()).thenReturn(clusterId);
    Envelope envelope = mock(Envelope.class);
    GetResponse getResponse = mockResponse(envelope, basicProperties);
    Message result = sut.map(getResponse);
    BasicProperties basicPropertiesOfResult = result.getProperties();
    assertNotNull(basicPropertiesOfResult);
    assertEquals(contentType, basicPropertiesOfResult.getContentType());
    assertEquals(contentEncoding, basicPropertiesOfResult.getContentEncoding());
    assertThat(basicPropertiesOfResult.getHeaders().keySet(), Matchers.hasSize(1));
    assertThat(basicPropertiesOfResult.getHeaders(), Matchers.hasKey(headerKey));
    assertEquals(headerValue, basicPropertiesOfResult.getHeaders().get(headerKey));
    assertEquals(deliveryMode, basicPropertiesOfResult.getDeliveryMode());
    assertEquals(priority, basicPropertiesOfResult.getPriority());
    assertEquals(correlationId, basicPropertiesOfResult.getCorrelationId());
    assertEquals(replyTo, basicPropertiesOfResult.getReplyTo());
    assertEquals(expiration, basicPropertiesOfResult.getExpiration());
    assertEquals(messageId, basicPropertiesOfResult.getMessageId());
    assertEquals(timestamp, basicPropertiesOfResult.getTimestamp());
    assertEquals(type, basicPropertiesOfResult.getType());
    assertEquals(userId, basicPropertiesOfResult.getUserId());
    assertEquals(appId, basicPropertiesOfResult.getAppId());
    assertEquals(clusterId, basicPropertiesOfResult.getClusterId());
}
Also used : Message(de.gessnerfl.rabbitmq.queue.management.model.Message) AMQP(com.rabbitmq.client.AMQP) BasicProperties(de.gessnerfl.rabbitmq.queue.management.model.BasicProperties) LongString(com.rabbitmq.client.LongString) Envelope(com.rabbitmq.client.Envelope) GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 9 with GetResponse

use of com.rabbitmq.client.GetResponse in project spring-integration by spring-projects.

the class AmqpMessageSourceTests method testNackOrRequeue.

private void testNackOrRequeue(boolean requeue) throws IOException, TimeoutException {
    Channel channel = mock(Channel.class);
    willReturn(true).given(channel).isOpen();
    Envelope envelope = new Envelope(123L, false, "ex", "rk");
    BasicProperties props = new BasicProperties.Builder().build();
    GetResponse getResponse = new GetResponse(envelope, props, "bar".getBytes(), 0);
    willReturn(getResponse).given(channel).basicGet("foo", false);
    Connection connection = mock(Connection.class);
    willReturn(true).given(connection).isOpen();
    willReturn(channel).given(connection).createChannel();
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    willReturn(connection).given(connectionFactory).newConnection((ExecutorService) isNull(), anyString());
    CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory);
    AmqpMessageSource source = new AmqpMessageSource(ccf, "foo");
    Message<?> received = source.receive();
    verify(connection).createChannel();
    StaticMessageHeaderAccessor.getAcknowledgmentCallback(received).acknowledge(requeue ? Status.REQUEUE : Status.REJECT);
    verify(channel).basicReject(123L, requeue);
    verify(connection).createChannel();
    ccf.destroy();
    verify(channel).close();
    verify(connection).close(30000);
}
Also used : CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Envelope(com.rabbitmq.client.Envelope) GetResponse(com.rabbitmq.client.GetResponse)

Example 10 with GetResponse

use of com.rabbitmq.client.GetResponse in project spring-integration by spring-projects.

the class AmqpMessageSourceTests method testAck.

@Test
public void testAck() throws Exception {
    Channel channel = mock(Channel.class);
    willReturn(true).given(channel).isOpen();
    Envelope envelope = new Envelope(123L, false, "ex", "rk");
    BasicProperties props = new BasicProperties.Builder().build();
    GetResponse getResponse = new GetResponse(envelope, props, "bar".getBytes(), 0);
    willReturn(getResponse).given(channel).basicGet("foo", false);
    Connection connection = mock(Connection.class);
    willReturn(true).given(connection).isOpen();
    willReturn(channel).given(connection).createChannel();
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    willReturn(connection).given(connectionFactory).newConnection((ExecutorService) isNull(), anyString());
    CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory);
    AmqpMessageSource source = new AmqpMessageSource(ccf, "foo");
    source.setRawMessageHeader(true);
    Message<?> received = source.receive();
    assertThat(received.getHeaders().get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE), instanceOf(org.springframework.amqp.core.Message.class));
    assertThat(received.getHeaders().get(AmqpHeaders.CONSUMER_QUEUE), equalTo("foo"));
    // make sure channel is not cached
    org.springframework.amqp.rabbit.connection.Connection conn = ccf.createConnection();
    // should not have been "closed"
    Channel notCached = conn.createChannel(false);
    verify(connection, times(2)).createChannel();
    StaticMessageHeaderAccessor.getAcknowledgmentCallback(received).acknowledge(Status.ACCEPT);
    verify(channel).basicAck(123L, false);
    // should have been "closed"
    Channel cached = conn.createChannel(false);
    verify(connection, times(2)).createChannel();
    notCached.close();
    cached.close();
    ccf.destroy();
    verify(channel, times(2)).close();
    verify(connection).close(30000);
}
Also used : Message(org.springframework.messaging.Message) BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) Envelope(com.rabbitmq.client.Envelope) GetResponse(com.rabbitmq.client.GetResponse) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Test(org.junit.Test)

Aggregations

GetResponse (com.rabbitmq.client.GetResponse)55 Test (org.junit.Test)27 Channel (com.rabbitmq.client.Channel)10 IOException (java.io.IOException)10 Envelope (com.rabbitmq.client.Envelope)8 Connection (com.rabbitmq.client.Connection)7 Message (de.gessnerfl.rabbitmq.queue.management.model.Message)6 HashMap (java.util.HashMap)6 AMQP (com.rabbitmq.client.AMQP)5 LongString (com.rabbitmq.client.LongString)5 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)4 BasicProperties (de.gessnerfl.rabbitmq.queue.management.model.BasicProperties)4 RMQDestination (com.rabbitmq.jms.admin.RMQDestination)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Queue (javax.jms.Queue)3 QueueSender (javax.jms.QueueSender)3 QueueSession (javax.jms.QueueSession)3