zeromq / goczmq

goczmq is a golang wrapper for CZMQ.
Mozilla Public License 2.0
592 stars 94 forks source link

Can't create a SubChanneler without subscriptions #225

Closed arodland closed 7 years ago

arodland commented 7 years ago

v4 added the ability to call Subscribe and Unsubscribe on a SubChanneler at runtime, which is great. But the case where you have no subscriptions to begin with, and add them on demand, isn't handled very well. If NewSubChanneler is called with an empty string as a subscription list it will subscribe to everything, there's no way to subscribe to nothing.

It's possible to work around this by calling .Unsubscribe("") right afterwards, but that's racy.

It's possible to work around it by passing some very improbable topic name as the initial subscription, but that's messy.

taotetek commented 7 years ago

@arodland Thank you for the report on this usability issue! Maybe we could change NewSubChanneler to:

func NewSubChanneler(endpoints string, subscribe ...string) *Channeler

Then, an empty string could keep the same functionality, and not passing a subscribe arg at all could create a SubChanneler that is not subscribed to anything.

arodland commented 7 years ago

Thank you. Yes, I think that's a good solution.

To prevent confusion, multiple values should also work, so that you could do NewSubChanneler(endpoint, "one", "two", "three") in place of NewSubChanneler(endpoint, "one,two,three"). Otherwise, someone will try it anyway :)

taotetek commented 7 years ago

@arodland haha yeah - so you'll be able to pass nothing, or one or more topics, and an empty string topic will be treated as "all" as it is now.

taotetek commented 7 years ago

@arodland ok - the change is merged on master, thanks again for the feedback.