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")
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)})
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})
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")))
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)
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")
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)
def offer(self, item, *args): EventBus.publish(self.channel, JsonObject(item))
def shutdown_handler(self, msg): EventBus.publish(msg.body['replyTo'], self._shutdown())
def timer_handler(timer_id): print "Python sending..." EventBus.publish('news-feed', 'Power Python')
def timer_handler(timer_id): EventBus.publish('news-feed', 'Python!')
def handler(tid): EventBus.publish("data.source.raw", create_package()) print 'And every second this is printed'
def timer_handler(timer_id): EventBus.publish('news-feed', 'Some News!')
def status_handler(self, msg): EventBus.publish(msg.body['replyTo'], self._status())
def status(tid): EventBus.publish(HBCAgent.STATUS_ADDRESS, dict(replyTo="test.status"))
def handler(msg): my_ip = urllib2.urlopen('http://ip.42.pl/raw').read() print ("myIp:" + my_ip) EventBus.publish('send-chat', my_ip);
def handler(tid): EventBus.publish("data.source.raw", create_package())
def timer_handler(timer_id): EventBus.publish('examples.message', 'Message from Jython')