ActiveMQ C ++同步消费者

时间:2011-11-15 18:29:41

标签: c++ activemq activemq-cpp

ActiveMQ C ++客户端有一些code samples,它们是异步的。我正在寻找的是同步消费者。我只是想发送和获取消息。我指出的代码使用异步,不知道如何从中创建同步类。

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();
        }
    }

1 个答案:

答案 0 :(得分:1)

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

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