【发布时间】:2011-01-05 14:33:28
【问题描述】:
正在尝试使用 ActiveMq 进行简单的发布/订阅。我可以让它一切正常,但订阅者在大约 30 秒后断开连接。我一直在寻找可以更改的超时类型值,但似乎没有任何效果。这是订阅者:
using System;
using Apache.NMS;
using Apache.NMS.ActiveMQ;
using Apache.NMS.ActiveMQ.Commands;
namespace ActiveMQCatcher
{
internal class Program
{
private static void Main(string[] args)
{
IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616/");
using (IConnection connection = factory.CreateConnection())
{
connection.ClientId = "MYID";
connection.Start();
using (ISession session = connection.CreateSession())
{
IMessageConsumer consumer = session.CreateConsumer(new ActiveMQTopic("MYTOPIC"), null, false);
consumer.Listener += consumer_Listener;
Console.ReadLine();
}
connection.Stop();
}
}
private static void consumer_Listener(IMessage message)
{
Console.WriteLine("Got: " + ((ITextMessage) message).Text);
}
}
}
我试过了:
connection.RequestTimeout = TimeSpan.MaxValue;
但它似乎并没有改变任何东西。
要解决问题,只需运行程序并等待大约 30 秒。您可以在 ActiveMQ 控制台中看到连接消失(默认为http://localhost:8161/admin/connections.jsp)
有什么想法吗?
【问题讨论】: