예제 #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))
예제 #2
0
 def subscribe(self, topic):
     self.in_sock.setsockopt(zmq.SUBSCRIBE, msg.createZmqFilter(topic))
예제 #3
0
 def test_createZmqFilterAny(self):
     self.assertEqual(b'', msg.createZmqFilter(''))
예제 #4
0
 def test_createZmqFilterForTopic(self):
     self.assertEqual(b'hello/world\x00',
                      msg.createZmqFilter('hello/world'))
예제 #5
0
 def test_createZmqFilterForNamespace(self):
     self.assertEqual(b'hello/',
                      msg.createZmqFilter('hello/'))
예제 #6
0
파일: bus.py 프로젝트: cvra/zmqmsgbus
 def subscribe(self, topic):
     self.in_sock.setsockopt(zmq.SUBSCRIBE, msg.createZmqFilter(topic))