23 lines
678 B
Python
23 lines
678 B
Python
from channels.layers import get_channel_layer
|
|
|
|
|
|
class NotificationDispatcher:
|
|
channel_layer = None
|
|
|
|
def __init__(self):
|
|
self.channel_layer = get_channel_layer()
|
|
|
|
async def dispatch(self, message):
|
|
print("Dispatching message:", message)
|
|
|
|
async def run_forever(self):
|
|
|
|
# Infinite loop to continuously listen for messages
|
|
while True:
|
|
# Blocking receive to get the message from the channel layer
|
|
message = await self.channel_layer.receive()
|
|
|
|
if message:
|
|
# Process the received message
|
|
print("Received message:", message)
|
|
await self.dispatch(message)
|