Search in sources :

Example 1 with QueueInfo

use of com.rabbitmq.http.client.domain.QueueInfo in project tutorials by jhkim105.

the class RabbitClientTest method delete.

@Test
void delete() throws Exception {
    String apiUrl = "http://localhost:15672/api";
    String username = "guest";
    String password = "guest";
    Client client = new Client(new ClientParameters().url(apiUrl).username(username).password(password));
    List<QueueInfo> queueInfoList = client.getQueues();
    queueInfoList.forEach(qi -> client.deleteQueue("/", qi.getName()));
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) ClientParameters(com.rabbitmq.http.client.ClientParameters) Client(com.rabbitmq.http.client.Client) Test(org.junit.jupiter.api.Test)

Example 2 with QueueInfo

use of com.rabbitmq.http.client.domain.QueueInfo 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);
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) 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 3 with QueueInfo

use of com.rabbitmq.http.client.domain.QueueInfo 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));
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) BindingInfo(com.rabbitmq.http.client.domain.BindingInfo) Client(com.rabbitmq.http.client.Client) ExchangeInfo(com.rabbitmq.http.client.domain.ExchangeInfo) AmqpOutboundEndpoint(org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint)

Example 4 with QueueInfo

use of com.rabbitmq.http.client.domain.QueueInfo in project spring-amqp by spring-projects.

the class RabbitListenerTests method queueOverAmqp.

@Test
void queueOverAmqp() throws Exception {
    Client client = new Client("http://guest:guest@localhost:" + managementPort() + "/api");
    QueueInfo queue = client.getQueue("/", "stream.created.over.amqp");
    assertThat(queue.getArguments().get("x-queue-type")).isEqualTo("stream");
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) Client(com.rabbitmq.http.client.Client) Test(org.junit.jupiter.api.Test)

Example 5 with QueueInfo

use of com.rabbitmq.http.client.domain.QueueInfo in project spring-amqp by spring-projects.

the class LocalizedQueueConnectionFactory method determineConnectionFactory.

@Nullable
private ConnectionFactory determineConnectionFactory(String queue) {
    for (int i = 0; i < this.adminUris.length; i++) {
        String adminUri = this.adminUris[i];
        if (!adminUri.endsWith("/api/")) {
            adminUri += "/api/";
        }
        try {
            Client client = createClient(adminUri, this.username, this.password);
            QueueInfo queueInfo = client.getQueue(this.vhost, queue);
            if (queueInfo != null) {
                String node = queueInfo.getNode();
                if (node != null) {
                    String uri = this.nodeToAddress.get(node);
                    if (uri != null) {
                        return nodeConnectionFactory(queue, node, uri);
                    }
                    if (this.logger.isDebugEnabled()) {
                        this.logger.debug("No match for node: " + node);
                    }
                }
            } else {
                throw new AmqpException("Admin returned null QueueInfo");
            }
        } catch (Exception e) {
            this.logger.warn("Failed to determine queue location for: " + queue + " at: " + adminUri + ": " + e.getMessage());
        }
    }
    this.logger.warn("Failed to determine queue location for: " + queue + ", using default connection factory");
    return null;
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) AmqpException(org.springframework.amqp.AmqpException) Client(com.rabbitmq.http.client.Client) AmqpException(org.springframework.amqp.AmqpException) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) Nullable(org.springframework.lang.Nullable)

Aggregations

QueueInfo (com.rabbitmq.http.client.domain.QueueInfo)15 Client (com.rabbitmq.http.client.Client)13 Test (org.junit.jupiter.api.Test)12 Channel (com.rabbitmq.client.Channel)3 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)3 ExchangeInfo (com.rabbitmq.http.client.domain.ExchangeInfo)3 Queue (org.springframework.amqp.core.Queue)3 BindingInfo (com.rabbitmq.http.client.domain.BindingInfo)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)2 RabbitTemplate (org.springframework.amqp.rabbit.core.RabbitTemplate)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 AmqpOutboundEndpoint (org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint)2 DeclareOk (com.rabbitmq.client.AMQP.Queue.DeclareOk)1 LongString (com.rabbitmq.client.LongString)1 ClientParameters (com.rabbitmq.http.client.ClientParameters)1 IOException (java.io.IOException)1