checkpoint commit
All checks were successful
Podman DDNS Image / build-and-push-ddns (push) Successful in 1m3s
All checks were successful
Podman DDNS Image / build-and-push-ddns (push) Successful in 1m3s
This commit is contained in:
46
active/device_unifi/rmq_dns_test.py
Normal file
46
active/device_unifi/rmq_dns_test.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pika
|
||||
import yaml
|
||||
|
||||
DEFAULT_CFG = """
|
||||
rabbitmq:
|
||||
host: "localhost"
|
||||
port: 5672
|
||||
virtual_host: "/"
|
||||
username: "guest"
|
||||
password: "guest"
|
||||
|
||||
# Which *exchange* (topic) you actually want to listen to.
|
||||
# The program will create a temporary queue, bind it to this exchange
|
||||
# with the routing key supplied in `routing_key`.
|
||||
subscriber:
|
||||
exchange: "nic" # ← change to “reese” or any other exchange
|
||||
routing_key: "add" # ← could be “add”, “delete”, or any pattern
|
||||
"""
|
||||
|
||||
CONFIG_PATH = Path("active/device_unifi/config.yaml")
|
||||
if not CONFIG_PATH.exists():
|
||||
CONFIG_PATH.write_text(DEFAULT_CFG)
|
||||
|
||||
with CONFIG_PATH.open() as f:
|
||||
cfg = yaml.safe_load(f)
|
||||
|
||||
|
||||
cred = pika.PlainCredentials(cfg["rabbitmq"]["username"], cfg["rabbitmq"]["password"])
|
||||
params = pika.ConnectionParameters(
|
||||
host=cfg["rabbitmq"]["host"],
|
||||
port=cfg["rabbitmq"]["port"],
|
||||
virtual_host=cfg["rabbitmq"]["virtual_host"],
|
||||
credentials=cred,
|
||||
)
|
||||
|
||||
with pika.BlockingConnection(params) as c:
|
||||
ch = c.channel()
|
||||
ch.basic_publish(
|
||||
exchange="reese",
|
||||
routing_key="add",
|
||||
body=json.dumps({"msg": "hello nic add"}),
|
||||
properties=pika.BasicProperties(delivery_mode=2), # make it persistent
|
||||
)
|
||||
Reference in New Issue
Block a user