Java源码示例:com.rabbitmq.client.CancelCallback
示例1
@Test
void rabbitMQShouldSupportTheExclusiveWorkQueueCase() throws Exception {
channel1.exchangeDeclare(EXCHANGE_NAME, "direct", DURABLE);
channel1.queueDeclare(WORK_QUEUE, DURABLE, !EXCLUSIVE, !AUTO_DELETE, ImmutableMap.of());
channel1.queueBind(WORK_QUEUE, EXCHANGE_NAME, ROUTING_KEY);
IntStream.range(0, 10)
.mapToObj(String::valueOf)
.map(RabbitMQTest.this::asBytes)
.forEach(Throwing.<byte[]>consumer(
bytes -> channel1.basicPublish(EXCHANGE_NAME, ROUTING_KEY, NO_PROPERTIES, bytes)).sneakyThrow());
String dyingConsumerTag = "dyingConsumer";
ImmutableMap<String, Object> arguments = ImmutableMap.of();
ConcurrentLinkedQueue<Integer> receivedMessages = new ConcurrentLinkedQueue<>();
CancelCallback doNothingOnCancel = consumerTag -> { };
DeliverCallback ackFirstMessageOnly = (consumerTag, message) -> {
if (receivedMessages.size() == 0) {
receivedMessages.add(Integer.valueOf(new String(message.getBody(), StandardCharsets.UTF_8)));
channel2.basicAck(message.getEnvelope().getDeliveryTag(), !MULTIPLE);
} else {
channel2.basicNack(message.getEnvelope().getDeliveryTag(), !MULTIPLE, REQUEUE);
}
};
channel2.basicConsume(WORK_QUEUE, !AUTO_ACK, dyingConsumerTag, !NO_LOCAL, EXCLUSIVE, arguments, ackFirstMessageOnly, doNothingOnCancel);
awaitAtMostOneMinute.until(() -> receivedMessages.size() == 1);
channel2.basicCancel(dyingConsumerTag);
InMemoryConsumer fallbackConsumer = new InMemoryConsumer(channel3);
channel3.basicConsume(WORK_QUEUE, AUTO_ACK, "fallbackConsumer", !NO_LOCAL, EXCLUSIVE, arguments, fallbackConsumer);
awaitAtMostOneMinute.until(() -> countReceivedMessages(fallbackConsumer) >= 1);
assertThat(receivedMessages).containsExactly(0);
assertThat(fallbackConsumer.getConsumedMessages()).contains(1, 2).doesNotContain(0);
}
示例2
public ConsumerWrapper(DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) {
this.deliverCallback = deliverCallback;
this.cancelCallback = cancelCallback;
this.shutdownSignalCallback = shutdownSignalCallback;
}
示例3
@Override
public String basicConsume(String queue, DeliverCallback deliverCallback, CancelCallback cancelCallback) {
return basicConsume(queue, false, deliverCallback, cancelCallback);
}
示例4
@Override
public String basicConsume(String queue, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) {
return basicConsume(queue, false, deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例5
@Override
public String basicConsume(String queue, boolean autoAck, DeliverCallback deliverCallback, CancelCallback cancelCallback) {
return basicConsume(queue, autoAck, Collections.emptyMap(), deliverCallback, cancelCallback);
}
示例6
@Override
public String basicConsume(String queue, boolean autoAck, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) {
return basicConsume(queue, autoAck, Collections.emptyMap(), deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例7
@Override
public String basicConsume(String queue, boolean autoAck, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback) {
return basicConsume(queue, autoAck, arguments, deliverCallback, cancelCallback, null);
}
示例8
@Override
public String basicConsume(String queue, boolean autoAck, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) {
return basicConsume(queue, autoAck, "", false, false, arguments, deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例9
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, DeliverCallback deliverCallback, CancelCallback cancelCallback) {
return basicConsume(queue, autoAck, consumerTag, deliverCallback, cancelCallback, null);
}
示例10
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) {
return basicConsume(queue, autoAck, consumerTag, false, false, Collections.emptyMap(), deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例11
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, boolean noLocal, boolean exclusive, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback) {
return basicConsume(queue, autoAck, consumerTag, noLocal, exclusive, arguments, deliverCallback, cancelCallback, null);
}
示例12
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, boolean noLocal, boolean exclusive, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) {
return basicConsume(queue, autoAck, consumerTag, noLocal, exclusive, arguments, new ConsumerWrapper(deliverCallback, cancelCallback, shutdownSignalCallback));
}
示例13
@Override
public String basicConsume(String queue, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
return delegate.basicConsume(queue, deliverCallback, cancelCallback);
}
示例14
@Override
public String basicConsume(String queue, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) throws IOException {
return delegate.basicConsume(queue, deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例15
@Override
public String basicConsume(String queue, boolean autoAck, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
return delegate.basicConsume(queue, autoAck, deliverCallback, cancelCallback);
}
示例16
@Override
public String basicConsume(String queue, boolean autoAck, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) throws IOException {
return delegate.basicConsume(queue, autoAck, deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例17
@Override
public String basicConsume(String queue, boolean autoAck, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
return delegate.basicConsume(queue, autoAck, arguments, deliverCallback, cancelCallback);
}
示例18
@Override
public String basicConsume(String queue, boolean autoAck, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) throws IOException {
return delegate.basicConsume(queue, autoAck, arguments, deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例19
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
return delegate.basicConsume(queue, autoAck, consumerTag, deliverCallback, cancelCallback);
}
示例20
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) throws IOException {
return delegate.basicConsume(queue, autoAck, consumerTag, deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例21
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, boolean noLocal, boolean exclusive, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
return delegate.basicConsume(queue, autoAck, consumerTag, noLocal, exclusive, arguments, deliverCallback, cancelCallback);
}
示例22
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, boolean noLocal, boolean exclusive, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) throws IOException {
return delegate.basicConsume(queue, autoAck, consumerTag, noLocal, exclusive, arguments, deliverCallback, cancelCallback, shutdownSignalCallback);
}
示例23
@Override
public String basicConsume(String queue, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
throw new UnsupportedOperationException("This method is not currently supported as it is not used by current API in testing");
}
示例24
@Override
public String basicConsume(String queue, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback) throws IOException {
throw new UnsupportedOperationException("This method is not currently supported as it is not used by current API in testing");
}
示例25
@Override
public String basicConsume(String queue, boolean autoAck, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
throw new UnsupportedOperationException("This method is not currently supported as it is not used by current API in testing");
}
示例26
@Override
public String basicConsume(String queue, boolean autoAck, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback)
throws IOException {
throw new UnsupportedOperationException("This method is not currently supported as it is not used by current API in testing");
}
示例27
@Override
public String basicConsume(String queue, boolean autoAck, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
throw new UnsupportedOperationException("This method is not currently supported as it is not used by current API in testing");
}
示例28
@Override
public String basicConsume(String queue, boolean autoAck, Map<String, Object> arguments, DeliverCallback deliverCallback, CancelCallback cancelCallback,
ConsumerShutdownSignalCallback shutdownSignalCallback) throws IOException {
throw new UnsupportedOperationException("This method is not currently supported as it is not used by current API in testing");
}
示例29
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, DeliverCallback deliverCallback, CancelCallback cancelCallback) throws IOException {
throw new UnsupportedOperationException("This method is not currently supported as it is not used by current API in testing");
}
示例30
@Override
public String basicConsume(String queue, boolean autoAck, String consumerTag, DeliverCallback deliverCallback, CancelCallback cancelCallback, ConsumerShutdownSignalCallback shutdownSignalCallback)
throws IOException {
throw new UnsupportedOperationException("This method is not currently supported as it is not used by current API in testing");
}