1) In the producer code, you should be setting the TimeToLive (the line you
have commented out), not the Expiration in the message directly.  TTL =
currentTime + 1000, for example.  Remember, this is just a temporary
work-around, in the future it will be TTL = 1000, which will match the JMS
API.  Expiration is a field in the message that is set by the JMS provider.
When you send a message, the MessageProducer will overwrite your value for
Expiration with what it thinks it should be (currently the time to live
value).
2) Since you're using an asynchronous consumer your onMessage method will be
called back asynchronously ... as soon as the message is received on the
wire.  I think the best bet would be to use the current time as your
TimeToLive (TTL) value.  The odds of your message being sent to the broker,
processed, and then sent back to the consumer in a single millisecond are
pretty small.  If you still receive the message, it may be an issue with the
broker.

On 11/29/06, sgliu <[EMAIL PROTECTED]> wrote:


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.


Reply via email to