Search in sources :

Example 11 with GetResponse

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

the class AmqpMessageSource method doReceive.

@Override
protected AbstractIntegrationMessageBuilder<Object> doReceive() {
    Connection connection = this.connectionFactory.createConnection();
    Channel channel = connection.createChannel(this.transacted);
    try {
        GetResponse resp = channel.basicGet(this.queue, false);
        if (resp == null) {
            RabbitUtils.closeChannel(channel);
            RabbitUtils.closeConnection(connection);
            return null;
        }
        AcknowledgmentCallback callback = this.ackCallbackFactory.createCallback(new AmqpAckInfo(connection, channel, this.transacted, resp));
        MessageProperties messageProperties = this.propertiesConverter.toMessageProperties(resp.getProps(), resp.getEnvelope(), StandardCharsets.UTF_8.name());
        messageProperties.setConsumerQueue(this.queue);
        Map<String, Object> headers = this.headerMapper.toHeadersFromRequest(messageProperties);
        org.springframework.amqp.core.Message amqpMessage = new org.springframework.amqp.core.Message(resp.getBody(), messageProperties);
        Object payload = this.messageConverter.fromMessage(amqpMessage);
        AbstractIntegrationMessageBuilder<Object> builder = getMessageBuilderFactory().withPayload(payload).copyHeaders(headers).setHeader(IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK, callback);
        if (this.rawMessageHeader) {
            builder.setHeader(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE, amqpMessage);
        }
        return builder;
    } catch (IOException e) {
        RabbitUtils.closeChannel(channel);
        RabbitUtils.closeConnection(connection);
        throw RabbitExceptionTranslator.convertRabbitAccessException(e);
    }
}
Also used : Channel(com.rabbitmq.client.Channel) Connection(org.springframework.amqp.rabbit.connection.Connection) AcknowledgmentCallback(org.springframework.integration.acks.AcknowledgmentCallback) IOException(java.io.IOException) GetResponse(com.rabbitmq.client.GetResponse) MessageProperties(org.springframework.amqp.core.MessageProperties)

Example 12 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class UnverifiedConnection method sSL.

@Test
public void sSL() throws IOException {
    channel.queueDeclare("Bug19356Test", false, true, true, null);
    channel.basicPublish("", "Bug19356Test", null, "SSL".getBytes());
    GetResponse chResponse = channel.basicGet("Bug19356Test", false);
    assertNotNull(chResponse);
    byte[] body = chResponse.getBody();
    assertEquals("SSL", new String(body));
}
Also used : GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 13 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class DurableBindingLifecycle method durableBindingsDeletion.

/**
 * This tests whether the bindings attached to a durable exchange
 * are correctly blown away when the exchange is nuked.
 *
 * This complements a unit test for testing non-durable exchanges.
 * In that case, an exchange is deleted and you expect any
 * bindings hanging to it to be deleted as well. To verify this,
 * the exchange is deleted and then recreated.
 *
 * After the recreation, the old bindings should no longer exist
 * and hence any messages published to that exchange get routed to
 * /dev/null
 *
 * This test exercises the durable variable of that test, so the
 * main difference is that the broker has to be restarted to
 * verify that the durable routes have been turfed.
 */
@Test
public void durableBindingsDeletion() throws IOException, TimeoutException {
    declareDurableTopicExchange(X);
    declareAndBindDurableQueue(Q, X, K);
    deleteExchange(X);
    restart();
    declareDurableTopicExchange(X);
    for (int i = 0; i < N; i++) {
        basicPublishVolatile(X, K);
    }
    GetResponse response = channel.basicGet(Q, true);
    assertNull("The initial response SHOULD BE null", response);
    deleteQueue(Q);
    deleteExchange(X);
}
Also used : GetResponse(com.rabbitmq.client.GetResponse) Test(org.junit.Test)

Example 14 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class FrameMax method frameSizes.

/* Publish a message of size FRAME_MAX.  The broker should split
     * this into two frames before sending back.  Frame content should
     * be less or equal to frame-max - 8. */
@Test
public void frameSizes() throws IOException, InterruptedException {
    String queueName = channel.queueDeclare().getQueue();
    /* This should result in at least 3 frames. */
    int howMuch = 2 * FRAME_MAX;
    basicPublishVolatile(new byte[howMuch], queueName);
    /* Receive everything that was sent out. */
    while (howMuch > 0) {
        try {
            GetResponse response = channel.basicGet(queueName, false);
            howMuch -= response.getBody().length;
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception in basicGet loop: " + e);
        }
    }
}
Also used : GetResponse(com.rabbitmq.client.GetResponse) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Test(org.junit.Test)

Example 15 with GetResponse

use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.

the class InternalExchange method tryPublishingToInternalExchange.

@Test
public void tryPublishingToInternalExchange() throws IOException {
    byte[] testDataBody = "test-data".getBytes();
    // We should be able to publish to the non-internal exchange as usual
    // and see our message land in the queue...
    channel.basicPublish("e0", "", null, testDataBody);
    GetResponse r = channel.basicGet("q1", true);
    assertTrue(Arrays.equals(r.getBody(), testDataBody));
    // Publishing to the internal exchange will not be allowed...
    channel.basicPublish("e1", "", null, testDataBody);
    expectError(AMQP.ACCESS_REFUSED);
}
Also used : GetResponse(com.rabbitmq.client.GetResponse) 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