use of com.rabbitmq.http.client.Client 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");
}
use of com.rabbitmq.http.client.Client 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;
}
use of com.rabbitmq.http.client.Client in project spring-amqp by spring-projects.
the class FixedReplyQueueDeadLetterTests method testQueueArgs3.
@Test
void testQueueArgs3() throws MalformedURLException, URISyntaxException, InterruptedException {
Client client = new Client(brokerRunning.getAdminUri(), brokerRunning.getAdminUser(), brokerRunning.getAdminPassword());
QueueInfo queue = await().until(() -> client.getQueue("/", "all.args.3"), 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.random.getValue());
ExchangeInfo exchange = client.getExchange("/", "dlx.test.requestEx");
assertThat(exchange.getArguments().get("alternate-exchange")).isEqualTo("alternate");
}
use of com.rabbitmq.http.client.Client in project spring-amqp by spring-projects.
the class LocalizedQueueConnectionFactoryTests method testFailOver.
@Test
public void testFailOver() throws Exception {
ConnectionFactory defaultConnectionFactory = mockCF("localhost:1234", null);
String rabbit1 = "localhost:1235";
String rabbit2 = "localhost:1236";
String[] addresses = new String[] { rabbit1, rabbit2 };
String[] adminUris = new String[] { "http://localhost:11235", "http://localhost:11236" };
String[] nodes = new String[] { "rabbit@foo", "rabbit@bar" };
String vhost = "/";
String username = "guest";
String password = "guest";
final AtomicBoolean firstServer = new AtomicBoolean(true);
final Client client1 = doCreateClient(adminUris[0], username, password, nodes[0]);
final Client client2 = doCreateClient(adminUris[1], username, password, nodes[1]);
final Map<String, ConnectionFactory> mockCFs = new HashMap<String, ConnectionFactory>();
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
mockCFs.put(rabbit1, mockCF(rabbit1, latch1));
mockCFs.put(rabbit2, mockCF(rabbit2, latch2));
LocalizedQueueConnectionFactory lqcf = new LocalizedQueueConnectionFactory(defaultConnectionFactory, addresses, adminUris, nodes, vhost, username, password, false, null) {
@Override
protected Client createClient(String adminUri, String username, String password) {
return firstServer.get() ? client1 : client2;
}
@Override
protected ConnectionFactory createConnectionFactory(String address, String node) {
return mockCFs.get(address);
}
};
Map<?, ?> nodeAddress = TestUtils.getPropertyValue(lqcf, "nodeToAddress", Map.class);
assertThat(nodeAddress.get("rabbit@foo")).isEqualTo(rabbit1);
assertThat(nodeAddress.get("rabbit@bar")).isEqualTo(rabbit2);
String[] admins = TestUtils.getPropertyValue(lqcf, "adminUris", String[].class);
assertThat(admins).containsExactly(adminUris);
Log logger = spy(TestUtils.getPropertyValue(lqcf, "logger", Log.class));
willReturn(true).given(logger).isInfoEnabled();
new DirectFieldAccessor(lqcf).setPropertyValue("logger", logger);
willAnswer(new CallsRealMethods()).given(logger).debug(anyString());
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(lqcf);
container.setQueueNames("q");
container.afterPropertiesSet();
container.start();
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
Channel channel = this.channels.get(rabbit1);
assertThat(channel).isNotNull();
verify(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), any(Consumer.class));
verify(logger, atLeast(1)).info(captor.capture());
assertThat(assertLog(captor.getAllValues(), "Queue: q is on node: rabbit@foo at: localhost:1235")).isTrue();
// Fail rabbit1 and verify the container switches to rabbit2
firstServer.set(false);
this.consumers.get(rabbit1).handleCancel(consumerTags.get(rabbit1));
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
channel = this.channels.get(rabbit2);
assertThat(channel).isNotNull();
verify(channel).basicConsume(anyString(), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), any(Consumer.class));
container.stop();
verify(logger, atLeast(1)).info(captor.capture());
assertThat(assertLog(captor.getAllValues(), "Queue: q is on node: rabbit@bar at: localhost:1236")).isTrue();
}
use of com.rabbitmq.http.client.Client in project spring-amqp by spring-projects.
the class EnableRabbitIntegrationTests method deadLetterOnDefaultExchange.
@Test
public void deadLetterOnDefaultExchange() {
this.rabbitTemplate.convertAndSend("amqp656", "foo");
assertThat(this.rabbitTemplate.receiveAndConvert("amqp656dlq", 10000)).isEqualTo("foo");
try {
Client rabbitRestClient = new Client("http://localhost:15672/api/", "guest", "guest");
QueueInfo amqp656 = rabbitRestClient.getQueue("/", "amqp656");
if (amqp656 != null) {
assertThat(amqp656.getArguments().get("test-empty")).isEqualTo("");
assertThat(amqp656.getArguments().get("test-null")).isEqualTo("undefined");
}
} catch (Exception e) {
// empty
}
}
Aggregations