node.jsrabbitmqamqpnode-amqprabbit.js

how to send a message to all subscribers except for the publisher which is also a listener on same rabbitMQ queue


i have a rabbitMQ installed used by a nodeJS server. i use rabbit.js library to interact with rabbit, and so far i was happy with it.

i got multiple subscribers on the same queue in fanout mode, each node which is a subscriber, is also a publisher this is good for me and works fine, because there are many situations in which i want to notify all servers about some update that happend on one of those nodes (which is also a publisher...)

i stumbled on a case in which i need to send all of the listeners on a queue a message, except for the one who sent it (which is also a listener on that same queue).

i don't know in advance who is listening (there could be single one, there could be millions), so i can't rout it to some specific nodes by some whitelist route rule. it must be some kind of an exclusion wildcard routing rule (some blacklist) for example, send this message to everyone who listens which don't correspond to my own unique id...

can it be done using rabbit.js? can it even be done in rabbitmq somehow?

i don't know rabbit that much... so be gentle with me :)

btw, if you know how to do it using rabbit.js, even better...

EDIT::

according to Derick Bailey's request here is the reason i need this

i have a system in which there are many load balanced nodeJS servers which operate as webServices. they are totally transparent to one another. none of them knows which other nodes exists. and i would like to keep it this way because this seperation makes it easier for me to better scale by just adding and removing other "parallel" nodes.

each of these nodes has his own in memory local cache service. and i stumbled on a situation in which a single node updates some entity. and now i need to make it possible for this node to notify all of the other parallel nodes (that might have the same entity in the cache) to invalidate it.

problem is that my node which sends the message (updating node) will also receive the message, since he is also a listener. so i want him to somehow exclude himself from the receivers list of that specific message... hence the need for some routing blacklist. (he knows himself, so i could make him route to everyone except for his own id... but he does not know even if someone is indeed listening on the other end... so it defenitly cannot be a whitelist)

hope my need is clearer now.

i already thought of a solution to my problem, but it requires extra development on my side, and i would like to avoid it by using the current abilities of rabbit (in case it is possible) i could just add a unique ID to the content of the message. then the sending node can recognize that this message came from him and ignore that message. but as you can obviously understand, this could get tricky because i need to consider additional pitfalls and other edge cases it might fail...

if someone can tell me how to do it using some rabbit existing configuration, i'll be more than glad to hear how :)


Solution

  • Don't know why i'm answering this question (since i'm the one who asked it in the first place) i assume that my solution will help others.

    anyway, i never really found a solution in entire amqp architechture. so i invented my own solution :)

    what i did was to create an internal service on each node that sends those kind of "ham radio style" messages to all that care to listen but himself.

    this service adds a unique hash to each message that is sent on this exchange before it is passed to rabbitMQ. and save the hash inside a local collection.

    each node that receives a message on this exchange, first tests to see if he is the one who sent it (by validating if the message hash is available in his "sent message" queue).

    if he detects it in his collection, the local service ignores the message if he doesn't detect it, he does not ignore the message and passes it on the piece of code that should handle it

    there's a single useless message that is sent there is a bit of a code overhead per each message sent on this queue

    but buttom line, it works like a charm

    hope it helps someone

    i really believe that this "HAM radio style" exchange in which only the sender does not receive the message could be usefull

    anyone thinks i should contact the people who design amqp architechture so they will add it? :)