use of com.rabbitmq.http.client.domain.ExchangeInfo in project spring-amqp by spring-projects.
the class RabbitAdminIntegrationTests method testDeleteExchangeWithInternalOption.
@Test
public void testDeleteExchangeWithInternalOption() throws Exception {
String exchangeName = "test.exchange.internal";
AbstractExchange exchange = new DirectExchange(exchangeName);
exchange.setInternal(true);
rabbitAdmin.declareExchange(exchange);
ExchangeInfo exchange2 = getExchange(exchangeName);
assertThat(exchange2.getType()).isEqualTo(ExchangeTypes.DIRECT);
assertThat(exchange2.isInternal()).isTrue();
boolean result = rabbitAdmin.deleteExchange(exchangeName);
assertThat(result).isTrue();
}
use of com.rabbitmq.http.client.domain.ExchangeInfo in project spring-amqp by spring-projects.
the class RabbitAdminIntegrationTests method testDeclareDelayedExchange.
@Test
public void testDeclareDelayedExchange() throws Exception {
DirectExchange exchange = new DirectExchange("test.delayed.exchange");
exchange.setDelayed(true);
Queue queue = new Queue(UUID.randomUUID().toString(), true, false, false);
String exchangeName = exchange.getName();
Binding binding = new Binding(queue.getName(), DestinationType.QUEUE, exchangeName, queue.getName(), null);
try {
this.rabbitAdmin.declareExchange(exchange);
} catch (AmqpIOException e) {
if (RabbitUtils.isExchangeDeclarationFailure(e) && e.getCause().getCause().getMessage().contains("exchange type 'x-delayed-message'")) {
return;
} else {
throw e;
}
} catch (@SuppressWarnings("unused") AutoRecoverConnectionNotCurrentlyOpenException e) {
return;
}
this.rabbitAdmin.declareQueue(queue);
this.rabbitAdmin.declareBinding(binding);
RabbitTemplate template = new RabbitTemplate(this.connectionFactory);
template.setReceiveTimeout(10000);
template.convertAndSend(exchangeName, queue.getName(), "foo", message -> {
message.getMessageProperties().setDelay(1000);
return message;
});
MessageProperties properties = new MessageProperties();
properties.setDelay(500);
template.send(exchangeName, queue.getName(), MessageBuilder.withBody("foo".getBytes()).andProperties(properties).build());
long t1 = System.currentTimeMillis();
Message received = template.receive(queue.getName());
assertThat(received).isNotNull();
assertThat(received.getMessageProperties().getReceivedDelay()).isEqualTo(Integer.valueOf(500));
received = template.receive(queue.getName());
assertThat(received).isNotNull();
assertThat(received.getMessageProperties().getReceivedDelay()).isEqualTo(Integer.valueOf(1000));
assertThat(System.currentTimeMillis() - t1).isGreaterThan(950L);
ExchangeInfo exchange2 = getExchange(exchangeName);
assertThat(exchange2.getArguments().get("x-delayed-type")).isEqualTo(ExchangeTypes.DIRECT);
assertThat(exchange2.getType()).isEqualTo("x-delayed-message");
this.rabbitAdmin.deleteQueue(queue.getName());
this.rabbitAdmin.deleteExchange(exchangeName);
}
use of com.rabbitmq.http.client.domain.ExchangeInfo 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);
}
use of com.rabbitmq.http.client.domain.ExchangeInfo in project service-api by reportportal.
the class ProjectControllerTest method deleteIndex.
@Test
void deleteIndex() throws Exception {
ExchangeInfo exchangeInfo = new ExchangeInfo();
exchangeInfo.setName("analyzer");
HashMap<String, Object> arguments = new HashMap<>();
arguments.put("analyzer_index", true);
arguments.put("analyzer", "test_analyzer");
exchangeInfo.setArguments(arguments);
when(rabbitClient.getExchanges(any())).thenReturn(Collections.singletonList(exchangeInfo));
mockMvc.perform(delete("/v1/project/default_personal/index").with(token(oAuthHelper.getDefaultToken()))).andExpect(status().isOk());
verify(rabbitTemplate, times(1)).convertSendAndReceiveAsType(eq(exchangeInfo.getName()), eq("delete"), eq(2L), any());
}
use of com.rabbitmq.http.client.domain.ExchangeInfo in project service-api by reportportal.
the class AnalyzerUtilsTest method testBadValues.
@Test
void testBadValues() {
ExchangeInfo mock = mock(ExchangeInfo.class);
when(mock.getArguments()).thenReturn(ImmutableMap.<String, Object>builder().put(ANALYZER_PRIORITY, "abracadabra").put(ANALYZER_INDEX, "666").put(ANALYZER_LOG_SEARCH, "666").build());
assertEquals(Integer.MAX_VALUE, AnalyzerUtils.EXCHANGE_PRIORITY.applyAsInt(mock));
assertFalse(AnalyzerUtils.DOES_SUPPORT_INDEX.test(mock));
assertFalse(DOES_SUPPORT_SEARCH.test(mock));
}
Aggregations