Arno Duvenhage
Arno Duvenhage

Reputation: 1960

ZeroMQ pub-sub categories: are wild cards possible for multiple subscriptions?

I have been reading through the ZeroMQ documentation and I was wondering if there is a way to subscribe using wild cards? I need a system where you can publish on something like A.B.C and then subscribe on A.*.C or A.B.* ( i.e. a subscription on A.*.C will match publications on A.B.C, A.X.C, A.Y.C, etc ).

Upvotes: 0

Views: 2797

Answers (3)

Grwww
Grwww

Reputation: 91

You can subscribe to "" in an in process zmq socket and then implement more advanced filter there as a proxied thread of execution that advertises the actual XPUB socket that receives requests to perform filtering.

Upvotes: 0

user3666197
user3666197

Reputation: 1

Directly? No.
Indirectly? Oh, sure, Sir!

ZeroMQ syntax for .setsockopt( zmq.SUBSCRIBE, ... ) method, per-se, does not permit to setup other but prefix-matched topic-filter subscriptions. Technology used inside the filtering does not permit a more complex string/parsing, due to performance reasons mentioned many times by both Martin SUSTRIK and Pieter HINTJENS.

A funny thing comes as side-effect from this - one cannot avoid expanded strings, that go "beyond" the topic-filter length, from positively matching and thus from being delivered.

This does not mean, we shall give up. ZeroMQ is known to operate on indeed many thousands items, so let's harness this side of the magic.

How to setup a filter like "A.*.C"?

One approach could be to use a rather naive ( mild ) force and "mechanically" setup all the possible "expansions" of the formal filter "A.*.C" - i.e.:

for aWildcardToEXPAND_item in ( "A", "B", "C", "D", ... ): # all legal expansions
    aSUB.setsockopt( zmq.SUBSCRIBE, "A.{0:%s}.C".format( aWildcardToEXPAND_item ) )
pass; # just-SEQ life is great & so forgiving :o)

Many way smarter, decorated, context-of-use specialised iterators may help in extending this into easy setup/discard expansion/subscription iterators, that will match all your needs, so do not hesitate to go forwards, it is doable.

Upvotes: 1

Schildmeijer
Schildmeijer

Reputation: 20946

ZeroMQ PUB/SUB does a prefix matching. So A.B.* is fine ( will match A.B.C in your example ).
"Inplace matching" is not supported, for obvious reasons ( subscriptions are stored in a trie data structure ) [http://www.250bpm.com/blog:19]

Upvotes: 0

Related Questions