use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.
the class RequeueOnClose method publishAndGet.
private void publishAndGet(int count, boolean doAck) throws IOException, InterruptedException, TimeoutException {
openConnection();
for (int repeat = 0; repeat < count; repeat++) {
open();
injectMessage();
GetResponse r1 = getMessage();
if (doAck)
channel.basicAck(r1.getEnvelope().getDeliveryTag(), false);
close();
open();
if (doAck) {
assertNull("Expected missing second basicGet (repeat=" + repeat + ")", getMessage());
} else {
assertNotNull("Expected present second basicGet (repeat=" + repeat + ")", getMessage());
}
close();
}
closeConnection();
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.
the class Policies method deadLetterExchange.
@Test
public void deadLetterExchange() throws IOException, InterruptedException {
Map<String, Object> args = ttlArgs(0);
String src = declareQueue("has-dlx", args);
String dest = declareQueue();
channel.exchangeDeclare("dlx", "fanout", false, true, null);
channel.queueBind(dest, "dlx", "");
basicPublishVolatile(src);
Thread.sleep(DELAY);
GetResponse resp = channel.basicGet(dest, true);
assertEquals("rk", resp.getEnvelope().getRoutingKey());
clearPolicies();
basicPublishVolatile(src);
Thread.sleep(DELAY);
assertDelivered(dest, 0);
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.
the class BindingLifecycleBase method sendUnroutable.
protected void sendUnroutable(Binding binding) throws IOException {
channel.basicPublish(binding.x, binding.k, null, payload);
GetResponse response = channel.basicGet(binding.q, true);
assertNull("The response SHOULD BE null", response);
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.
the class BindingLifecycleBase method sendRoutable.
protected void sendRoutable(Binding binding) throws IOException {
channel.basicPublish(binding.x, binding.k, null, payload);
GetResponse response = channel.basicGet(binding.q, true);
assertNotNull("The response should not be null", response);
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.
the class Metrics method metricsAck.
@Test
public void metricsAck() throws IOException, TimeoutException {
StandardMetricsCollector metrics = new StandardMetricsCollector();
connectionFactory.setMetricsCollector(metrics);
Connection connection = null;
try {
connection = connectionFactory.newConnection();
Channel channel1 = connection.createChannel();
Channel channel2 = connection.createChannel();
sendMessage(channel1);
GetResponse getResponse = channel1.basicGet(QUEUE, false);
channel1.basicAck(getResponse.getEnvelope().getDeliveryTag(), false);
assertThat(metrics.getConsumedMessages().getCount()).isEqualTo(1L);
assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L);
// basicGet / basicAck
sendMessage(channel1);
sendMessage(channel2);
sendMessage(channel1);
sendMessage(channel2);
sendMessage(channel1);
sendMessage(channel2);
GetResponse response1 = channel1.basicGet(QUEUE, false);
GetResponse response2 = channel2.basicGet(QUEUE, false);
GetResponse response3 = channel1.basicGet(QUEUE, false);
GetResponse response4 = channel2.basicGet(QUEUE, false);
GetResponse response5 = channel1.basicGet(QUEUE, false);
GetResponse response6 = channel2.basicGet(QUEUE, false);
assertThat(metrics.getConsumedMessages().getCount()).isEqualTo(1L + 6L);
assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L);
channel1.basicAck(response5.getEnvelope().getDeliveryTag(), false);
assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L + 1L);
channel1.basicAck(response3.getEnvelope().getDeliveryTag(), true);
assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L + 1L + 2L);
channel2.basicAck(response2.getEnvelope().getDeliveryTag(), true);
assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L + (1L + 2L) + 1L);
channel2.basicAck(response6.getEnvelope().getDeliveryTag(), true);
assertThat(metrics.getAcknowledgedMessages().getCount()).isEqualTo(1L + (1L + 2L) + 1L + 2L);
long alreadySentMessages = 1 + (1 + 2) + 1 + 2;
// basicConsume / basicAck
channel1.basicConsume(QUEUE, false, new MultipleAckConsumer(channel1, false));
channel1.basicConsume(QUEUE, false, new MultipleAckConsumer(channel1, true));
channel2.basicConsume(QUEUE, false, new MultipleAckConsumer(channel2, false));
channel2.basicConsume(QUEUE, false, new MultipleAckConsumer(channel2, true));
int nbMessages = 10;
for (int i = 0; i < nbMessages; i++) {
sendMessage(i % 2 == 0 ? channel1 : channel2);
}
waitAtMost(timeout(), () -> metrics.getConsumedMessages().getCount() == alreadySentMessages + nbMessages);
waitAtMost(timeout(), () -> metrics.getAcknowledgedMessages().getCount() == alreadySentMessages + nbMessages);
} finally {
safeClose(connection);
}
}
Aggregations