Search in sources :

Example 6 with ExchangeInfo

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();
}
Also used : DirectExchange(org.springframework.amqp.core.DirectExchange) ExchangeInfo(com.rabbitmq.http.client.domain.ExchangeInfo) AbstractExchange(org.springframework.amqp.core.AbstractExchange) Test(org.junit.jupiter.api.Test)

Example 7 with ExchangeInfo

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);
}
Also used : Binding(org.springframework.amqp.core.Binding) Message(org.springframework.amqp.core.Message) MessageProperties(org.springframework.amqp.core.MessageProperties) DirectExchange(org.springframework.amqp.core.DirectExchange) AutoRecoverConnectionNotCurrentlyOpenException(org.springframework.amqp.rabbit.connection.AutoRecoverConnectionNotCurrentlyOpenException) AmqpIOException(org.springframework.amqp.AmqpIOException) ExchangeInfo(com.rabbitmq.http.client.domain.ExchangeInfo) Queue(org.springframework.amqp.core.Queue) AnonymousQueue(org.springframework.amqp.core.AnonymousQueue) Test(org.junit.jupiter.api.Test)

Example 8 with ExchangeInfo

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);
}
Also used : RabbitConsumerProperties(org.springframework.cloud.stream.binder.rabbit.properties.RabbitConsumerProperties) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) Lifecycle(org.springframework.context.Lifecycle) SimpleMessageListenerContainer(org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer) LongString(com.rabbitmq.client.LongString) ExchangeInfo(com.rabbitmq.http.client.domain.ExchangeInfo) AmqpOutboundEndpoint(org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint) MessageChannel(org.springframework.messaging.MessageChannel) BindingInfo(com.rabbitmq.http.client.domain.BindingInfo) Client(com.rabbitmq.http.client.Client) Test(org.junit.jupiter.api.Test)

Example 9 with ExchangeInfo

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());
}
Also used : ExchangeInfo(com.rabbitmq.http.client.domain.ExchangeInfo) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 10 with ExchangeInfo

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));
}
Also used : ExchangeInfo(com.rabbitmq.http.client.domain.ExchangeInfo) Test(org.junit.jupiter.api.Test)

Aggregations

ExchangeInfo (com.rabbitmq.http.client.domain.ExchangeInfo)14 Test (org.junit.jupiter.api.Test)12 Client (com.rabbitmq.http.client.Client)4 DirectExchange (org.springframework.amqp.core.DirectExchange)4 BindingInfo (com.rabbitmq.http.client.domain.BindingInfo)3 QueueInfo (com.rabbitmq.http.client.domain.QueueInfo)3 AmqpOutboundEndpoint (org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint)3 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)2 LongString (com.rabbitmq.client.LongString)2 Exchange (org.springframework.amqp.core.Exchange)2 SimpleMessageListenerContainer (org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer)2 RabbitConsumerProperties (org.springframework.cloud.stream.binder.rabbit.properties.RabbitConsumerProperties)2 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)2 Lifecycle (org.springframework.context.Lifecycle)2 MessageChannel (org.springframework.messaging.MessageChannel)2 HashMap (java.util.HashMap)1 AmqpIOException (org.springframework.amqp.AmqpIOException)1 AbstractExchange (org.springframework.amqp.core.AbstractExchange)1 AnonymousQueue (org.springframework.amqp.core.AnonymousQueue)1 Binding (org.springframework.amqp.core.Binding)1