我在遍歷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上正常工作,但在通過防火牆時無法正常工作。 –
你可以實現你自己的心跳消息來保持連接的活動 - 你可以讓你的用戶發送消息到隊列並再次接收它們。 –