In Producer,follow code: ... #include <sys/timeb.h> unsigned long getcurt() { struct timeb t; ftime (&t); unsigned long timeStamp = (t.time * 1000LL) + t.millitm; return timeStamp; } ... destination = session->createTopic( "mytopic" ); producer = session->createProducer( destination ); producer->setDeliveryMode( DeliveryMode::PERSISTANT ); ... unsigned long ttt=getcurt(); message->setCMSTimeStamp(ttt); message->setCMSExpiration(ttt + 10000); //producer->setTimeToLive(10000); producer->send( message ); ...
In Consumer ,follow code: ... ... ... virtual void run() { try { string user,passwd,sID; user="default"; passwd=""; sID="lsgID"; // Create a ConnectionFactory ActiveMQConnectionFactory* connectionFactory = new ActiveMQConnectionFactory( "tcp://localhost:61613",user,passwd,sID); // Create a Connection connection = connectionFactory->createConnection();//user,passwd,sID); delete connectionFactory; connection->start(); connection->setExceptionListener(this); session = connection->createSession( Session::AUTO_ACKNOWLEDGE ); destination = session->createTopic( "mytopic?consumer.retroactive=true" ); consumer = session->createDurableConsumer( destination , user , "",false); consumer->setMessageListener( this ); Thread::sleep( waitMillis ); } catch (CMSException& e) { e.printStackTrace(); } } virtual void onMessage( const Message* message ){ try { const TextMessage* textMessage = dynamic_cast< const TextMessage* >( message ); string text = textMessage->getText(); printf( "Received: %s\n", text.c_str() ); } catch (CMSException& e) { e.printStackTrace(); } } virtual void onException( const CMSException& ex ) { printf("JMS Exception occured. Shutting down client.\n"); } ... ... I hope: send first,a few time later,I receive nothing. (a few time later,message will disappear itself.) (I use visual C++ 2005) Please help me. I guess I'm not sure exactly what you're trying to do. I don't see a consumer in the code snippets. Is your consumer a C++ or Java client? Are you using an asynchronous consumer through the MessageListener interface, or are you calling receive() after a timed wait? -- View this message in context: http://www.nabble.com/Message%27s-live-time-tf2706004.html#a7597066 Sent from the ActiveMQ - User mailing list archive at Nabble.com.