ActiveMQ C ++ Client有一些code samples,它们是异步的。我正在寻找的是同步消费者。我只想发送和接收消息。我指出的代码使用异步,并且不确定如何使用它制作一个同步类。

MessageConsumer类指示存在一个同步调用,即: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();
        }
    }

最佳答案

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

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

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

10-13 08:48