Skip to content
Snippets Groups Projects

WIP: Feat use queuename attribute for routing key

2 files
+ 23
21
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -3,10 +3,10 @@ import sys
import json
from rc_rmq import RCRMQ
task = 'user_reg_event_log'
task = "user_reg_event_log"
# Instantiate rabbitmq object
rc_rmq = RCRMQ({'exchange': 'RegUsr', 'exchange_type': 'topic'})
rc_rmq = RCRMQ({"exchange": "RegUsr", "exchange_type": "topic"})
# Define your callback function
def log_user_reg_events(ch, method, properties, body):
@@ -18,7 +18,9 @@ def log_user_reg_events(ch, method, properties, body):
routing_key = method.routing_key
action = routing_key.split(".")[0]
user = routing_key.split(".")[1]
print(f'Got a {action} message for {user} with routing key: {routing_key}')
print(
f"Got a {action} message for {user} with routing key: {routing_key}"
)
print(msg)
# Acknowledge message
@@ -26,8 +28,10 @@ def log_user_reg_events(ch, method, properties, body):
print("Start listening to queue: {}".format(task))
rc_rmq.start_consume({
'queue': task, # Define your Queue name
'routing_key': "#", # Define your routing key
'cb': log_user_reg_events # Pass in callback function you just define
})
rc_rmq.start_consume(
{
"queue": task, # Define your Queue name
"routing_key": "#", # Define your routing key
"cb": log_user_reg_events, # Pass in callback function you just define
}
)
Loading