本文介绍了ActiveMQ C ++同步消费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 ActiveMQ C ++客户端有一些代码示例,它们是异步的。我所寻找的是同步消费者。我只是想发送和获得消息。我已经指出的代码使用异步,不知道如何使一个同步类出来。There are some code samples for ActiveMQ C++ Client, which are asynchronous. What I am looking for is synchronous consumer. I just want to send and get messages. The code I have pointed out uses asynchronous and not sure how to make a synchronous class out of it. MessageConsumer 类指示存在同步调用,即:recieve()。 当我调用这个对我的对象,它失败如下,我该如何解决这个?我怎么能只是从队列呼叫接收。 MessageConsumer class indicates that there is a synchronous call, ie: recieve().When i call this on my object it fails as follows, how can i fix this? how can i just call a recieve from queue. 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 followingvirtual 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(); } } 推荐答案前两个错误是因为接收是拼写错误的:更改 std :: cout to std :: cout The first two errors are because receive is misspelled: Change std::cout<<consumer->recieve(); to std::cout<<consumer->receive();最后一个错误是因为 consumer 用作指针:将 consumer-> getMessage(); 更改为 consumer.getMessage(); The last error is because consumer is being used as a pointer: Change the line consumer->getMessage(); to consumer.getMessage(); 这篇关于ActiveMQ C ++同步消费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 06:46