Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print 'got message: ', msg
yield sleep(3.0 + random.random())
class ZmqTestServer(Process):
@inlineCallbacks
def start(self):
while True:
req = yield self.get()
print 'got request: ', req
yield sleep(5.0)
self.put(req)
f = ZmqFactory()
client1 = ZmqTestClient()
client2 = ZmqTestClient()
client3 = ZmqTestClient()
server = ZmqTestServer()
application = Application(
Pipeline(
client1,
ZmqReq(f, 'ipc://foobar', 'client1'),
client1,
),
Pipeline(
client2,
while True:
if not self._routing_info:
yield sleep(.1)
continue
agent_id, transport_id = random.choice(self._routing_info.items())
print "SERVER: send job to agent %s @ ZMQ identity %s" % (agent_id, repr(transport_id))
self.put((transport_id, 'job'), outbox='jobs')
yield sleep(1.0)
def stop(self):
print "SERVER: going down"
for _, transport_id in self._routing_info.items():
self.put((transport_id, 'server-going-down'), outbox='ctrl')
f = ZmqFactory()
SERVER_ADDR = 'ipc://server'
server = TestServer()
server_transport = ZmqRouter(f, SERVER_ADDR)
server.connect(['ctrl', 'jobs'], server_transport)
server_transport.connect('ctrl', server)
application = Application(
[server]
)
def __init__(self, path_prefix=None):
"""
Initialize the txzmq component.
"""
self._factory = txzmq.ZmqFactory()
self._factory.registerForShutdown()
if path_prefix is None:
path_prefix = get_path_prefix(flags.STANDALONE)
self._config_prefix = os.path.join(path_prefix, "leap", "events")
self._connections = []
def main(config):
zmq_requests_factory = ZmqFactory()
zmq_requests_endpoint = ZmqEndpoint(ZmqEndpointType.bind, config['endpoint.command'])
zmq_requests = ZmqRequests(zmq_requests_factory, zmq_requests_endpoint)
zmq_broadcast_factory = ZmqFactory()
zmq_broadcast_endpoint = ZmqEndpoint(ZmqEndpointType.bind, config['endpoint.broadcast'])
zmq_broadcast = ZmqPubConnection(zmq_broadcast_factory, zmq_broadcast_endpoint)
api_endpoint = TCP4ClientEndpoint(reactor, config['ibtws.host'], config['ibtws.port'])
api_endpoint.connect(IBTWSProtocolFactory(zmq_requests, zmq_broadcast))
reactor.run()
def startService(self):
factory = ZmqFactory()
bind_point = 'tcp://0.0.0.0:8050'
log.msg("Broadcaster binding on: %s" % bind_point)
endpoint = ZmqEndpoint('bind', bind_point)
self.conn = ZmqPushConnection(factory, endpoint)
def __init__(self, reactor, screen_ui, audio_player, first_block_hash):
f = ZmqFactory()
f.reactor = reactor
e = ZmqEndpoint("connect", "tcp://127.0.0.1:28332")
s = ZmqSubConnection(f, e)
s.subscribe("hashblock".encode("utf-8"))
s.messageReceived = self.listener
self.screen_ui = screen_ui
self.new_block_queue = []
self.queue_running = False
self.audio_player = audio_player
new_block = NewBlock(self, first_block_hash, self.screen_ui,
audio_player)
self.new_block_queue.append(new_block)
self._try_next()
def _before_start(self):
if not ZmqProxyBase._FACTORY:
ZmqProxyBase._FACTORY = ZmqFactory()
self._conn = self.CONNECTION_CLASS(self._FACTORY, identity=self._identity)
self._conn.gotMessage = self._zmq_msg_received
self.add_endpoints(self._pending_endpoints)
while True:
if not self._routing_info:
yield sleep(.1)
continue
agent_id, transport_id = random.choice(self._routing_info.items())
print "SERVER: send job to agent %s @ ZMQ identity %s" % (agent_id, repr(transport_id))
self.put((transport_id, 'job'), outbox='jobs')
yield sleep(1.0)
def stop(self):
print "SERVER: going down"
for _, transport_id in self._routing_info.items():
self.put((transport_id, 'server-going-down'), outbox='ctrl')
f = ZmqFactory()
SERVER_ADDR = 'ipc://server'
server = TestServer()
server_transport = ZmqRouter(f, SERVER_ADDR)
server.connect(['ctrl', 'jobs'], server_transport)
server_transport.connect('ctrl', server)
application = Application(
[server]
)
def __init__(self, id):
super(TestConsumer, self).__init__()
self.id = id
@inlineCallbacks
def start(self):
yield sleep(.1)
while True:
print 'CONSUMER %s sending' % self.id
self.put(message='msg-from-%s' % self.id)
msg = yield self.get()
print 'CONSUMER %s received %s' % (self.id, msg)
f = ZmqFactory()
BROKER_BE_ADDR = 'ipc://broker-be'
BROKER_FE_ADDR = 'ipc://broker-fe'
broker = TestBroker()
make_cycle(ZmqRouter(f, ZmqEndpoint('bind', BROKER_FE_ADDR)),
('frontend', broker, 'frontend'))
make_cycle(ZmqReq(f, ZmqEndpoint('bind', BROKER_BE_ADDR)),
('backend', broker, 'backend'))
consumers = [TestConsumer(i + 1) for i in range(3)]