Skip to content
Snippets Groups Projects
Commit 5efbe741 authored by istmxrein's avatar istmxrein
Browse files

rework MetaListener

parent 3d0e56ee
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ import time
import traceback
from enum import Enum
from ipaddress import IPv4Address
from typing import List, Optional, Callable
from typing import List, Optional, Callable, Dict
import pika
import pika.exceptions
......@@ -80,13 +80,12 @@ class Event(BaseModel):
payload: Cube
class EventListener(threading.Thread):
def __init__(self, exchange: str, queue: str, callback: Callable):
super(EventListener, self).__init__()
self.exchange: str = exchange
class MetaListener(threading.Thread):
def __init__(self, callback: Callable, queue: str = STREAM_NAME, offset = "last"):
super(MetaListener, self).__init__()
self.queue: str = queue
self.callback: Callable = callback
self.arguments = {"x-stream-offset": offset}
self.channel = None
self.connection = None
......@@ -105,10 +104,8 @@ class EventListener(threading.Thread):
try:
self.connection = utils.get_blocking_connection()
self.channel = self.connection.channel()
self.channel.exchange_declare(exchange=self.exchange, exchange_type='fanout')
self.channel.queue_declare(queue=self.queue, durable=True, exclusive=False, auto_delete=False)
self.channel.queue_bind(exchange=self.exchange, queue=self.queue)
self.channel.basic_consume(queue=self.queue, on_message_callback=self.default_callback, auto_ack=False)
self.channel.queue_declare(queue=self.queue, durable=True, exclusive=False, auto_delete=False, arguments={"x-queue-type": "stream"})
self.channel.basic_consume(queue=self.queue, on_message_callback=self.default_callback, auto_ack=False, arguments=self.arguments)
try:
self.channel.start_consuming()
except SystemExit:
......
......@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name='pilab',
version='2.1.1',
version='3.0.0',
description='Shared-Libs for the pi-lab microservices',
url='https://code.fbi.h-da.de/api/v4/projects/27896/packages/pypi/pilab',
author='Max Reinheimer',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment