You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ActiveMQ C++ SSL连接start()方法挂起问题求助

ActiveMQ-CPP SSL连接start()方法无响应问题

我正尝试让activemq-cpp库实现SSL连接功能,普通TCP连接可正常工作,但使用SSL Broker URL时,connection的*start()*方法始终无法返回。tcpdump显示运行代码时没有向61617端口发送数据包,但Python STOMP客户端已成功实现SSL连接,因此问题大概率不在Broker端。

C++测试代码

#include <iostream>

#include <activemq/library/ActiveMQCPP.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
#include <activemq/util/Config.h>
#include <decaf/lang/System.h>
#include <cms/Connection.h>

/*
 * Build exe with: g++ -std=c++11 -o main -I/usr/include/activemq-cpp-3.9.3 -I/usr/include/apr-1 -lactivemq-cpp -ldl -luuid main.cpp
 */

int main()
{

  using namespace cms;

  activemq::library::ActiveMQCPP::initializeLibrary();

  {
    // Setting SSL params
    decaf::lang::System::setProperty( "decaf.net.ssl.keyStore", "/home/pcarter/tmp/active_mq_question/client.pem" );
    decaf::lang::System::setProperty( "decaf.net.ssl.keyStorePassword", "password" );
    decaf::lang::System::setProperty( "decaf.net.ssl.trustStore", "/home/pcarter/tmp/active_mq_question/broker.pem" );

    // Program works fine with tcp url below
    //std::string broker_url = "failover:(tcp://localhost:61616)";

    // Program locks up in start() call with ssl url below:
    std::string broker_url = "failover:(ssl://localhost:61617)";

    // Create a ConnectionFactory
    std::unique_ptr<ConnectionFactory> connection_factory(
             ConnectionFactory::createCMSConnectionFactory(broker_url));

    // Create a Connection
    std::unique_ptr<cms::Connection> connection(connection_factory->createConnection());

    std::cout << "Calling start()" << std::endl;
    connection->start();   // This never returns
    std::cout << "start() returned" << std::endl;

  }
  activemq::library::ActiveMQCPP::shutdownLibrary();

  return 0;
}

ActiveMQ Broker配置(activemq.xml)

<transportConnectors>
   <transportConnector name="stomp+ssl" uri="stomp+nio+ssl://0.0.0.0:61613?transport.enabledProtocols=TLSv1.2&amp;needClientAuth=true" />
   <transportConnector name="ssl" uri="ssl://0.0.0.0:61617?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600&amp;needClientAuth=true" />
   <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>

环境信息

  • 系统:CentOS 7
  • ActiveMQ-CPP版本:3.9.3(通过yum安装)
  • 编译器:gcc 4.8.5
  • 证书生成遵循标准SSL证书生成步骤,且Python STOMP客户端可正常通过SSL连接Broker

内容的提问来源于stack exchange,提问作者pcarter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 22:55:18