【问题标题】:Apache NMS on .NET fails to connect to ActiveMQ [Channel was inactive for too long].NET 上的 Apache NMS 无法连接到 ActiveMQ [通道太长时间处于非活动状态]
【发布时间】:2016-08-02 01:19:28
【问题描述】:

我正在尝试从 .NET 应用程序订阅 ActiveMQ 主题,下面是我的代码(我使用 Apache NMS 1.7.0):

using Apache.NMS;
using Apache.NMS.ActiveMQ;
...

public void Start()
{
    try {
        // connect to ActiveMQ
        long timestamp = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
        string providerUrl = String.Format("tcp://{0}:{1}", Host, Port);
        IConnectionFactory connectionFactory = new ConnectionFactory(providerUrl);

        connection = connectionFactory.CreateConnection(); // fails here
        connection.ClientId = String.Format("{0}/{1}/{2}", AssemblyInfo.Title, Username, timestamp);
        connection.Start();

        // create consumer and register callback for incoming messages
        ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
        IMessageConsumer messageConsumer = session.CreateConsumer(
            new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(TopicName), MessageSelector, false
        );

        messageConsumer.Listener += new MessageListener(OnMessage);
    } catch (Exception e) {
       _.Logger.Error(Resources.ErrorStartingConsumer, e.Message);
    }
}

public void OnMessage(IMessage message)
{
    if (!(message is ITextMessage)) {
        // 'message' is not a text message
        _.Logger.Warn(Resources.SkippedMessage, message.NMSMessageId);
    } else {
        string textMessage = (message as ITextMessage).Text;
        foreach (string acceptedProtocol in AcceptedProtocols) {
            if (textMessage.StartsWith(acceptedProtocol + ":")) {
                // process message here
                return;
            }
        }

        // the url contained in 'message' is not supported
        _.Logger.Warn(Resources.SkippedMessage, message.NMSMessageId);
    }
}

上面的代码编译成功...但是尝试连接到 ActiveMQ 服务器失败。下面是失败的语句...

connection = connectionFactory.CreateConnection(); 

...这是错误消息:

Channel was inactive for too long: tcp://172.16.126.194:61615

我有点困惑,因为即使这是我的客户端第一次尝试连接 ActiveMQ 服务器,我也会收到此错误。

我也试过设置wireformat.maxinactivityduration=0,但没办法。任何帮助将不胜感激。

【问题讨论】:

  • 听起来你没有连接到代理,你确定那个端口上有一个实时代理而不是别的什么。
  • 是的,telnet 172.16.126.194 61615 按预期工作。此外,通过 Java Producer,我可以向主题添加内容。
  • 该端口的代理端配置是什么,即 TransportConnector。真的不足以继续在这里提供帮助

标签: c# .net activemq apache-nms


【解决方案1】:

就我而言,我使用了错误的端口号来访问代理。我必须使用安全端口 61616。

【讨论】:

    【解决方案2】:

    在我们的例子中,端口 61615 是一个安全端口...所以我只需要像这样修改连接字符串:

        string providerUrl = String.Format("ssl://{0}:{1}", Host, Port);
    

    经过这个小修改后,一切都按预期工作。

    【讨论】:

      猜你喜欢
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多