Commit c7a7d59b authored by Jonathan Schaeffer's avatar Jonathan Schaeffer
Browse files

Using a protin.reactor.Container class

parent bdc9bf74
......@@ -10,8 +10,9 @@ import subprocess
import sys
import traceback
from proton.utils import BlockingConnection
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container
from resif_pyinventory import resif_pyinventory
SCRIPT_VERSION = 2021.190
......@@ -45,6 +46,23 @@ SEEDTREE_PATH = os.getenv("SEEDTREE_PATH")
SEEDTREE_PATH = os.getenv("SEEDTREE_PATH")
class Recv(MessagingHandler):
def __init__(self, url):
super(Recv, self).__init__()
self.url = url
def on_start(self, event):
event.container.create_receiver(self.url)
def on_message(self, event):
if event.message.id and event.message.id < self.received:
# ignore duplicate message
return
logging.info("Receiving %s",event.message.body)
# connect to AMQP server
connection = None
session = None
......@@ -193,7 +211,12 @@ if __name__ == "__main__":
from wfcatalog.collector.WFCatalogCollector import WFCatalogCollector
queue = QUEUE_WFCATALOG_UPDATE
# connect to AMQP broker
try:
Container(Recv(f"{AMQP_SERVER}/{QUEUE_VALIDATED_DATA_INTEGRATED_FILES}")).run()
except KeyboardInterrupt: pass
# connect to AMQP broker
logger.info("Trying to connect to %s", AMQP_SERVER)
connection = BlockingConnection(AMQP_SERVER)
receiver = connection.create_receiver(queue)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment