在C++中使用ActiveMQ时,可以通过以下步骤简化配置:
#include <activemq/ActiveMQ.h>
#include <activemq/core/ActiveMQConnectionFactory.h>
std::string brokerURL = "tcp://localhost:61616";
ActiveMQConnectionFactory* factory = new ActiveMQConnectionFactory(brokerURL);
try {
factory->createConnection();
} catch (CMSException& e) {
e.printStackTrace();
}
CMSSession* session = factory->createSession(false, Session::AUTO_ACKNOWLEDGE);
std::string destinationName = "queue://testQueue";
ActiveMQDestination* destination = session->createQueue(destinationName);
ActiveMQTextMessage* message = session->createTextMessage("Hello World!");
try {
destination->send(message);
} catch (CMSException& e) {
e.printStackTrace();
}
delete message;
delete session;
delete factory;
通过以上步骤,可以简化ActiveMQ的配置过程。需要注意的是,在实际使用中,还需要根据具体需求进行相应的配置,例如设置连接超时时间、消息回执策略等。