def test_pub_suber(self): """Test publisher and subscriber. """ pub_address = "tcp://" + str(get_own_ip()) + ":0" pub = Publisher(pub_address) addr = pub_address[:-1] + str(pub.port_number) sub = Subscriber([addr], '/counter') tested = False for counter in range(5): message = Message("/counter", "info", str(counter)) pub.send(str(message)) time.sleep(1) msg = sub.recv(2).next() if msg is not None: self.assertEquals(str(msg), str(message)) tested = True self.assertTrue(tested) pub.stop()
"%Y%m%d%H%M%S").isoformat(), "time_of_last_scanline": datetime.strptime(base[32:46], "%Y%m%d%H%M%S").isoformat()} import pprint pprint.pprint(metadata) yield Message('/dc/polar/gds', 'file', metadata) PUB_ADDRESS = "tcp://" + str(get_own_ip()) + ":9000" BROADCASTER = sendaddresstype('p1', PUB_ADDRESS, "HRPT 1b", 2).start() time.sleep(10) PUB = Publisher(PUB_ADDRESS) try: #for msg in SUB(timeout=1): # print "Consumer got", msg counter = 0 while True: counter += 1 for i in send_new_files(): print "publishing " + str(i) PUB.send(str(i)) time.sleep(60) except KeyboardInterrupt: print "terminating datasource..." BROADCASTER.stop() PUB.stop()
PUB = Publisher(PUB_ADDRESS) oper test dev db """ /oper/polar/direct_readout/norrköping /oper/polar/regional/kangerlusuaq /oper/geo/0deg /oper/geo/rss /oper/geo/iodc /oper/geo/iodc """ try: counter = 0 while True: counter += 1 msg = Message('/oper/nwp', 'file', {"type": "NWP", "source": "hirlam", "timestamp": str(datetime.utcnow())}) print "publishing " + str(msg) PUB.send(str(msg)) time.sleep(5) except KeyboardInterrupt: print "terminating datasource..." BROADCASTER.stop() PUB.stop()