from BridgePython.bridge import Bridge bridge = Bridge(api_key='f99ede2465de4114') def message_cb(msg): print msg forjs = """ handler.run = function(message_cb, start, end) { var temp = start + end; console.log(temp); message_cb(temp); } """ channel = bridge.get_channel('function-channel') channel.message(forjs) cluster = bridge.get_service('cluster') cluster.run(message_cb, 1, 3) cluster.run(message_cb, 5, 3) bridge.connect()
# Any Python object can be published. A published service # can be retrieved by any Bridge client with the same API key pair. # # Only Bridge clients using the prviate API key may publish services. # class TestService(object): def ping(self, cb): print 'Received ping request!' cb('Pong') bridge.publish_service('testService', TestService()) # # Retrieving a Bridge service # # This can be done from any Bridge client connected to the same # Bridge server, regardless of language. # If multiple clients publish a Bridge service, getService will # retrieve from the publisher with the least load. # def message_cb(msg): print msg testService = bridge.get_service('testService') print 'Sending ping request' testService.ping(message_cb) bridge.connect()