ActiveMQ C++ Synchronous consumer

▼魔方 西西 提交于 2020-01-14 06:26:06

问题


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 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'

and here is the code:

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:


The first two errors are because receive is misspelled: Change std::cout<<consumer->recieve(); to std::cout<<consumer->receive();

The last error is because consumer is being used as a pointer: Change the line consumer->getMessage(); to consumer.getMessage();



来源:https://stackoverflow.com/questions/8141245/activemq-c-synchronous-consumer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!