Ejemplo n.º 1
0
def forward(sub_addr, pub_addr, topic='', rename_topic=None, bind=False):
    context = zmq.Context()

    in_sock = context.socket(zmq.SUB)
    out_sock = context.socket(zmq.PUB)

    if bind is True:
        map_string_or_list_of_strings(in_sock.bind, sub_addr)
        map_string_or_list_of_strings(out_sock.bind, pub_addr)
    else:
        map_string_or_list_of_strings(in_sock.connect, sub_addr)
        map_string_or_list_of_strings(out_sock.connect, pub_addr)

    in_sock.setsockopt(zmq.SUBSCRIBE, msg.createZmqFilter(topic))
    if rename_topic is None:
        zmq.device(zmq.FORWARDER, in_sock, out_sock)
    else:
        while (1):
            out_sock.send(rename_message(in_sock.recv(), topic, rename_topic))
Ejemplo n.º 2
0
 def subscribe(self, topic):
     self.in_sock.setsockopt(zmq.SUBSCRIBE, msg.createZmqFilter(topic))
Ejemplo n.º 3
0
 def test_createZmqFilterAny(self):
     self.assertEqual(b'', msg.createZmqFilter(''))
Ejemplo n.º 4
0
 def test_createZmqFilterForTopic(self):
     self.assertEqual(b'hello/world\x00',
                      msg.createZmqFilter('hello/world'))
Ejemplo n.º 5
0
 def test_createZmqFilterForNamespace(self):
     self.assertEqual(b'hello/',
                      msg.createZmqFilter('hello/'))
Ejemplo n.º 6
0
 def subscribe(self, topic):
     self.in_sock.setsockopt(zmq.SUBSCRIBE, msg.createZmqFilter(topic))