Open rbcollins123 opened 8 years ago
So, while not obvious to a 1st time user of Autobahn, the example does work as it should. Default behavior of publish() is to exclude delivery of the message back to the endpoint that initially published the message (unless explicitly allowed via setting exclude_me=False
) and therefor the subscription method never fires.
I would suggest modifying the README to make it run in a more "expected" manner for 1st time users, since I would think lots of users of autobahn-sync may be looking for a way to quickly connect to autobahn/crossbar infrastructure without full knowledge of the async Autobahn's behavior.
Below were my edits to the introductory example in case you want to update the README or in case it helps others during their initial investigation:
from time import sleep
from autobahn_sync import publish, call, register, subscribe, run
from autobahn.wamp.types import PublishOptions
@register('com.app.shout')
def shout(msg):
return msg.upper()
@subscribe('com.app.idea')
def on_thought(msg):
print("I've just had a new idea: %s" % msg)
run()
while True:
print(call('com.app.shout', 'Autobahn is cool !'))
publish('com.app.idea', 'Use autobahn everywhere !', options=PublishOptions(exclude_me=False))
sleep(1)
which results in the the output one would expect to STDOUT:
AUTOBAHN IS COOL !
I've just had a new idea: Use autobahn everywhere !
AUTOBAHN IS COOL !
I've just had a new idea: Use autobahn everywhere !
We were going to leverage this for a project, so I popped the example in to quickly evaluate it, but it didn't seem to run as expected out of the box?
When I ran the example in a fresh virtualenv for python 2.7 and 3.5, i see no output from the publish() calls. I flipped the print statements over to a logger and still saw no output?