Pub/sub "topics", routing key and wildcards

1,012 views
Skip to first unread message

workin...@gmail.com

unread,
Jan 14, 2014, 3:45:31 PM1/14/14
to pypu...@googlegroups.com
Hello,

I've ever "play" with AMQP (RabbitMQ and pika).
but I'm totally new to pypubsub so please excuse my ignorance.

I wonder if pypubsub supports wildcards like

I also wonder if the same concept of routing key (a list of words, delimited by dots)
also exists with pypubsub

Thanks
(and sorry if my question is stupid)

oliver

unread,
Jan 14, 2014, 3:56:37 PM1/14/14
to PyPubSub
Hi Working4coins, regarding wildcards, pypubsub supports equivalent of suffix wildcards but not prefix. I.e. a topic a.b.c will be sent to all listeners of a.b.c, a.b and a, so a listener of 'a' is equal to a listener of 'a.*'. There isn't currently a way to specify *.*.c in case you also have d.e.c and f.g.c. Also, a.*.c either, because although it is suffix to a, it is prefix to c. 

So yes there is a concept of routing in pypubsub: hierarchical. This is different from network routing, which is more along the lines of what RabbitMQ provides. Loosely put, hiearchical routing is subset of network routing. 

If you have other questions, please don't hesitate. 
Oliver

Oliver
Contributor to Open Source: PyPubSub, Lua-iCxx, iof
Contributor to StackOverflow



--
You received this message because you are subscribed to the Google Groups "pypubsub" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pypubsub+u...@googlegroups.com.
To post to this group, send email to pypu...@googlegroups.com.
Visit this group at http://groups.google.com/group/pypubsub.
For more options, visit https://groups.google.com/groups/opt_out.

workin...@gmail.com

unread,
Jan 17, 2014, 2:38:27 PM1/17/14
to pypu...@googlegroups.com
Thanks for your answer.

I wonder if pypubsub provide function to manage hierarchical routing keys like
building a routing key string from tuple or list or returning a tuple from a routing key

I'm aware of '.'.join(my_tuple) and str_key.split('.') but I'm looking for pypubsub functions

oliver

unread,
Jan 17, 2014, 2:58:10 PM1/17/14
to PyPubSub
Yes there is, just can't remember if it's in public API, I'll look it up later, or if you want to search it's something like tupleize for parse string -> tuple and stringize for reverse. 

Oliver
Contributor to Open Source: PyPubSub, Lua-iCxx, iof
Contributor to StackOverflow



workin...@gmail.com

unread,
Jan 17, 2014, 3:13:07 PM1/17/14
to pypu...@googlegroups.com
Ok I found it

It will be great if there is also a function to add prefix (at start) or suffix (at end)

something like join in os.path

oliver

unread,
Jan 17, 2014, 3:52:57 PM1/17/14
to PyPubSub
Good idea. Can you post some example code showing how you would see yourself using this? 

Note that 3.1.2 is rather old, 3.2 has been out for a few months and 3.3 is imminent (the release candidate has been available for a couple weeks, as per https://groups.google.com/d/msg/pypubsub/B19kc2BQCUc/AbtplonQLk0J). 

Oliver
Contributor to Open Source: PyPubSub, Lua-iCxx, iof
Contributor to StackOverflow



workin...@gmail.com

unread,
Jan 18, 2014, 12:16:03 AM1/18/14
to pypu...@googlegroups.com
I will use it like this

topic_prefix = 'prefix1.prefix2'
topic_topic = 'foo.bar'
topic_suffix = 'suffix1.suffix2'

pub.join(topic_prefix, topic_topic, topic_suffix)
will return 'prefix1.prefix2.foo.bar.suffix1.suffix2'

but it should be able to take care of empty string or None
topic_prefix = 'prefix1.prefix2'
topic_topic = 'foo.'
topic_suffix = 'suffix1.suffix2'
pub.join(topic_prefix, topic_topic, topic_suffix)
will return 'prefix1.prefix2.foo.suffix1.suffix2'
and not  'prefix1.prefix2.foo..suffix1.suffix2'

==

topic_prefix = 'prefix1.prefix2'
topic_topic = ''
topic_suffix = 'suffix1.suffix2'
pub.join(topic_prefix, topic_topic, topic_suffix)
will return 'prefix1.prefix2.suffix1.suffix2'

==

topic_prefix = 'prefix1.prefix2'
topic_topic = None
topic_suffix = 'suffix1.suffix2'
pub.join(topic_prefix, topic_topic, topic_suffix)
will return 'prefix1.prefix2.suffix1.suffix2'

WFC

workin...@gmail.com

unread,
Jan 18, 2014, 12:39:50 AM1/18/14
to pypu...@googlegroups.com
We should also have a function to "normalize" topics (like os.normpath)

normtopic('prefix1.foo..bar.suffix1')
should return 'prefix1.foo.bar.suffix1'

normtopic('prefix1.foo.bar.suffix1.')
should return 'prefix1.foo.bar.suffix1'

normtopic('.prefix1.foo.bar.suffix1.')
should return 'prefix1.foo.bar.suffix1'

topics should be normalized before being joined


About version of pypubsub
I found this version to read code using Google an pydoc
but I think you should put somewhere in pypubsub website
a link to a source control explorer.

but no HTTP link to read the code

After several minutes I found this link
I think you should put it in 

I also notice that you use '.' in your code
maybe you should define a variable
topic_sep = '.'
in pub.py
and use pub.topic_sep

Oliver

unread,
Jan 18, 2014, 4:35:50 PM1/18/14
to pypu...@googlegroups.com, pypubsub_dev
Proposal accepted. Now if you want to go ahead and implement pub.joinTopicNames() (that's what I will name it), you will get it sooner than if you wait for me to do it. 8-D  If you create a unit test, even better (doesn't have to use nose, I can adjust it). Then post a patch relative to latest SVN. to the pypubsub_dev forum (not this forum). Otherwise I will create a ticket for it. Right now I'm busy on updating lua-icxx for integration with SWIG. 
Oliver

Oliver

unread,
Jan 18, 2014, 4:44:45 PM1/18/14
to pypu...@googlegroups.com, pypubsub_dev
On Saturday, 18 January 2014 00:39:50 UTC-5, workin...@gmail.com wrote:
We should also have a function to "normalize" topics (like os.normpath)

normtopic('prefix1.foo..bar.suffix1')
should return 'prefix1.foo.bar.suffix1'

normtopic('prefix1.foo.bar.suffix1.')
should return 'prefix1.foo.bar.suffix1'

normtopic('.prefix1.foo.bar.suffix1.')
should return 'prefix1.foo.bar.suffix1'

topics should be normalized before being joined


Proposal accepted. As in previous post: if you want to go ahead and implement pub.normTopicNames() (that's what I will name it), you will get it sooner than if you wait for me to do it. If you create a unit test, even better (doesn't have to use nose, I can adjust it). Then post a patch relative to latest SVN. to the pypubsub_dev forum (not this forum).  

About version of pypubsub
I found this version to read code using Google an pydoc

Can you clarify the above
 
but I think you should put somewhere in pypubsub website
a link to a source control explorer.

but no HTTP link to read the code


I just noticed that the installation page needs updating. I'll add the http link. 
 
I also notice that you use '.' in your code
maybe you should define a variable
topic_sep = '.'
in pub.py
and use pub.topic_sep

I think that should be doable, but I'd have to take a closer look at the code to determine how much work involved, and there may be some tricky aspects.

 
Reply all
Reply to author
Forward
0 new messages