logger.info("RabbitMQ:");
createService(VCAP_RABBIT_SERVICE, "rabbitmq", "2.4");
int tunnelPort = LOCAL_PORT + 4;
createTunnelServer(VCAP_RABBIT_SERVICE, tunnelPort);
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(LOCAL_HOST, tunnelPort);
connectionFactory.setUsername(svc_username);
connectionFactory.setPassword(svc_passwd);
connectionFactory.setVirtualHost(svc_vhost);
String queueName = "CLOUD";
AmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory);
Queue cloudQueue = new Queue(queueName);
amqpAdmin.declareQueue(cloudQueue);
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setRoutingKey(queueName);
template.setQueue(queueName);
template.afterPropertiesSet();
template.convertAndSend("Hello, CloudFoundry!");
template.convertAndSend("Hello, Spring!");
template.convertAndSend("Hello, Java!");
template.convertAndSend("Hello, Caldecott!");
template.convertAndSend("Hello, Rabbit!");
template.convertAndSend("Hello, AMQP!");
int count = 0;
while (true) {
String message = (String) template.receiveAndConvert();
if (message == null) {
break;
}
else {
count++;
}
}
Assert.assertEquals("Did not send/receive the messages correctly", 6, count);
connectionFactory.destroy();
stopTunnelServer();
removeService(VCAP_RABBIT_SERVICE);
logger.info("Time elapsed: " + (System.currentTimeMillis() - start) / 1000.0d + " sec");
}