qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Acácio Centeno <acacio.cent...@terra.com.br>
Subject Re: Behaviour when there're elements on the queue before instantiating the consumers
Date Tue, 15 Dec 2009 16:08:00 GMT
Hello Mr. Sim,

	Could you give me an example on using flow control? I tried this,
expecting to limit the amount of messages to be consumed to five, but almost
all the messages on the queue were consumed (I'm also fuzzy about why not
all of them were consumed):

#include <iostream>

#include <qpid/client/Connection.h>
#include <qpid/client/Session.h>
#include <qpid/client/Message.h>
#include <qpid/client/SubscriptionManager.h>

using namespace std;
using namespace qpid::client;
using namespace qpid::framing;

int main(int argc, char *argv[]) {
   Connection           connection;
   ConnectionSettings   settings;
   Session              session;
   SubscriptionManager  *mngr;
   LocalQueue           incoming;
   Message              m;

   pid_t                pid = getpid();

   try {
      settings.host = "localhost";
      settings.port = 5672;
      settings.virtualhost = "bridge";
      settings.mechanism = "ANONYMOUS";
      settings.tcpNoDelay = false;

      connection.open(settings);
      session = connection.newSession();

      mngr = new SubscriptionManager( session );
      mngr->subscribe(incoming, "teste_flow");
      // O esperado eh que apenas 5 elementos sejam consumidos.
      mngr->setFlowControl( "teste_flow", 5, 0, false );

      while ( incoming.get(m, 1000000L) ) {
         printf("[%d] [%s]\n", pid, m.getData().c_str());
      }

      printf("[%d] finalizado.\n", pid);
   } catch(const std::exception& error) {
      fprintf(stderr, "Erro: %s\n", error.what());
      return 1;
   }

   return 0;
}

Thanks,
Acácio.

-----Mensagem original-----
De: Gordon Sim [mailto:gsim@redhat.com] 
Enviada em: segunda-feira, 14 de dezembro de 2009 09:46
Para: users@qpid.apache.org
Assunto: Re: Behaviour when there're elements on the queue before
instantiating the consumers

On 12/14/2009 11:37 AM, Acácio Centeno wrote:
> Hi,
>
>
>
>                  We’re using QPid 0.5 and found a peculiar behaviour.
We’re
> wondering why that’s happening.
>
>
>
>                  When the queue has elements, say 100, and we instantiate
N
> consumers, say 5, only the first one receives those elements on the queue.
> Should we send new elements, they will be distributed among all the
> consumers, but the “old ones” will be delivered only to the first consumer
> (which we called internally “the hero” as it gets pretty stressed trying
to
> come up with the backlog).
>
>
>
>                  Is this a bug, a known issue or not an issue at all but a
> required behavior? If it’s a bug, is it fixed on the 0.6 release?

Which broker & client(s) are you using?

For the c++ broker, when the first subscription is added it will take as 
many messages as it can get (subject to credit and ability to write to 
the socket) and thus (especially if the messages are relatively small) 
may get all 100 before the next subscription is ready to to compete with it.

You could try setting a finite credit window (default is infinite) to 
make the distribution fairer. Assuming you are using the c++ client, you 
do this by passing in SubscriptionSettings to the 
SubscriptionManager::subscribe() call.

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



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


Mime
View raw message