1 package dst.ass3.messaging;
3 import org.junit.rules.ExternalResource;
4 import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
5 import org.springframework.amqp.rabbit.core.RabbitAdmin;
6 import org.springframework.amqp.rabbit.core.RabbitManagementTemplate;
7 import org.springframework.amqp.rabbit.core.RabbitTemplate;
9 public class RabbitResource extends ExternalResource {
11 private RabbitAdmin admin;
12 private RabbitManagementTemplate manager;
13 private CachingConnectionFactory connectionFactory;
14 private RabbitTemplate client;
17 protected void before() throws Throwable {
18 manager = new RabbitManagementTemplate(Constants.RMQ_API_URL, Constants.RMQ_USER, Constants.RMQ_PASSWORD);
20 connectionFactory = new CachingConnectionFactory(Constants.RMQ_HOST);
21 connectionFactory.setUsername(Constants.RMQ_USER);
22 connectionFactory.setPassword(Constants.RMQ_PASSWORD);
24 client = new RabbitTemplate(connectionFactory);
25 admin = new RabbitAdmin(connectionFactory);
29 protected void after() {
30 connectionFactory.destroy();
33 public RabbitManagementTemplate getManager() {
37 public RabbitTemplate getClient() {
41 public RabbitAdmin getAdmin() {
45 public CachingConnectionFactory getConnectionFactory() {
46 return connectionFactory;