Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMQP-812: Deprecate RabbitManagementTemplate #779

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ project('spring-rabbit') {
compile project(":spring-amqp")

compile "com.rabbitmq:amqp-client:$rabbitmqVersion"
compile "com.rabbitmq:http-client:$rabbitmqHttpClientVersion"
compile ("com.rabbitmq:http-client:$rabbitmqHttpClientVersion", optional)

compile ("org.springframework:spring-aop:$springVersion", optional)
compile "org.springframework:spring-context:$springVersion"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,9 @@
* @author Gary Russell
* @since 1.5
*
* @deprecated since 2.1 in favor of direct usage of target REST API client.
*/
@Deprecated
public interface AmqpManagementOperations {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AbstractExchange;
import org.springframework.amqp.core.AmqpManagementOperations;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Binding.DestinationType;
import org.springframework.amqp.core.DirectExchange;
Expand All @@ -48,8 +47,10 @@
*
* @since 1.5
*
* @deprecated since 2.1 in favor of direct {@link Client} usage.
*/
public class RabbitManagementTemplate implements AmqpManagementOperations {
@Deprecated
public class RabbitManagementTemplate implements org.springframework.amqp.core.AmqpManagementOperations {

private static final String DEFAULT_VHOST = "/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import org.springframework.amqp.rabbit.connection.ConnectionNameStrategy;
import org.springframework.amqp.rabbit.connection.SimplePropertyValueConnectionNameStrategy;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitManagementTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler;
Expand Down Expand Up @@ -140,6 +139,8 @@
import org.springframework.util.ErrorHandler;

import com.rabbitmq.client.Channel;
import com.rabbitmq.http.client.Client;
import com.rabbitmq.http.client.domain.QueueInfo;

/**
*
Expand Down Expand Up @@ -718,8 +719,8 @@ public void deadLetterOnDefaultExchange() {
this.rabbitTemplate.convertAndSend("amqp656", "foo");
assertEquals("foo", this.rabbitTemplate.receiveAndConvert("amqp656dlq", 10000));
try {
RabbitManagementTemplate rmt = new RabbitManagementTemplate();
org.springframework.amqp.core.Queue amqp656 = rmt.getQueue("amqp656");
Client rabbitRestClient = new Client("http://localhost:15672/api/", "guest", "guest");
QueueInfo amqp656 = rabbitRestClient.getQueue("/", "amqp656");
if (amqp656 != null) {
assertEquals("", amqp656.getArguments().get("test-empty"));
assertEquals("undefined", amqp656.getArguments().get("test-null"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
package org.springframework.amqp.rabbit.core;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
Expand All @@ -41,6 +40,7 @@
import org.springframework.amqp.core.Binding.DestinationType;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
Expand All @@ -56,6 +56,8 @@
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.http.client.Client;
import com.rabbitmq.http.client.domain.ExchangeInfo;

/**
* @author Dave Syer
Expand Down Expand Up @@ -260,8 +262,8 @@ public void testDeleteExchangeWithInternalOption() throws Exception {
exchange.setInternal(true);
rabbitAdmin.declareExchange(exchange);

Exchange exchange2 = getExchange(exchangeName);
assertThat(exchange2, instanceOf(DirectExchange.class));
ExchangeInfo exchange2 = getExchange(exchangeName);
assertEquals(ExchangeTypes.DIRECT, exchange2.getType());
assertTrue(exchange2.isInternal());

boolean result = rabbitAdmin.deleteExchange(exchangeName);
Expand Down Expand Up @@ -416,22 +418,22 @@ public void testDeclareDelayedExchange() throws Exception {
assertEquals(Integer.valueOf(1000), received.getMessageProperties().getReceivedDelay());
assertThat(System.currentTimeMillis() - t1, greaterThan(950L));

Exchange exchange2 = getExchange(exchangeName);
ExchangeInfo exchange2 = getExchange(exchangeName);
assertNotNull(exchange2);
assertThat(exchange2, instanceOf(DirectExchange.class));
assertTrue(exchange2.isDelayed());
assertEquals(ExchangeTypes.DIRECT, exchange2.getArguments().get("x-delayed-type"));
assertEquals("x-delayed-message", exchange2.getType());

this.rabbitAdmin.deleteQueue(queue.getName());
this.rabbitAdmin.deleteExchange(exchangeName);
}

private Exchange getExchange(String exchangeName) throws InterruptedException {
RabbitManagementTemplate rmt = new RabbitManagementTemplate();
private ExchangeInfo getExchange(String exchangeName) throws Exception {
Client rabbitRestClient = new Client("http://localhost:15672/api/", "guest", "guest");
int n = 0;
Exchange exchange = rmt.getExchange(exchangeName);
ExchangeInfo exchange = rabbitRestClient.getExchange("/", exchangeName);
while (n++ < 100 && exchange == null) {
Thread.sleep(100);
exchange = rmt.getExchange(exchangeName);
exchange = rabbitRestClient.getExchange("/", exchangeName);
}
return exchange;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,8 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -45,6 +47,9 @@

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.http.client.Client;
import com.rabbitmq.http.client.domain.BindingInfo;
import com.rabbitmq.http.client.domain.ExchangeInfo;
import com.rabbitmq.http.client.domain.QueueInfo;

/**
Expand All @@ -54,53 +59,58 @@
* @since 1.5
*
*/
public class RabbitManagementTemplateTests {
public class RabbitRestApiTests {

private final CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");

private final RabbitManagementTemplate template = new RabbitManagementTemplate();
private final Client rabbitRestClient;


@ClassRule
public static BrokerRunning brokerAndManagementRunning = BrokerRunning.isBrokerAndManagementRunning();

public RabbitRestApiTests() throws MalformedURLException, URISyntaxException {
this.rabbitRestClient = new Client("http://localhost:15672/api/", "guest", "guest");
}

@After
public void tearDown() {
connectionFactory.destroy();
}

@Test
public void testExchanges() {
List<Exchange> list = this.template.getExchanges();
List<ExchangeInfo> list = this.rabbitRestClient.getExchanges();
assertTrue(list.size() > 0);
}

@Test
public void testExchangesVhost() {
List<Exchange> list = this.template.getExchanges("/");
List<ExchangeInfo> list = this.rabbitRestClient.getExchanges("/");
assertTrue(list.size() > 0);
}

@Test
public void testBindings() {
List<Binding> list = this.template.getBindings();
List<BindingInfo> list = this.rabbitRestClient.getBindings();
assertTrue(list.size() > 0);
}

@Test
public void testBindingsVhost() {
List<Binding> list = this.template.getBindings("/");
List<BindingInfo> list = this.rabbitRestClient.getBindings("/");
assertTrue(list.size() > 0);
}

@Test
public void testQueues() {
List<Queue> list = this.template.getQueues();
List<QueueInfo> list = this.rabbitRestClient.getQueues();
assertTrue(list.size() > 0);
}

@Test
public void testQueuesVhost() {
List<Queue> list = this.template.getQueues("/");
List<QueueInfo> list = this.rabbitRestClient.getQueues("/");
assertTrue(list.size() > 0);
}

Expand All @@ -125,12 +135,12 @@ public void testBindingsDetail() {
.with("bar");
admin.declareBinding(binding2);

List<Binding> bindings = this.template.getBindingsForExchange("/", exchange1.getName());
List<BindingInfo> bindings = this.rabbitRestClient.getBindingsBySource("/", exchange1.getName());
assertEquals(2, bindings.size());
assertEquals(exchange1.getName(), bindings.get(0).getExchange());
assertEquals(exchange1.getName(), bindings.get(0).getSource());
assertThat("foo", anyOf(equalTo(bindings.get(0).getRoutingKey()), equalTo(bindings.get(1).getRoutingKey())));
Binding qout = null;
Binding eout = null;
BindingInfo qout = null;
BindingInfo eout = null;
if (bindings.get(0).getRoutingKey().equals("foo")) {
qout = bindings.get(0);
eout = bindings.get(1);
Expand All @@ -139,12 +149,12 @@ public void testBindingsDetail() {
eout = bindings.get(0);
qout = bindings.get(1);
}
assertEquals(Binding.DestinationType.QUEUE, qout.getDestinationType());
assertEquals("queue", qout.getDestinationType());
assertEquals(queue.getName(), qout.getDestination());
assertNotNull(qout.getArguments());
assertEquals("", qout.getArguments().get("alternate-exchange"));

assertEquals(Binding.DestinationType.EXCHANGE, eout.getDestinationType());
assertEquals("exchange", eout.getDestinationType());
assertEquals(exchange2.getName(), eout.getDestination());

admin.deleteExchange(exchange1.getName());
Expand All @@ -157,7 +167,7 @@ public void testSpecificExchange() {
Map<String, Object> args = Collections.<String, Object>singletonMap("alternate-exchange", "");
Exchange exchange = new DirectExchange(UUID.randomUUID().toString(), true, true, args);
admin.declareExchange(exchange);
Exchange exchangeOut = this.template.getExchange("/", exchange.getName());
ExchangeInfo exchangeOut = this.rabbitRestClient.getExchange("/", exchange.getName());
assertTrue(exchangeOut.isDurable());
assertTrue(exchangeOut.isAutoDelete());
assertEquals(exchange.getName(), exchangeOut.getName());
Expand All @@ -180,13 +190,13 @@ public void testSpecificQueue() throws Exception {
admin.declareQueue(queue2);
Channel channel = this.connectionFactory.createConnection().createChannel(false);
String consumer = channel.basicConsume(queue1.getName(), false, "", false, true, null, new DefaultConsumer(channel));
QueueInfo qi = this.template.getClient().getQueue("/", queue1.getName());
QueueInfo qi = this.rabbitRestClient.getQueue("/", queue1.getName());
int n = 0;
while (n++ < 100 && (qi.getExclusiveConsumerTag() == null || qi.getExclusiveConsumerTag().equals(""))) {
Thread.sleep(100);
qi = this.template.getClient().getQueue("/", queue1.getName());
qi = this.rabbitRestClient.getQueue("/", queue1.getName());
}
Queue queueOut = this.template.getQueue("/", queue1.getName());
QueueInfo queueOut = this.rabbitRestClient.getQueue("/", queue1.getName());
assertFalse(queueOut.isDurable());
assertFalse(queueOut.isExclusive());
assertTrue(queueOut.isAutoDelete());
Expand All @@ -196,7 +206,7 @@ public void testSpecificQueue() throws Exception {
channel.basicCancel(consumer);
channel.close();

queueOut = this.template.getQueue("/", queue2.getName());
queueOut = this.rabbitRestClient.getQueue("/", queue2.getName());
assertTrue(queueOut.isDurable());
assertFalse(queueOut.isExclusive());
assertFalse(queueOut.isAutoDelete());
Expand All @@ -211,12 +221,17 @@ public void testSpecificQueue() throws Exception {
public void testDeleteExchange() {
String exchangeName = "testExchange";
Exchange testExchange = new DirectExchange(exchangeName);
this.template.addExchange(testExchange);
Exchange exchangeToAssert = this.template.getExchange(exchangeName);
ExchangeInfo info = new ExchangeInfo();
info.setArguments(testExchange.getArguments());
info.setAutoDelete(testExchange.isAutoDelete());
info.setDurable(testExchange.isDurable());
info.setType(testExchange.getType());
this.rabbitRestClient.declareExchange("/", testExchange.getName(), info);
ExchangeInfo exchangeToAssert = this.rabbitRestClient.getExchange("/", exchangeName);
assertEquals(testExchange.getName(), exchangeToAssert.getName());
assertEquals(testExchange.getType(), exchangeToAssert.getType());
this.template.deleteExchange(testExchange);
assertNull(this.template.getExchange(exchangeName));
this.rabbitRestClient.deleteExchange("/", testExchange.getName());
assertNull(this.rabbitRestClient.getExchange("/", exchangeName));
}

}
Loading