ActiveMq NMS 大约 30 秒后断开连接

发布于 2024-08-17 19:55:49 字数 1466 浏览 4 评论 0原文

我正在尝试使用 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默认情况下

有什么想法吗?

'm trying to do simple pub/sub with ActiveMq. I can get it all working fine, but the subscriber disconnects after about 30 seconds. I've looked for a timeout type of value I can change but nothing seems to be working. Here is the subscriber:

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);
        }
    }
}

I tried this:

connection.RequestTimeout = TimeSpan.MaxValue;

But it didn't seem to change anything.

To get the problem just run the program and sit waiting for about 30 seconds. You can see the connection disappear in the ActiveMQ Console (http://localhost:8161/admin/connections.jsp by default)

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

感情洁癖 2024-08-24 19:55:49

当然,我在发布问题后几分钟就弄清楚了。这是其他人寻找的答案:

问题是 NMS 使用 OpenWire,而 OpenWire 默认情况下有 30 秒超时。您可以在 \conf\ActiveMq.xml 文件中更改此设置。以下是您需要更改的内容:

<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?wireFormat.maxInactivityDuration=0"/>
</transportConnectors>

wireFormat.maxInactivityDuration 参数是关键。

Of course I figure it out just a few minutes after posting the question. Here is the answer for anyone else looking:

The problem is that NMS is using OpenWire, and OpenWire by default has a 30 second timeout. You can change this in the \conf\ActiveMq.xml file. Here is what you need to change:

<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?wireFormat.maxInactivityDuration=0"/>
</transportConnectors>

That wireFormat.maxInactivityDuration parameter is the key.

一向肩并 2024-08-24 19:55:49

警告!
看起来,如果您设置 maxInactivityDuration=0 ,那么套接字永远不会消失。
即使您在 IConnection 上调用 CloseDispose ,底层连接及其运行的线程仍然保留。
根据您的实现,这可能意味着内存泄漏。

WARNING!
It appears that if you set maxInactivityDuration=0 then the socket never dies.
Even if you call Close and Dispose on your IConnection , the underlying connection and the thread it is running on still remain.
Depending on your implementation, this could could mean a memory leak.

北笙凉宸 2024-08-24 19:55:49

听起来您使用的是较旧版本的 NMS,请尝试更新到最新版本 (1.5.5),此问题应该会消失。有几个与故障转移和不活动监视器相关的问题已在最近几个版本中全部解决。最新版本已得到很好的强化。

蒂姆
Fusesource.com

Sounds like you are using an older version of NMS, try updating to the latest release (1.5.5) and this problem should go away. There were several issues related to failover and inactivity monitor that have all been resolved in the last several releases. The latest version is well hardened.

Tim
Fusesource.com

弃爱 2024-08-24 19:55:49

不确定它是一个答案还是一个更多的问题(或两个;),

但在我们的 NMS 使用中,我们指定wireFormat.MaxInactivityDuration=-1
在客户端的连接 url 中。

似乎有相同的效果,但我们应该使用“-1”还是“0”......?
想知道,有什么区别...

另外,有趣的是,不知怎的,我们没有在服务器配置上指定任何内容,但我们所有的 JAVA 应用程序连接似乎无论如何都保持连接(是因为 JAVA 客户端对 OpenWire config.params 使用不同的默认值吗?或者短信?)

Not sure if it's an answer or a more of a question (or two ;),

but in our NMS use, we specify wireFormat.MaxInactivityDuration=-1
on the client side in connection url.

Seems to have same effect, but should we use "-1" or "0"... ??
Wonder, what's the difference...

Also, interestingly enough, somehow we don't specify anything on server config, but all our JAVA app connections seems to stay conneccted regardless (is it because JAVA client uses a different default for OpenWire config.params or smtng?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文