【问题标题】:ActiveMQ C++ Synchronous consumerActiveMQ C++ 同步消费者
【发布时间】:2019-11-05 06:37:09
【问题描述】:

ActiveMQ C++ 客户端有一些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();
        }
    }

【问题讨论】:

    标签: c++ activemq activemq-cpp


    【解决方案1】:

    前两个错误是因为receive拼写错误:将std::cout&lt;&lt;consumer-&gt;recieve();改为std::cout&lt;&lt;consumer-&gt;receive();

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

    【讨论】:

      猜你喜欢
      • 2015-11-25
      • 2014-08-06
      • 2020-09-30
      • 2012-04-18
      • 2021-12-02
      • 2012-12-24
      • 1970-01-01
      • 2015-07-23
      • 1970-01-01
      相关资源
      最近更新 更多