use of com.rabbitmq.http.client.domain.BindingInfo in project spring-cloud-stream by spring-cloud.
the class RabbitBinderTests method testConsumerPropertiesWithUserInfrastructureCustomQueueArgs.
@Test
public void testConsumerPropertiesWithUserInfrastructureCustomQueueArgs() throws Exception {
RabbitTestBinder binder = getBinder();
ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
RabbitConsumerProperties extProps = properties.getExtension();
extProps.setExchangeType(ExchangeTypes.DIRECT);
extProps.setExchangeDurable(false);
extProps.setExchangeAutoDelete(true);
extProps.setBindingRoutingKey("foo");
extProps.setExpires(30_000);
extProps.setLazy(true);
extProps.setMaxLength(10_000);
extProps.setMaxLengthBytes(100_000);
extProps.setMaxPriority(10);
extProps.setOverflowBehavior("drop-head");
extProps.setTtl(2_000);
extProps.setAutoBindDlq(true);
extProps.setDeadLetterQueueName("customDLQ");
extProps.setDeadLetterExchange("customDLX");
extProps.setDeadLetterExchangeType(ExchangeTypes.TOPIC);
extProps.setDeadLetterRoutingKey("customDLRK");
extProps.setDlqDeadLetterExchange("propsUser3");
// GH-259 - if the next line was commented, the test failed.
extProps.setDlqDeadLetterRoutingKey("propsUser3");
extProps.setDlqExpires(60_000);
extProps.setDlqLazy(true);
extProps.setDlqMaxLength(20_000);
extProps.setDlqMaxLengthBytes(40_000);
extProps.setDlqOverflowBehavior("reject-publish");
extProps.setDlqMaxPriority(8);
extProps.setDlqTtl(1_000);
extProps.setConsumerTagPrefix("testConsumerTag");
extProps.setExclusive(true);
Binding<MessageChannel> consumerBinding = binder.bindConsumer("propsUser3", "infra", createBindableChannel("input", new BindingProperties()), properties);
Lifecycle endpoint = extractEndpoint(consumerBinding);
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class);
assertThat(container.isRunning()).isTrue();
Client client = new Client(adminUri());
List<BindingInfo> bindings = client.getBindingsBySource("/", "propsUser3");
int n = 0;
while (n++ < 100 && bindings == null || bindings.size() < 1) {
Thread.sleep(100);
bindings = client.getBindingsBySource("/", "propsUser3");
}
assertThat(bindings.size()).isEqualTo(1);
assertThat(bindings.get(0).getSource()).isEqualTo("propsUser3");
assertThat(bindings.get(0).getDestination()).isEqualTo("propsUser3.infra");
assertThat(bindings.get(0).getRoutingKey()).isEqualTo("foo");
bindings = client.getBindingsBySource("/", "customDLX");
n = 0;
while (n++ < 100 && bindings == null || bindings.size() < 1) {
Thread.sleep(100);
bindings = client.getBindingsBySource("/", "customDLX");
}
// assertThat(bindings.size()).isEqualTo(1);
assertThat(bindings.get(0).getSource()).isEqualTo("customDLX");
assertThat(bindings.get(0).getDestination()).isEqualTo("customDLQ");
assertThat(bindings.get(0).getRoutingKey()).isEqualTo("customDLRK");
ExchangeInfo exchange = client.getExchange("/", "propsUser3");
n = 0;
while (n++ < 100 && exchange == null) {
Thread.sleep(100);
exchange = client.getExchange("/", "propsUser3");
}
assertThat(exchange.getType()).isEqualTo("direct");
assertThat(exchange.isDurable()).isEqualTo(false);
assertThat(exchange.isAutoDelete()).isEqualTo(true);
exchange = client.getExchange("/", "customDLX");
n = 0;
while (n++ < 100 && exchange == null) {
Thread.sleep(100);
exchange = client.getExchange("/", "customDLX");
}
assertThat(exchange.getType()).isEqualTo("topic");
assertThat(exchange.isDurable()).isEqualTo(true);
assertThat(exchange.isAutoDelete()).isEqualTo(false);
QueueInfo queue = client.getQueue("/", "propsUser3.infra");
n = 0;
while (n++ < 100 && queue == null || queue.getConsumerCount() == 0) {
Thread.sleep(100);
queue = client.getQueue("/", "propsUser3.infra");
}
assertThat(queue).isNotNull();
Map<String, Object> args = queue.getArguments();
assertThat(args.get("x-expires")).isEqualTo(30_000);
assertThat(args.get("x-max-length")).isEqualTo(10_000);
assertThat(args.get("x-max-length-bytes")).isEqualTo(100_000);
assertThat(args.get("x-overflow")).isEqualTo("drop-head");
assertThat(args.get("x-max-priority")).isEqualTo(10);
assertThat(args.get("x-message-ttl")).isEqualTo(2_000);
assertThat(args.get("x-dead-letter-exchange")).isEqualTo("customDLX");
assertThat(args.get("x-dead-letter-routing-key")).isEqualTo("customDLRK");
assertThat(args.get("x-queue-mode")).isEqualTo("lazy");
assertThat(queue.getExclusiveConsumerTag()).isEqualTo("testConsumerTag#0");
queue = client.getQueue("/", "customDLQ");
n = 0;
while (n++ < 100 && queue == null) {
Thread.sleep(100);
queue = client.getQueue("/", "customDLQ");
}
assertThat(queue).isNotNull();
args = queue.getArguments();
assertThat(args.get("x-expires")).isEqualTo(60_000);
assertThat(args.get("x-max-length")).isEqualTo(20_000);
assertThat(args.get("x-max-length-bytes")).isEqualTo(40_000);
assertThat(args.get("x-overflow")).isEqualTo("reject-publish");
assertThat(args.get("x-max-priority")).isEqualTo(8);
assertThat(args.get("x-message-ttl")).isEqualTo(1_000);
assertThat(args.get("x-dead-letter-exchange")).isEqualTo("propsUser3");
assertThat(args.get("x-dead-letter-routing-key")).isEqualTo("propsUser3");
assertThat(args.get("x-queue-mode")).isEqualTo("lazy");
consumerBinding.unbind();
assertThat(container.isRunning()).isFalse();
verifyAutoDeclareContextClear(binder);
}
use of com.rabbitmq.http.client.domain.BindingInfo in project spring-cloud-stream by spring-cloud.
the class RabbitBinderTests method testConsumerPropertiesWithHeaderExchanges.
@Test
public void testConsumerPropertiesWithHeaderExchanges() throws Exception {
RabbitTestBinder binder = getBinder();
ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
properties.getExtension().setExchangeType(ExchangeTypes.HEADERS);
properties.getExtension().setAutoBindDlq(true);
properties.getExtension().setDeadLetterExchange(ExchangeTypes.HEADERS);
properties.getExtension().setDeadLetterExchange("propsHeader.dlx");
Map<String, String> queueBindingArguments = new HashMap<>();
queueBindingArguments.put("x-match", "any");
queueBindingArguments.put("foo", "bar");
properties.getExtension().setQueueBindingArguments(queueBindingArguments);
properties.getExtension().setDlqBindingArguments(queueBindingArguments);
String group = "bindingArgs";
Binding<MessageChannel> consumerBinding = binder.bindConsumer("propsHeader", group, createBindableChannel("input", new BindingProperties()), properties);
Lifecycle endpoint = extractEndpoint(consumerBinding);
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class);
assertThat(container.isRunning()).isTrue();
consumerBinding.unbind();
assertThat(container.isRunning()).isFalse();
assertThat(container.getQueueNames()[0]).isEqualTo("propsHeader." + group);
Client client = new Client(adminUri());
List<BindingInfo> bindings = client.getBindingsBySource("/", "propsHeader");
int n = 0;
while (n++ < 100 && bindings == null || bindings.size() < 1) {
Thread.sleep(100);
bindings = client.getBindingsBySource("/", "propsHeader");
}
assertThat(bindings.size()).isEqualTo(1);
assertThat(bindings.get(0).getSource()).isEqualTo("propsHeader");
assertThat(bindings.get(0).getDestination()).isEqualTo("propsHeader." + group);
assertThat(bindings.get(0).getArguments()).hasEntrySatisfying("x-match", v -> assertThat(v).isEqualTo("any"));
assertThat(bindings.get(0).getArguments()).hasEntrySatisfying("foo", v -> assertThat(v).isEqualTo("bar"));
bindings = client.getBindingsBySource("/", "propsHeader.dlx");
n = 0;
while (n++ < 100 && bindings == null || bindings.size() < 1) {
Thread.sleep(100);
bindings = client.getBindingsBySource("/", "propsHeader.dlx");
}
assertThat(bindings.size()).isEqualTo(1);
assertThat(bindings.get(0).getSource()).isEqualTo("propsHeader.dlx");
assertThat(bindings.get(0).getDestination()).isEqualTo("propsHeader." + group + ".dlq");
assertThat(bindings.get(0).getArguments()).hasEntrySatisfying("x-match", v -> assertThat(v).isEqualTo("any"));
assertThat(bindings.get(0).getArguments()).hasEntrySatisfying("foo", v -> assertThat(v).isEqualTo("bar"));
verifyAutoDeclareContextClear(binder);
}
use of com.rabbitmq.http.client.domain.BindingInfo in project spring-cloud-stream by spring-cloud.
the class RabbitBinderModuleTests method checkCustomizedArgs.
private void checkCustomizedArgs() throws MalformedURLException, URISyntaxException, InterruptedException {
Client client = new Client(String.format("http://guest:guest@localhost:%d/api", RABBITMQ.getHttpPort()));
List<BindingInfo> bindings = client.getBindingsBySource("/", "process-in-0");
int n = 0;
while (n++ < 100 && bindings == null || bindings.size() < 1) {
Thread.sleep(100);
bindings = client.getBindingsBySource("/", "process-in-0");
}
assertThat(bindings).isNotNull();
assertThat(bindings.get(0).getArguments()).contains(entry("added.by", "customizer"));
ExchangeInfo exchange = client.getExchange("/", "process-in-0");
assertThat(exchange.getArguments()).contains(entry("added.by", "customizer"));
QueueInfo queue = client.getQueue("/", bindings.get(0).getDestination());
assertThat(queue.getArguments()).contains(entry("added.by", "customizer"));
assertThat(queue.getArguments()).contains(entry("x-single-active-consumer", Boolean.TRUE));
}
use of com.rabbitmq.http.client.domain.BindingInfo in project spring-amqp by spring-projects.
the class RabbitRestApiTests method testBindingsDetail.
@Test
public void testBindingsDetail() {
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
Map<String, Object> args = Collections.<String, Object>singletonMap("alternate-exchange", "");
Exchange exchange1 = new DirectExchange(UUID.randomUUID().toString(), false, true, args);
admin.declareExchange(exchange1);
Exchange exchange2 = new DirectExchange(UUID.randomUUID().toString(), false, true, args);
admin.declareExchange(exchange2);
Queue queue = admin.declareQueue();
Binding binding1 = BindingBuilder.bind(queue).to(exchange1).with("foo").and(args);
admin.declareBinding(binding1);
Binding binding2 = BindingBuilder.bind(exchange2).to((DirectExchange) exchange1).with("bar");
admin.declareBinding(binding2);
List<BindingInfo> bindings = this.rabbitRestClient.getBindingsBySource("/", exchange1.getName());
assertThat(bindings).hasSize(2);
assertThat(bindings.get(0).getSource()).isEqualTo(exchange1.getName());
assertThat("foo").isIn(bindings.get(0).getRoutingKey(), bindings.get(1).getRoutingKey());
BindingInfo qout = null;
BindingInfo eout = null;
if (bindings.get(0).getRoutingKey().equals("foo")) {
qout = bindings.get(0);
eout = bindings.get(1);
} else {
eout = bindings.get(0);
qout = bindings.get(1);
}
assertThat(qout.getDestinationType()).isEqualTo("queue");
assertThat(qout.getDestination()).isEqualTo(queue.getName());
assertThat(qout.getArguments()).isNotNull();
assertThat(qout.getArguments().get("alternate-exchange")).isEqualTo("");
assertThat(eout.getDestinationType()).isEqualTo("exchange");
assertThat(eout.getDestination()).isEqualTo(exchange2.getName());
admin.deleteExchange(exchange1.getName());
admin.deleteExchange(exchange2.getName());
}
use of com.rabbitmq.http.client.domain.BindingInfo in project spring-cloud-stream by spring-cloud.
the class RabbitBinderTests method testConsumerPropertiesWithUserInfrastructureCustomExchangeAndRK.
@Test
public void testConsumerPropertiesWithUserInfrastructureCustomExchangeAndRK() throws Exception {
RabbitTestBinder binder = getBinder();
ExtendedConsumerProperties<RabbitConsumerProperties> properties = createConsumerProperties();
properties.getExtension().setExchangeType(ExchangeTypes.DIRECT);
properties.getExtension().setBindingRoutingKey("foo,bar");
properties.getExtension().setBindingRoutingKeyDelimiter(",");
properties.getExtension().setQueueNameGroupOnly(true);
// properties.getExtension().setDelayedExchange(true); // requires delayed message
// exchange plugin; tested locally
String group = "infra";
Binding<MessageChannel> consumerBinding = binder.bindConsumer("propsUser2", group, createBindableChannel("input", new BindingProperties()), properties);
Lifecycle endpoint = extractEndpoint(consumerBinding);
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class);
assertThat(container.isRunning()).isTrue();
consumerBinding.unbind();
assertThat(container.isRunning()).isFalse();
assertThat(container.getQueueNames()[0]).isEqualTo(group);
Client client = new Client(adminUri());
List<BindingInfo> bindings = client.getBindingsBySource("/", "propsUser2");
int n = 0;
while (n++ < 100 && bindings == null || bindings.size() < 1) {
Thread.sleep(100);
bindings = client.getBindingsBySource("/", "propsUser2");
}
assertThat(bindings.size()).isEqualTo(2);
assertThat(bindings.get(0).getSource()).isEqualTo("propsUser2");
assertThat(bindings.get(0).getDestination()).isEqualTo(group);
assertThat(bindings.get(0).getRoutingKey()).isIn("foo", "bar");
assertThat(bindings.get(1).getSource()).isEqualTo("propsUser2");
assertThat(bindings.get(1).getDestination()).isEqualTo(group);
assertThat(bindings.get(1).getRoutingKey()).isIn("foo", "bar");
assertThat(bindings.get(1).getRoutingKey()).isNotEqualTo(bindings.get(0).getRoutingKey());
ExchangeInfo exchange = client.getExchange("/", "propsUser2");
while (n++ < 100 && exchange == null) {
Thread.sleep(100);
exchange = client.getExchange("/", "propsUser2");
}
assertThat(exchange.getType()).isEqualTo("direct");
assertThat(exchange.isDurable()).isEqualTo(true);
assertThat(exchange.isAutoDelete()).isEqualTo(false);
verifyAutoDeclareContextClear(binder);
}
Aggregations