Search in sources :

Example 16 with Client

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

the class FixedReplyQueueDeadLetterTests method testQueueArgs2.

@Test
void testQueueArgs2() throws MalformedURLException, URISyntaxException, InterruptedException {
    Client client = new Client(brokerRunning.getAdminUri(), brokerRunning.getAdminUser(), brokerRunning.getAdminPassword());
    QueueInfo queue = await().until(() -> client.getQueue("/", "all.args.2"), que -> que != null);
    Map<String, Object> arguments = queue.getArguments();
    assertThat(arguments.get("x-message-ttl")).isEqualTo(1000);
    assertThat(arguments.get("x-expires")).isEqualTo(200_000);
    assertThat(arguments.get("x-max-length")).isEqualTo(42);
    assertThat(arguments.get("x-max-length-bytes")).isEqualTo(10_000);
    assertThat(arguments.get("x-overflow")).isEqualTo("drop-head");
    assertThat(arguments.get("x-dead-letter-exchange")).isEqualTo("reply.dlx");
    assertThat(arguments.get("x-dead-letter-routing-key")).isEqualTo("reply.dlrk");
    assertThat(arguments.get("x-max-priority")).isEqualTo(4);
    assertThat(arguments.get("x-queue-mode")).isEqualTo("lazy");
    assertThat(arguments.get(Queue.X_QUEUE_LEADER_LOCATOR)).isEqualTo(LeaderLocator.clientLocal.getValue());
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) Client(com.rabbitmq.http.client.Client) Test(org.junit.jupiter.api.Test)

Example 17 with Client

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

the class FixedReplyQueueDeadLetterTests method testQuorumArgs.

/*
	 * Does not require a 3.8 broker - they are just arbitrary arguments.
	 */
@Test
void testQuorumArgs() throws MalformedURLException, URISyntaxException, InterruptedException {
    Client client = new Client(brokerRunning.getAdminUri(), brokerRunning.getAdminUser(), brokerRunning.getAdminPassword());
    QueueInfo queue = await().until(() -> client.getQueue("/", "test.quorum"), que -> que != null);
    Map<String, Object> arguments = queue.getArguments();
    assertThat(arguments.get("x-queue-type")).isEqualTo("quorum");
    assertThat(arguments.get("x-delivery-limit")).isEqualTo(10);
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) Client(com.rabbitmq.http.client.Client) Test(org.junit.jupiter.api.Test)

Example 18 with Client

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

the class RabbitAdminTests method testLeaderLocator.

@Test
public void testLeaderLocator() throws Exception {
    CachingConnectionFactory cf = new CachingConnectionFactory(RabbitAvailableCondition.getBrokerRunning().getConnectionFactory());
    RabbitAdmin admin = new RabbitAdmin(cf);
    AnonymousQueue queue = new AnonymousQueue();
    admin.declareQueue(queue);
    Client client = new Client("http://guest:guest@localhost:15672/api");
    AnonymousQueue queue1 = queue;
    QueueInfo info = await().until(() -> client.getQueue("/", queue1.getName()), inf -> inf != null);
    assertThat(info.getArguments().get(Queue.X_QUEUE_LEADER_LOCATOR)).isEqualTo("client-local");
    queue = new AnonymousQueue();
    queue.setLeaderLocator(null);
    admin.declareQueue(queue);
    AnonymousQueue queue2 = queue;
    info = await().until(() -> client.getQueue("/", queue2.getName()), inf -> inf != null);
    assertThat(info.getArguments().get(Queue.X_QUEUE_LEADER_LOCATOR)).isNull();
    cf.destroy();
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) BDDMockito.willReturn(org.mockito.BDDMockito.willReturn) RabbitAvailable(org.springframework.amqp.rabbit.junit.RabbitAvailable) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) LogLevels(org.springframework.amqp.rabbit.junit.LogLevels) UncategorizedAmqpException(org.springframework.amqp.UncategorizedAmqpException) DirectExchange(org.springframework.amqp.core.DirectExchange) Awaitility.await(org.awaitility.Awaitility.await) BDDMockito.willThrow(org.mockito.BDDMockito.willThrow) Connection(org.springframework.amqp.rabbit.connection.Connection) UUID(java.util.UUID) QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) BDDMockito.willDoNothing(org.mockito.BDDMockito.willDoNothing) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) Binding(org.springframework.amqp.core.Binding) Channel(com.rabbitmq.client.Channel) Client(com.rabbitmq.http.client.Client) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DestinationType(org.springframework.amqp.core.Binding.DestinationType) ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) Exchange(org.springframework.amqp.core.Exchange) SingleConnectionFactory(org.springframework.amqp.rabbit.connection.SingleConnectionFactory) HashMap(java.util.HashMap) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) Declarables(org.springframework.amqp.core.Declarables) BindingBuilder(org.springframework.amqp.core.BindingBuilder) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Queue(org.springframework.amqp.core.Queue) RabbitAvailableCondition(org.springframework.amqp.rabbit.junit.RabbitAvailableCondition) QueueInformation(org.springframework.amqp.core.QueueInformation) DeclareOk(com.rabbitmq.client.AMQP.Queue.DeclareOk) ExecutorService(java.util.concurrent.ExecutorService) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) NoBackOffPolicy(org.springframework.retry.backoff.NoBackOffPolicy) Properties(java.util.Properties) Mockito.times(org.mockito.Mockito.times) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Mockito.verify(org.mockito.Mockito.verify) ApplicationEvent(org.springframework.context.ApplicationEvent) TestUtils(org.springframework.amqp.utils.test.TestUtils) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Log(org.apache.commons.logging.Log) AnonymousQueue(org.springframework.amqp.core.AnonymousQueue) Bean(org.springframework.context.annotation.Bean) RetryTemplate(org.springframework.retry.support.RetryTemplate) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AnonymousQueue(org.springframework.amqp.core.AnonymousQueue) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Client(com.rabbitmq.http.client.Client) Test(org.junit.jupiter.api.Test)

Example 19 with Client

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

the class LocalizedQueueConnectionFactoryTests method doCreateClient.

private Client doCreateClient(String uri, String username, String password, String node) {
    Client client = mock(Client.class);
    QueueInfo queueInfo = new QueueInfo();
    queueInfo.setNode(node);
    given(client.getQueue("/", "q")).willReturn(queueInfo);
    return client;
}
Also used : QueueInfo(com.rabbitmq.http.client.domain.QueueInfo) Client(com.rabbitmq.http.client.Client)

Example 20 with Client

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

the class BrokerRunningSupport method createQueues.

private Channel createQueues(Connection connection) throws IOException, URISyntaxException {
    Channel channel;
    channel = connection.createChannel();
    for (String queueName : this.queues) {
        if (this.purge) {
            LOGGER.debug("Deleting queue: " + queueName);
            // Delete completely - gets rid of consumers and bindings as well
            channel.queueDelete(queueName);
        }
        if (isDefaultQueue(queueName)) {
            // Just for test probe.
            channel.queueDelete(queueName);
        } else {
            channel.queueDeclare(queueName, true, false, false, null);
        }
    }
    if (this.management) {
        Client client = new Client(getAdminUri(), this.adminUser, this.adminPassword);
        if (!client.alivenessTest("/")) {
            throw new BrokerNotAliveException("Aliveness test failed for localhost:15672 guest/quest; " + "management not available");
        }
    }
    return channel;
}
Also used : Channel(com.rabbitmq.client.Channel) Client(com.rabbitmq.http.client.Client)

Aggregations

Client (com.rabbitmq.http.client.Client)20 Test (org.junit.jupiter.api.Test)15 QueueInfo (com.rabbitmq.http.client.domain.QueueInfo)13 RabbitConsumerProperties (org.springframework.cloud.stream.binder.rabbit.properties.RabbitConsumerProperties)5 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)5 AmqpOutboundEndpoint (org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint)5 MessageChannel (org.springframework.messaging.MessageChannel)5 BindingInfo (com.rabbitmq.http.client.domain.BindingInfo)4 ExchangeInfo (com.rabbitmq.http.client.domain.ExchangeInfo)4 SimpleMessageListenerContainer (org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer)4 Channel (com.rabbitmq.client.Channel)3 LongString (com.rabbitmq.client.LongString)3 ClientParameters (com.rabbitmq.http.client.ClientParameters)3 HashMap (java.util.HashMap)3 Lifecycle (org.springframework.context.Lifecycle)3 Log (org.apache.commons.logging.Log)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 DeclareOk (com.rabbitmq.client.AMQP.Queue.DeclareOk)1