use of com.rabbitmq.http.client.Client 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.Client in project spring-cloud-stream by spring-cloud.
the class RabbitBinderTests method testAutoBindDLQManualAcks.
@Test
public void testAutoBindDLQManualAcks() throws Exception {
RabbitTestBinder binder = getBinder();
ExtendedConsumerProperties<RabbitConsumerProperties> consumerProperties = createConsumerProperties();
consumerProperties.getExtension().setPrefix(TEST_PREFIX);
consumerProperties.getExtension().setAutoBindDlq(true);
consumerProperties.setMaxAttempts(2);
consumerProperties.getExtension().setDurableSubscription(true);
consumerProperties.getExtension().setAcknowledgeMode(AcknowledgeMode.MANUAL);
BindingProperties bindingProperties = createConsumerBindingProperties(consumerProperties);
DirectChannel moduleInputChannel = createBindableChannel("input", bindingProperties);
moduleInputChannel.setBeanName("dlqTestManual");
Client client = new Client(adminUri());
moduleInputChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
// Wait until the unacked state is reflected in the admin
QueueInfo info = client.getQueue("/", TEST_PREFIX + "dlqTestManual.default");
int n = 0;
while (n++ < 100 && info.getMessagesUnacknowledged() < 1L) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
info = client.getQueue("/", TEST_PREFIX + "dlqTestManual.default");
}
throw new RuntimeException("foo");
}
});
Binding<MessageChannel> consumerBinding = binder.bindConsumer("dlqTestManual", "default", moduleInputChannel, consumerProperties);
RabbitTemplate template = new RabbitTemplate(this.rabbitTestSupport.getResource());
template.convertAndSend("", TEST_PREFIX + "dlqTestManual.default", "foo");
int n = 0;
while (n++ < 100) {
Object deadLetter = template.receiveAndConvert(TEST_PREFIX + "dlqTestManual.default.dlq");
if (deadLetter != null) {
assertThat(deadLetter).isEqualTo("foo");
break;
}
Thread.sleep(100);
}
assertThat(n).isLessThan(100);
n = 0;
QueueInfo info = client.getQueue("/", TEST_PREFIX + "dlqTestManual.default");
while (n++ < 100 && info.getMessagesUnacknowledged() > 0L) {
Thread.sleep(100);
info = client.getQueue("/", TEST_PREFIX + "dlqTestManual.default");
}
assertThat(info.getMessagesUnacknowledged()).isEqualTo(0L);
consumerBinding.unbind();
ApplicationContext context = TestUtils.getPropertyValue(binder, "binder.provisioningProvider.autoDeclareContext", ApplicationContext.class);
assertThat(context.containsBean(TEST_PREFIX + "dlqTestManual.default.binding")).isFalse();
assertThat(context.containsBean(TEST_PREFIX + "dlqTestManual.default")).isFalse();
assertThat(context.containsBean(TEST_PREFIX + "dlqTestManual.default.dlq.binding")).isFalse();
assertThat(context.containsBean(TEST_PREFIX + "dlqTestManual.default.dlq")).isFalse();
verifyAutoDeclareContextClear(binder);
}
use of com.rabbitmq.http.client.Client in project hop by rabbitmq.
the class SanityCheck method main.
public static void main(String[] args) {
try {
Client c = new Client(new ClientParameters().url("http://127.0.0.1:15672/api/").username("guest").password("guest"));
c.getOverview();
LoggerFactory.getLogger("rabbitmq").info("Test succeeded with Hop {}", Client.class.getPackage().getImplementationVersion());
System.exit(0);
} catch (Exception e) {
LoggerFactory.getLogger("rabbitmq").info("Test failed", e);
System.exit(1);
}
}
use of com.rabbitmq.http.client.Client in project hop by rabbitmq.
the class AppTest method createUseClient.
@Test
void createUseClient() throws Exception {
HttpLayerFactory httpLayerFactory = JdkHttpClientHttpLayer.configure().clientBuilderConsumer(clientBuilder -> clientBuilder.connectTimeout(Duration.ofSeconds(10))).requestBuilderConsumer(requestBuilder -> requestBuilder.timeout(Duration.ofSeconds(10)).setHeader("Authorization", authorization("guest", "guest"))).create();
Client c = new Client(new ClientParameters().url("http://127.0.0.1:15672/api/").username("guest").password("guest").httpLayerFactory(httpLayerFactory));
c.getOverview();
}
use of com.rabbitmq.http.client.Client in project spring-amqp by spring-projects.
the class FixedReplyQueueDeadLetterTests method testQueueArgs1.
@Test
void testQueueArgs1() throws MalformedURLException, URISyntaxException, InterruptedException {
Client client = new Client(brokerRunning.getAdminUri(), brokerRunning.getAdminUser(), brokerRunning.getAdminPassword());
QueueInfo queue = await().until(() -> client.getQueue("/", "all.args.1"), 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("reject-publish");
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.minLeaders.getValue());
assertThat(arguments.get("x-single-active-consumer")).isEqualTo(Boolean.TRUE);
}
Aggregations