1

I'm new to ZeroMQ. Today I am trying the pub/sub pattern with NetMQ (the ZMQ library for .NET). I noticed some strange behavior (at least, to me!). I create a subscriber socket and subscribes to topic "12345". The publisher then publishes messages with topic "1234567890". The subscriber can receive the messages! That means, the filter does not compare the whole topic string, but only checks if the published topic "starts with" the subscribed topic. To confirm that, I changed the subscribed topic to "2345". And the subscriber did not receive the messages. If I change the publishing topic to "23456890" (while the subscribed topic is "2345"), then the messages come! I'd like to know, is that the normal behavior of the topic filter in ZeroMQ (and NetMQ)? Thank you very much!

Kenna
  • 15
  • 3

2 Answers2

0

" ...is that the normal behavior of the topic filter in ZeroMQ (and NetMQ)? "

Yes, this is documented property of ZeroMQ implementation of ultra-fast TOPIC-filtering. It works this way since ever ( v2.1.1+, v3.+, v4.+ and most probably it will remain so due to its ultimate performance and scaling envelopes ).

Also be informed, that a similar approach was taken by Martin SUSTRIK, the ZeroMQ co-father, in foundations of nanomsg and its ports and more recent breeds ( pynano, pynng et al ), so it could be called a de-facto industry best-practice, could it not?

halfer
  • 19,824
  • 17
  • 99
  • 186
user3666197
  • 1
  • 6
  • 50
  • 92
0

Establish a new message filter. Newly created Subsriber sockets will filtered out all incoming messages. Call this method to subscribe to messages beginning with the given prefix. Multiple filters may be attached to a single socket, in which case a message shall be accepted if it matches at least one filter. Subscribing without any filters shall subscribe to all incoming messages. const sub = new Subscriber()

// Listen to all messages beginning with 'foo'. sub.subscribe("foo")

// Listen to all incoming messages. sub.subscribe() Params: prefixes – The prefixes of messages to subscribe to.

subscribe(...prefixes: Array<Buffer | string>): void;
mat.twg
  • 438
  • 1
  • 5
  • 11