有没有办法为RabbitMQ的Java客户端设置代理?
package com.rabbitmq;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;
public class SendToRabbitMQ {
private final static String QUEUE_NAME = "observation_queue";
public static void sendObservation(String observation) {
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("x.x.x.x");
factory.setUsername("test");
factory.setVirtualHost("test_vh");
factory.setPassword("test");
Connection con = factory.newConnection();
Channel channel = con.createChannel();
channel.queueDeclare(QUEUE_NAME, true, false, false, null);
channel.basicPublish( "", QUEUE_NAME,
MessageProperties.PERSISTENT_TEXT_PLAIN,
observation.getBytes());
System.out.println(" Ovservation Sent '" + observation + "'");
channel.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
我想为这个连接设置代理。