Anirban B
Anirban B

Reputation: 517

RabbitMQ direct exchange queue not created

I am trying to send message through direct exchange. I have not declared the queue as mentioned in the official page tutorial. Below is my code:

import sys
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))  # Connect to AMQP

def setup():
        channel = connection.channel()
        channel.exchange_declare(exchange='direct_logs', type='direct')
        return channel

def log_emitter(message, severity):
        channel = setup()
        channel.basic_publish(exchange='direct_logs',
                      routing_key=severity,
                      body=message)

def logger():
        severity = sys.argv[1] if len(sys.argv) > 2 else 'info'
        print severity
        exit = 'N'
        message = ' '.join(sys.argv[2:]) or "Hello World!"
        log_emitter(message, severity)
        print(" [x] Sent %r:%r" % (severity, message))
    connection.close()

logger()

I am executing with

python direct_log_publisher.py info "Info testing"

It is creating the direct_logs exchange but I cannot see any "info" queue is created in the admin console. As per my understanding no queue binding is required at publisher side. Thanks in advance.

Upvotes: 0

Views: 863

Answers (1)

user1527491
user1527491

Reputation: 965

Why would you want the queue to be created automatically? Since you don't bind a queue anywhere, the message is dropped basically (because it has nowhere to go). Either your consumer or your producer have to declare and bind the queue to the exchange (depending on what makes sense to you).

Upvotes: 0

Related Questions