publish a message from cli to webclient

#1

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)

``

···
0 Likes

#2

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.

0 Likes

#3

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

···

2014-11-07 16:59 GMT+01:00 Tobias Oberstein tobias.o...@gmail.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+unsubscribe@googlegroups.com

mailto:autobahnws+unsub...@googlegroups.com.

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

mailto:autobahnws@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.

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.

For more options, visit https://groups.google.com/d/optout.

0 Likes

#4

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)

``

0 Likes