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);
}
}
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));
}
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);
}
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);
}
}
}
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);
}
Aggregations