2011-11-15 183 views
0

ActiveMQ C++ Client有一些code samples,它們是異步的。我正在尋找的是同步消費者。我只想發送和獲取消息。我指出的代碼使用了異步,並不確定如何從中創建一個同步類。ActiveMQ C++同步消費者

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

前兩個錯誤,因爲接收的拼寫錯誤:更改std::cout<<consumer->recieve();std::cout<<consumer->receive();

的最後一個錯誤是因爲consumer被用作指針:將行consumer->getMessage();更改爲consumer.getMessage();