qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gordon Sim <g...@redhat.com>
Subject Re: send/receive to/from remote machine
Date Fri, 20 Mar 2009 15:26:46 GMT
ft420 wrote:
> I did following:
> connection.open(host, port);
> Session session = connection.newSession();
>                         :
>                         :
>                         :
> SubscriptionManager sub(session);
> sub.setAcquireMode(ACQUIRE_MODE_PRE_ACQUIRED);
> 
> for (uint i = 0; i < queueMsgCnt; i++)
> {
>     sub.get(message, "myqueue");
>     cout << "Message is " << message.getData() << endl;
> }
> 
> But this get() call on SubscriptionManager object removes message from queue
> instead of just peeking/browsing it from queue.

Yes, I don't think I like the default acquire mode on the subscription 
manager and certainly the get() method ignores it anyway.

> Please let me know where am i going wrong?? how to use
> ACQUIRE_MODE_PRE_ACQUIRED for peeking/browsing messages??

Option 1: browsing using NOT_ACQUIRED

SubscriptionManager sub(session);
SubscriptionSettings settings;
settings.acquireMode = ACQUIRE_MODE_NOT_ACQUIRED;
LocalQueue incoming;
sub.subscribe(incoming, "myqueue", settings);
....
for (uint i = 0; i < queueMsgCnt; i++)
{
     incoming.get(message);
     cout << "Message is " << message.getData() << endl;
}

Option 2: releasing PRE_ACQUIREd messages:

SubscriptionManager sub(session);
SubscriptionSettings settings;
settings.acquireMode = ACQUIRE_MODE_PRE_ACQUIRED;
settings.autoAck = 0;
LocalQueue incoming;
Subscription s = sub.subscribe(incoming, "myqueue", settings);
....
for (uint i = 0; i < queueMsgCnt; i++)
{
     incoming.get(message);
     cout << "Message is " << message.getData() << endl;
}
s.cancel();
s.release(s.getUnaccepted());//messages are left on the queue

(You can use a MessageListener instead of the LocalQueue if you prefer a 
push style interface to the pull style above).

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Mime
View raw message