gpt4 book ai didi

c++ - ActiveMQ C++ 同步消费者

转载 作者:行者123 更新时间:2023-11-28 08:14:18 25 4
gpt4 key购买 nike

有一些code samples对于异步的 ActiveMQ C++ 客户端。我正在寻找的是同步消费者。我只想发送和接收消息。我指出的代码使用异步并且不确定如何从中创建同步类。

MessageConsumer class表示有同步调用,即:recieve()。当我在我的对象上调用它时,它失败如下,我该如何解决这个问题?我怎样才能从队列中调用接收。

ActiveMQConsumer.cc: In member function `virtual void ActiveMQConsumer::getMessage()':
ActiveMQConsumer.cc:62: error: 'class cms::MessageConsumer' has no member named 'recieve'
In file included from ActiveMQWrapper.cc:29:
ActiveMQConsumer.cc: In member function `virtual void ActiveMQConsumer::getMessage()':
ActiveMQConsumer.cc:62: error: 'class cms::MessageConsumer' has no member named 'recieve'
ActiveMQWrapper.cc: In static member function `static std::string ActiveMQWrapper::get()':
ActiveMQWrapper.cc:58: error: base operand of `->' has non-pointer type `ActiveMQConsumer'

代码如下:

void ActiveMQWrapper::get(){

std:string brokerURI = "tcp://localhost:61613?wireFormat=stomp";

ActiveMQConsumer consumer( brokerURI);
consumer->getMessage();
}

// ActiveMQConsumer class code is following

virtual void getMessage() {

try {

auto_ptr<ConnectionFactory> connectionFactory(ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
connection = connectionFactory->createConnection();
connection->start();
session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
destination = session->createQueue( "TEST.Prototype" );
consumer = session->createConsumer( destination );
std::cout<<consumer->recieve();
} catch( CMSException& e ) {

e.printStackTrace();
}
}

最佳答案

前两个错误是因为receive拼写错误:更改std::cout<<consumer->recieve();std::cout<<consumer->receive();

最后一个错误是因为consumer用作指针:更改行 consumer->getMessage();consumer.getMessage();

关于c++ - ActiveMQ C++ 同步消费者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8141245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com