2012-01-06 4 views
0

메시지를 브로커에 보낼 때 activemq 연결에 대한 timeout 속성을 설정했습니다.activemq-cpp 상태를 보내거나받는 시간을 얻는 방법

그러나 예외가 발생하지 않았거나 제한 시간을 보낼 때 반환 할 수 없었습니다.

송신 성공 또는 시간 초과 상태를 얻을 수 없습니다.

이것은 수신 (long long timeout)을 사용할 때도 발생합니다.

이 두 상태를 구별 할 수있는 방법이 있습니까?

버전의 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이 있으며 브로커 연결이 끊어졌을 때 작동하는 장애 조치 전송에 시간 초과 옵션이 있습니다.

모든 코드 나 URI를 표시 했으므로 여기에서 모든 일이 일어나고 있지만 AlwaysSyncSend 옵션을 설정하지 않은 경우에는 보내기가 가능하므로 메시지가 비동기로 전송됩니다.

+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

관련 문제