publish a message from cli to webclient

93 views
Skip to first unread message

Icham Achtir

unread,
Nov 7, 2014, 10:18:44 AM11/7/14
to autob...@googlegroups.com

hi,

i need to send message from a command line to the web user using wamp.
i can send a static message but i need to change the message based to the notify.py script argument
also i don't know if my code is the correct way and the easiest way to do this???
Could you help?

here is my code

from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
   
@inlineCallbacks
   
def onJoin(self, details):
     
def onevent(msg):
         
print("Got event: {}".format(msg))

     
yield self.subscribe(onevent, 'com.myapp.notify')
     
self.publish('com.Myapp.notify',  "message")
     
self.leave()
   
def onDisconnect(self):
     
print("disconnected")
      reactor
.stop()
if __name__ == '__main__':
   
from autobahn.twisted.wamp import ApplicationRunner
   runner
= ApplicationRunner("ws://127.0.0.1:8888/ws", "realm1", standalone=False, debug=False, debug_wamp=False, debug_app=False)
   runner
.run(Component)




 

Tobias Oberstein

unread,
Nov 7, 2014, 10:59:28 AM11/7/14
to autob...@googlegroups.com
Icham,

arguable, the simplest way of sending WAMP events from the CLI isn't
using Autobahn or anything at all, but simply "curl" (or any other
thingy that can issue a HTTP/POST) plus the HTTP-pusher service of
Crossbar.io:

curl -H "Content-Type: application/json" \
-d '{"topic": "com.myapp.topic1", "args": ["Hello, world"]}' \
http://127.0.0.1:8080/push

http://crossbar.io/docs/HTTP-Pusher-Service/

===

If you want to follow the route you've been starting with your code
below, pass the message via the "extra" attribute to ApplicationRunner.
You can access this within your ApplicationSession class as
self.config.extra.

Cheers,
/Tobias


Am 07.11.2014 16:18, schrieb Icham Achtir:
>
> hi,
>
> i need to send message from a command line to the web user using wamp.
> i can send a static message but i need to change the message based to
> the notify.py script argument
> also i don't know if my code is the correct way and the easiest way to
> do this???
> Could you help?
>
> here is my code
>
> |
> fromtwisted.internet importreactor
> fromtwisted.internet.defer importinlineCallbacks
> fromautobahn.twisted.wamp importApplicationSession
> classComponent(ApplicationSession):
> @inlineCallbacks
> defonJoin(self,details):
> defonevent(msg):
> print("Got event: {}".format(msg))
>
> yieldself.subscribe(onevent,'com.myapp.notify')
> self.publish('com.Myapp.notify',"message")
> self.leave()
> defonDisconnect(self):
> print("disconnected")
> reactor.stop()
> if__name__ =='__main__':
> fromautobahn.twisted.wamp importApplicationRunner
> runner
> =ApplicationRunner("ws://127.0.0.1:8888/ws","realm1",standalone=False,debug=False,debug_wamp=False,debug_app=False)
> runner.run(Component)
> |
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autobahnws+...@googlegroups.com
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/e77f2151-874c-419b-8b53-9aec82548cae%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/e77f2151-874c-419b-8b53-9aec82548cae%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Icham Achtir

unread,
Nov 7, 2014, 11:05:00 AM11/7/14
to autob...@googlegroups.com
thanks Tobias


Both way is very interesting,
the first one for my friend using ruby.

The second one for myself

I will check and give a feed back


To post to this group, send email to autob...@googlegroups.com

--
You received this message because you are subscribed to a topic in the Google Groups "Autobahn" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/OcWGnazR5n0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to autobahnws+unsubscribe@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/545CEC4A.1000505%40gmail.com.

Icham Achtir

unread,
Dec 1, 2014, 4:54:08 AM12/1/14
to autob...@googlegroups.com
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession
class Component(ApplicationSession):
   
@inlineCallbacks
   
def onJoin(self, details):
     
def onevent(msg):
         
print("Got event: {}".format(msg))

     
yield self.subscribe(onevent, 'com.myapp.notify')

     
self.publish('com.Myapp.notify',  self.config.extra)

     
self.leave()
   
def onDisconnect(self):
     
print("disconnected")
      reactor
.stop()
if __name__ == '__main__':
   
from autobahn.twisted.wamp import ApplicationRunner

   msg="hello from outside"
   runner
= ApplicationRunner("ws://127.0.0.1:8888/ws", "realm1",extra=msg, standalone=False, debug=False, debug_wamp=False, debug_app=False)
   runner
.run(Component)
Reply all
Reply to author
Forward
0 new messages