ActiveMQ-恢复连接后,CreateSession故障转移超时 [英] ActiveMQ - CreateSession failover timeout after a connection is resumed

查看:476
本文介绍了ActiveMQ-恢复连接后,CreateSession故障转移超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ActiveMQ 5.6.0和ActiveMQ NMS客户端。

I'm using ActiveMQ 5.6.0 and ActiveMQ NMS client.

我使用以下代码连接到代理:

I connect to the broker using the follow code:

var connectionFactory = new ConnectionFactory(
    "failover:(tcp://localhost:61616)?transport.timeout=5000"
    );

connection = connectionFactory.CreateConnection();    
connection.Start();

connection.ConnectionResumedListener += OnConnectionResumed;

然后我停止经纪人并重新启动。之后,在方法OnConnectionResumed

Then I stop the broker and start it again. After that in the method OnConnectionResumed

private void OnConnectionResumed()
{
    var session = connection.CreateSession();

    ...
}

我总是得到故障转移尝试创建会话时发生超时异常。

I always get the failover timeout exception when try to create a session.

我在做什么错了?

谢谢

推荐答案

出现此问题是因为我在其中进行了
恢复呼叫的线程中创建了一个会话。

This problem appeared because I had created a session in the thread where the resumed call is made in.

正确的代码是:

The correct code is:

private void OnConnectionResumed()
{
    Task.Factory.StartNew(() =>
        {
            var session = connection.CreateSession();

            ...
        });
}

这篇关于ActiveMQ-恢复连接后,CreateSession故障转移超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆