本文整理汇总了Python中core.event_bus.EventBus.publish方法的典型用法代码示例。如果您正苦于以下问题:Python EventBus.publish方法的具体用法?Python EventBus.publish怎么用?Python EventBus.publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.event_bus.EventBus
的用法示例。
在下文中一共展示了EventBus.publish方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def handler(msg):
print "Received message"
flights = JsonArray()
for flight in msg.body:
the_flight = JsonObject()
#print str(flight)
#the_flight.putString("name", flight.getString("callsign"))
#the_flight.putString("planeType", flight.getString("equipment") )
the_flight.putString("speed", flight.get("properties").get("direction"))
the_flight.putString("alt", flight.get("properties").get("route"))
position_array = flight.get("geometry").get("coordinates")
#print position_array
#There can sometimes be two positions readings but I am not sure what they do so I am just going to take the first
#position = position_array[0]
the_flight.putNumber("lat", position_array[1])
the_flight.putNumber("lon", position_array[0])
#build the object to persist to mongo
forMongo = JsonObject()
forMongo.putString("action", "save")
forMongo.putString("collection", "buses")
forMongo.putObject("document", the_flight)
#persist it
EventBus.publish('vertx.mongopersistor', forMongo)
#add now to the array
flights.addObject(the_flight)
#Sent the array on the EventBus - this is the one the page should subscribe to
EventBus.publish('flights.updated', flights)
print("published the flights")
示例2: login_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def login_handler(msg):
user = msg.body
id = vertx.config()['user-prefix'] + str(uuid.uuid4())
users.add(user)
EventBus.register_handler(id,
handler=lambda msg: command_handler(user, msg))
EventBus.publish(vertx.config()['users-address'], user)
msg.reply({'id': id, 'users': list(users)})
示例3: command_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def command_handler(user, msg):
body = msg.body
status = 'unknown-command'
if (body['command'] == 'say'):
EventBus.publish(vertx.config()['messages-address'],
{'user': user,
'message': body['payload']})
status = 'ok'
msg.reply({'status': status})
示例4: init_test_setup
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def init_test_setup(config):
if not config.get('testmode', False):
return
def register(addr):
def _wrapper(func):
EventBus.register_handler(addr, handler=func)
return func
return _wrapper
@register('test.tweets')
def tweet_handler(msg):
print msg.body
@functools.partial(vertx.set_periodic, 1000)
def status(tid):
EventBus.publish(HBCAgent.STATUS_ADDRESS, dict(replyTo="test.status"))
@register('test.status')
def print_status(msg):
print "Status >>>", msg.body
@register('test.shutdown')
def on_shutdown(msg):
print "Shutdown >>>", msg.body
vertx.exit()
# simple shutdown hook
exit_after = config.get('testmode').get('exitAfter', 10)
if exit_after:
vertx.set_timer(exit_after * 1000,
lambda x: EventBus.publish(HBCAgent.SHUTDOWN_ADDRESS,
dict(replyTo="test.shutdown")))
示例5: test_send_multiple_matching_handlers
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def test_send_multiple_matching_handlers(self):
json = {'message' : 'hello world!'}
address = "some-address"
num_handlers = 10
count = [0] # use an array to ensure pass by ref
for i in range(0,num_handlers):
class Handler(object):
def __init__(self, count):
self.count = count
def handler_func(self, msg):
tu.azzert(msg.body['message'] == json['message'])
EventBus.unregister_handler(self.id)
self.count[0] += 1
if self.count[0] == num_handlers:
tu.test_complete()
handler = Handler(count)
handler.id = EventBus.register_handler(address, handler=handler.handler_func)
EventBus.publish(address, json)
示例6: handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def handler(msg):
print 'Received message'
flights = JsonArray()
for flight in msg.body:
the_flight = JsonObject()
the_flight.putString("name", flight.getString("callsign"))
the_flight.putString("planeType", flight.getString("equipment") )
position_array = flight.getArray("positions").toArray()
#There can sometimes be two positions readings but I am not sure what they do so I am just going to take the first
position = position_array[0]
the_flight.putNumber("lat", position.get("lat"))
the_flight.putNumber("lon", position.get("lon"))
the_flight.putNumber("speed", position.get("speedMph"))
the_flight.putNumber("alt", position.get("altitudeFt"))
flights.addObject(the_flight)
#Sent the array on the EventBus - this is the one the page should subscribe to
EventBus.publish('flights.updated', flights)
print("published the flights")
示例7: timer_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def timer_handler(timer_id):
EventBus.publish('news-feed', 'Python!')
示例8: timer_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def timer_handler(timer_id):
print "Python sending..."
EventBus.publish('news-feed', 'Power Python')
示例9: handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def handler(msg):
my_ip = urllib2.urlopen('http://ip.42.pl/raw').read()
print ("myIp:" + my_ip)
EventBus.publish('send-chat', my_ip);
示例10: shutdown_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def shutdown_handler(self, msg):
EventBus.publish(msg.body['replyTo'], self._shutdown())
示例11: status_handler
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def status_handler(self, msg):
EventBus.publish(msg.body['replyTo'], self._status())
示例12: offer
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def offer(self, item, *args):
EventBus.publish(self.channel, JsonObject(item))
示例13: status
# 需要导入模块: from core.event_bus import EventBus [as 别名]
# 或者: from core.event_bus.EventBus import publish [as 别名]
def status(tid):
EventBus.publish(HBCAgent.STATUS_ADDRESS, dict(replyTo="test.status"))