2012-01-06 19 views
0

メッセージをブローカに送信するときにactivemq接続のタイムアウトプロパティを設定しました。activemq-cppステータスを送信または受信する方法を得るには

しかし、私はタイムアウトを送信するときに例外やリターンを得ることができませんでした。

送信成功またはタイムアウトのステータスを取得できませんでした。

これは私がreceive(long long timeout)を使用したときにも起こりました。

これら2つの状態を区別する方法はありますか?

バージョンのActiveMQ 5.4.2 ActiveMQの-CPP 3.2.5

URI:

failover:(tcp://192.168.32.11:61617) without any option, all use default. 

接続コード:

bool CActiveMqProducer::Initial() 
{ 
    try 
    { 
     activemq::library::ActiveMQCPP::initializeLibrary(); 

     //sure has been cleaned up before initial 
     if (!m_bCleanUp) 
      CleanUp(); 

     if(m_strBrokerURI == "" || m_strDestURI == "") 
     { 
      printf("MQ initial failed for m_strBrokerURI == \"\" || m_strDestURI == \"\"\n"); 
      return false; 
     } 

     //create a connection factory 
     auto_ptr<ActiveMQConnectionFactory> ConnFactoryPtr(new ActiveMQConnectionFactory(m_strBrokerURI, m_strAccount, m_strPsw)); 

     // Create a Connection 
     try 
     { 
      m_pConnObj = ConnFactoryPtr->createConnection(); 
      if(m_pConnObj != NULL) 
      { 

       ActiveMQConnection* amqConnection = dynamic_cast<ActiveMQConnection*>(m_pConnObj); 
       amqConnection->setSendTimeout(m_unSendTimeout); 
       //here set send timeout option 
      } 
      else 
      { 
       return false; 
      } 

      m_pConnObj->start(); 
     } 
     catch (CMSException& e) 
     { 
      e.printStackTrace(); 
      throw e; 
     } 

     // Create a Session 
     if (m_bClientAck) 
     { 
      m_pSession = m_pConnObj->createSession(Session::CLIENT_ACKNOWLEDGE); 
      if(m_pSession == NULL) 
       return false; 
     } 
     else 
     { 
      m_pSession = m_pConnObj->createSession(Session::AUTO_ACKNOWLEDGE); 
      if(m_pSession == NULL) 
       return false; 
     } 

     // Create the destination (Topic or Queue) 
     if (m_bUseTopic) 
     { 
      m_pMsgDest = m_pSession->createTopic(m_strDestURI); 
      if(m_pMsgDest == NULL) 
       return false; 
     } 
     else 
     { 
      m_pMsgDest = m_pSession->createQueue(m_strDestURI); 
      if(m_pMsgDest == NULL) 
       return false; 
     } 

     // Create a MessageProducer from the Session to the Topic or Queue 
     m_pMsgProducer = m_pSession->createProducer(m_pMsgDest); 
     if(m_pMsgProducer == NULL) 
      return false; 
     if(m_bPresistent) 
     { 
      m_pMsgProducer->setDeliveryMode(DeliveryMode::PERSISTENT); 
     } 
     else 
     { 
      m_pMsgProducer->setDeliveryMode(DeliveryMode::NON_PERSISTENT); 
     } 

     //control the logic 
     m_bInitialized = true; 
     m_bCleanUp = false; 

    } 
    catch (CMSException& e) 
    { 
     e.printStackTrace(); 
     return false; 
    } 
    return true; 
} 

送信コード:

bool CActiveMqProducer::SendTextMessage(const char* msg, int deliveryMode, int priority, long long timeToLive, std::map<std::string,std::string> property) 
{ 
    try 
    { 
     if(!m_bInitialized) 
     { 
      printf("MQ client has not been initialized!\n"); 
      return false; 
     } 
     TextMessage * tmsg = m_pSession->createTextMessage(); 
     tmsg->setText(msg); 
     std::map<std::string, std::string>::iterator it = property.begin(); 
     for(; it != property.end(); it++) 
     { 
      tmsg->setStringProperty(it->first,it->second); 
     } 

     m_pMsgProducer->send(tmsg, deliveryMode, priority, timeToLive); 

     delete tmsg; 
    } 
    catch(MessageFormatException &e) 
    { 
     e.printStackTrace(); 
     return false; 
    } 
    catch(InvalidDestinationException &e) 
    { 
     e.printStackTrace(); 
     return false; 
    } 
    catch(UnsupportedOperationException &e) 
    { 
     e.printStackTrace(); 
     return false; 
    } 
    catch(CMSException &e) 
    { 
     //if an internal error occurs while sending the message. 
     e.printStackTrace(); 
     return false; 
    } 
    return true; 

} 

答えて

0

まず、最新のリリースv3.4.1を使用することをおすすめします。これに影響を与える可能性のある多くの修正があります。次に、タイムアウト値を渡すと、受信からNULLが返されます。

タイムアウトオプションに関しては、あなたが設定していることを言いますと、あなたが設定しているオプションがカップルであることをより明確にする必要があります。メッセージが同期して送信されたときにタイムアウトに使用されるrequestTimeoutがあり、ブローカ接続が切断されたときに起動するタイムアウトオプションがフェールオーバートランスポートにあります。

AlwaysSyncSendオプションを設定していない場合は、コードやURIがすべて表示されているので、ここでは何が起こっているのか分かりませんが、メッセージは非同期で送信されます。

+0

V3.2.5の新バージョンでリリースv3.4.1を使用していますが、PrefetchSizeオプションを使用できません。質問後に表示されるコードとURI。私はuriにオプションを設定していません。 AlwaysSyncSendのデフォルト値はfalseです。 – jaylong35

+0

@Tim Bishこの質問をご覧ください.http://stackoverflow.com/questions/19706788/jersey-rest-web-service-with-activemq-middleware-integration時間をいただきありがとうございます。 – Kumar

関連する問題