Ejemplo n.º 1
0
def main():
    pubsub_endpoint = "localhost:9092"
    topic = "out_topic_ad_notif_test"

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hs:t:",
                                   ["server=", "topic="])
    except getopt.GetoptError:
        printhelp()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            printhelp()
            sys.exit()
        elif opt in ("-s", "--server"):
            pubsub_endpoint = arg
        elif opt in ("-t", "--topic"):
            topic = arg

    # print out configs
    print(f"Endpoint: {pubsub_endpoint}")
    print(f"Topic: {topic}")

    kafka_mgr = PubSubManagerKafka(PubSubConnectionKafka(pubsub_endpoint))
    consumer = kafka_mgr.create_consumer([topic], "testapp_sig_gen", "testapp")

    print("Starting listening for notifications ...")

    while True:
        (t, o) = consumer.poll()
        if o is not None:
            print(f"Getting message from topic t={t}:")
            print(f"{o}")
            print(f"")
Ejemplo n.º 2
0
    def signal_thread(self, notif_callback):

        kafka_mgr = PubSubManagerKafka(PubSubConnectionKafka(self.pubsub_endpoint))
        consumer = kafka_mgr.create_consumer([self.topic], "testapp_sig_gen", "testapp")

        print("Starting listening for notifications ...")

        while not self.terminating_thread:
            (t, o) = consumer.poll(1)
            if o is not None:
                print(f"Getting message from topic t={t}:")
                print(f"{o}")
                print(f"")
                notif_callback(o.notification_id)
Ejemplo n.º 3
0
    def signal_thread(self, terminating_thread):

        kafka_mgr = PubSubManagerKafka(
            PubSubConnectionKafka(self.pubsub_endpoint))
        consumer = kafka_mgr.create_consumer([self.topic], "testapp_sig_gen",
                                             "testapp")

        print("Starting listening for notifications ...")
        while not terminating_thread():
            (t, o) = consumer.poll(1)
            print(t)
            if o is not None:
                print(terminating_thread())
                if o.notification_id == 'is_not_me':
                    self.data = 'not_me'
                else:
                    self.data = 'me'
                with self.condition:
                    self.condition.notifyAll()