메시지를 브로커에 보낼 때 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;
}
V3.2.5 용 새 버전에서는 릴리스 v3.4.1을 사용할 예정이며 PrefetchSize 옵션을 사용할 수 없습니다. 질문 뒤에 표시되는 코드와 URI. uri에 옵션을 설정하지 않았습니다. AlwaysSyncSend의 기본값은 false입니다. – jaylong35
@Tim Bish이 질문을보십시오 .http : //stackoverflow.com/questions/19706788/jersey-rest-web-service-with-activemq-middleware-integration 시간 내 주셔서 감사합니다. – Kumar