20 lines
547 B
Python
20 lines
547 B
Python
import json
|
|
|
|
from pika.adapters.blocking_connection import BlockingChannel
|
|
|
|
from .extension import with_pika_channel
|
|
|
|
|
|
@with_pika_channel
|
|
def ensure_queue_exists(name: str, channel: BlockingChannel = None):
|
|
channel.queue_declare(queue=name)
|
|
|
|
|
|
@with_pika_channel
|
|
def queue_publish(queue_name: str, message, channel: BlockingChannel = None):
|
|
ensure_queue_exists(queue_name, channel=channel)
|
|
|
|
body = json.dumps(message)
|
|
body_bytes = body.encode('utf-8')
|
|
channel.basic_publish(exchange='', routing_key=queue_name, body=body_bytes)
|