0

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

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

1 回答 1

1

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

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

于 2011-11-15T18:49:56.740 回答