[zeromq-dev] exchange id issue.

Martin Sustrik sustrik at fastmq.com
Wed Mar 18 18:03:22 CET 2009

Hi Alexandre,

> I found what may be a defect in the exchange id attribution.
> This is my use case:
> - the main thread of my program create an api_thread_t and use it to 
> create a process scope exchange.
> - a spawned thread create an api_thread_t and use it to create a thread 
> scope exchange.
> Both exchange have the same exchange_id, therefore, I can't use the 
> process scope exchange from my spawned thread (message are delivered 
> through the thread scope exchange). As exchanges are passed to 
> api_thread_id::send() by exchange id, should they not have different id?

No. The idea is that you can used object you've created only from that 
particular thread (this is needed because internally, exchanges and 
queues are represented as ultra-efficient lock-free queues that can be 
accessed only by a single thread at a moment.)

If what you need is a "shared queue", i.e. an object that can be written 
to by many applications and from which many applications can fetch data, 
you should create a simple application that does the thing. Have a look 
at chat example. The "chatroom" component is actually a shared queue.

In most cases the code boils down to something like this:

int eid = api->create_exchange ("E");
api->create_queue ("Q");

while (true) {
     message_t message;
     api->receiver (&message);
     api->send (eid, message);

At some time in the future we'll ship pre-packaged shared queue 
implementation with 0MQ, however, at the moment you have to write 
something like the code above yourself.

Hope this helps.

More information about the zeromq-dev mailing list