試圖用ActiveMq做簡單的pub/sub。我可以很好地工作,但約30秒後用戶斷開連接。我找了一個超時類型的值,我可以改變,但似乎沒有任何工作。這裏是用戶:ActiveMq NMS在大約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)
任何想法?
好的。現在我必須像這樣實現它,因爲知道有泄漏的可能性。還沒有找到更好的方法。 – Kelly 2010-08-11 23:31:59