send a message to

Asked

Viewed 11 times

1

The Rabbit connection was made correctly, it is working. If I create a queue without vhost, I can send messages normally. The problem is when you are inside one. No error, just don’t send anything to Queue.

Follows my code:

import pika
import os
import time

class RabbitService:

    def __init__(self):
        config = {
            "RABBIT_HOST": os.environ.get("RABBIT_HOST"),
            "RABBIT_PORT": os.environ.get("RABBIT_PORT"),
            "RABBIT_USER": os.environ.get("RABBIT_USER"),
            "RABBIT_PASSWORD": os.environ.get("RABBIT_PASSWORD")
        }


    connection = self.createConnection(config)
    channel = connectionCentral.channel()
    print("Connected to central.")

    channel.queue_declare(queue='hello1')
    channel.basic_publish(exchange='', routing_key='hello', body='Hello World!') # Esse funciona

    channel.basic_publish(exchange='', routing_key='hello2', body='Hello World!') # esse não funciona (a fila já esta criada dentro de um vhost)


    def createConnection(self, config):
        credentials = pika.PlainCredentials(config["RABBIT_USER"], config["RABBIT_PASSWORD"])
        parameters = pika.ConnectionParameters(config["RABBIT_HOST"], config["RABBIT_PORT"], '/',
                                               credentials)
        return pika.BlockingConnection(parameters)
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.