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

最初の 2 つのエラーは receive のスペルが間違っているためですstd::cout<<consumer->recieve();:std::cout<<consumer->receive();

最後のエラーは、consumerがポインターとして使用されているためです: 行consumer->getMessage();を次のように変更します。consumer.getMessage();

于 2011-11-15T18:49:56.740 に答える