Esempio n. 1
0
def test_push_pull():
    received = {'pull1': False, 'pull2': False}
    with pynng.Push0(listen=addr) as push, \
            pynng.Pull0(dial=addr, recv_timeout=1000) as pull1, \
            pynng.Pull0(dial=addr, recv_timeout=1000) as pull2:

        def recv1():
            pull1.recv()
            received['pull1'] = True

        def recv2():
            pull2.recv()
            received['pull2'] = True

        # push/pull does round robin style distribution
        t1 = threading.Thread(target=recv1, daemon=True)
        t2 = threading.Thread(target=recv2, daemon=True)

        t1.start()
        t2.start()
        time.sleep(0.01)
        push.send(b'somewhere someone should see this')
        push.send(b'somewhereeeee')
        t1.join()
        t2.join()
        assert received['pull1']
        assert received['pull2']
Esempio n. 2
0
 def __init__(self, local_endpoint):
     self.local_endpoint = local_endpoint
     self.serializer = PickleSerializer()  # TODO set dynamically.
     self.push = pynng.Push0()
     self.push.tcp_keepalive = True
     #self.push.add_post_pipe_connect_cb(self.__on_connect)
     #self.push.add_post_pipe_remove_cb(self.__on_disconnect)
     self.push.dial('tcp://0.0.0.0:41000',
                    block=True)  # TODO - Set dynamically or via config
 async def connect(self):
     if self.push_sock:
         return
     self.push_sock = pynng.Push0(send_timeout=SEND_TIMEOUT)
     self.push_sock.dial(self.address, block=True)
Esempio n. 4
0
async def node1(message):
    with pynng.Push0() as sock:
        sock.dial(address)
        print(f'NODE1: SENDING "{message}"')
        await sock.asend(message.encode())
        await curio.sleep(1)  # wait for messages to flush before shutting down