def on_pub(sub, pub, payload): print("Received on %s" % dps.get_listen_address(dps.subscription_get_node(sub))) print( "Pub %s(%d) matches:" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))) print(" pub " + " | ".join(dps.publication_get_topics(pub))) print(" sub " + " | ".join(dps.subscription_get_topics(sub))) print(payload.tobytes())
def on_pub(sub, pub, payload): print("Pub %s(%d) matches:" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))) print(" pub " + " | ".join(dps.publication_get_topics(pub))) print(" sub " + " | ".join(dps.subscription_get_topics(sub))) print(payload.tobytes()) if dps.publication_is_ack_requested(pub): ack_msg = "This is an ACK from %s" % (dps.get_listen_address(dps.publication_get_node(pub))) print("Sending ack for pub UUID %s(%d)" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))) print(" %s" % (ack_msg)) dps.ack_publication(pub, ack_msg);
def subscriber(topic, remote_listen_addr): node = dps.create_node("/", key_store, None) dps.start_node(node, 0, None) print("Subscriber is listening on %s" % dps.get_listen_address(node)) sub = dps.create_subscription(node, [topic]) dps.subscribe(sub, on_pub) if remote_listen_addr != None: event.clear() ret = dps.link(node, str(remote_listen_addr), on_link) if ret == dps.OK: event.wait() nodes.append(node) return node
print(payload.tobytes()) if dps.publication_is_ack_requested(pub): ack_msg = "This is an ACK from %s" % (dps.get_listen_address(dps.publication_get_node(pub))) print("Sending ack for pub UUID %s(%d)" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))) print(" %s" % (ack_msg)) dps.ack_publication(pub, ack_msg); import argparse parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", action='store_true', help="Enable debug ouput if built for debug.") args = parser.parse_args() dps.cvar.debug = args.debug node = dps.create_node("/") dps.start_node(node, dps.MCAST_PUB_ENABLE_RECV + dps.MCAST_PUB_ENABLE_SEND, None) print("Subscriber is listening on %s" % (dps.get_listen_address(node))) sub = dps.create_subscription(node, ['a/b/c']); dps.subscribe(sub, on_pub) time.sleep(1) # Let publishers know we are here pub = dps.create_publication(node) dps.init_publication(pub, ['new_subscriber'], False) dps.publish(pub, "Hi") if not sys.flags.interactive: while True: time.sleep(1)
dps.destroy_key_store(key_store) if args.port != None: mcast = dps.MCAST_PUB_DISABLED node = dps.create_node("/", key_store, node_id) listen_addr = None if args.listen != None: listen_addr = dps.create_address() try: dps.set_address(listen_addr, "[::]:%d" % (int(args.listen))) except ValueError: dps.set_address(listen_addr, args.listen) dps.start_node(node, mcast, listen_addr) print("Publisher is listening on %s" % (dps.get_listen_address(node))) if args.port != None: try: addr_text = "[::1]:%d" % (int(args.port)) except ValueError: addr_text = args.port event.clear() ret = dps.link(node, addr_text, on_link) if ret == dps.OK: event.wait() else: print("link %s returned %s" % (addr_text, dps.err_txt(ret))) pub = dps.create_publication(node) dps.init_publication(pub, ['a/b/c'], False, None, on_ack)
def on_link(node, addr, status): if status == dps.OK: print("Linked %s to %s" % (dps.get_listen_address(node), addr)) event.set()
event.wait() nodes.append(node) return node import argparse parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", action='store_true', help="Enable debug ouput if built for debug.") args = parser.parse_args() dps.cvar.debug = args.debug sub1 = subscriber('B/B', None) sub2 = subscriber('A/A', dps.get_listen_address(sub1)) sub3 = subscriber('C/C', dps.get_listen_address(sub1)) sub4 = subscriber('a/b/c', dps.get_listen_address(sub2)) sub5 = subscriber('d/e/f', dps.get_listen_address(sub2)) sub6 = subscriber('g/h/i', dps.get_listen_address(sub2)) sub7 = subscriber('1/2/3', dps.get_listen_address(sub3)) sub8 = subscriber('4/5/6', dps.get_listen_address(sub3)) sub9 = subscriber('7/8/9', dps.get_listen_address(sub3)) time.sleep(15) sub10 = subscriber('+/#', dps.get_listen_address(sub7)) time.sleep(15) sub11 = subscriber('+/#', dps.get_listen_address(sub1))