我在遍历CISCO ASA 5505防火墙时订阅RabbitMQ消息时遇到问题。看起来在防火墙中存在某种超时,它会关闭空闲连接,并导致我的RabbitMQ订阅被无声地丢弃。结果是我的订阅者不会抛出/显示任何异常,但不会收到发布的消息。RabbitMQ用户超时
public class RabbitMqSubscriber<T extends Serializable> implements Subscriber<T> {
private QueueingConsumer consumer;
private MessageListener<T> listener;
private String exchange;
private String topic;
public RabbitMqSubscriber(String host,String exchange,String topic) throws IOException {
this.exchange=exchange;
this.topic=topic;
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(host);
factory.setRequestedHeartbeat(10);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(exchange, "topic");
String queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, exchange, topic);
consumer = new QueueingConsumer(channel);
channel.basicConsume(queueName, true, consumer);
}
public void run() {
while (true) {
QueueingConsumer.Delivery delivery;
try {
delivery = consumer.nextDelivery();
Object o=SerializationUtils.deserialize(delivery.getBody());
listener.receive((T)o);
} catch (ShutdownSignalException | ConsumerCancelledException | InterruptedException e) {
throw new RuntimeException(e);
}
}
}
@Override
public void setListener(MessageListener<T> listener) {
this.listener=listener;
}
}
我也尝试添加到存活的服务器配置,但这并没有帮助或者:
[ {rabbit, [{tcp_listen_options, [binary,
{packet, raw},
{reuseaddr, true},
{backlog, 128},
{nodelay, true},
{exit_on_close, false},
{keepalive, true}]}]}].
这似乎是一个防火墙问题......在Intranet上正常工作,但在通过防火墙时无法正常工作。 –
你可以实现你自己的心跳消息来保持连接的活动 - 你可以让你的用户发送消息到队列并再次接收它们。 –