Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8160661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:19:13+00:00 2026-06-06T18:19:13+00:00

I need to setup multiple queues on an exchange. I would like to create

  • 0

I need to setup multiple queues on an exchange. I would like to create a single connection, then declare multiple queues (this works) then, publish messages on the multiple queues (this does not work).

I setup some test code to do this, but it gets hung up on the 2nd publish everytime. I think it does not like publishing on multiple queues without closing the connection, as this code works when I publish on a single queue (even multiple messages on a single queue).

Is there something I need to add to make this work? I would really like to not have to close the connection between publishes. Also, when I have my consumers up, they do not see anything when I send to basic_publish()’s when sending on multiple queues. I do see messages appear almost instantly when I am publishing on a single queue.

#!/usr/bin/env python
import pika


queue_names = ['1a', '2b', '3c', '4d']


# Variables to hold our connection and channel
connection = None
channel = None


# Called when our connection to RabbitMQ is closed
def on_closed(frame):
    global connection
    # connection.ioloop is blocking, this will stop and exit the app
    connection.ioloop.stop()



def on_connected(connection):
    """
    Called when we have connected to RabbitMQ
    This creates a channel on the connection
    """
    global channel #TODO: Test removing this global call

    connection.add_on_close_callback(on_closed)

    # Create a channel on our connection passing the on_channel_open callback
    connection.channel(on_channel_open)



def on_channel_open(channel_):
    """
    Called when channel opened
    Declare a queue on the channel
    """
    global channel

    # Our usable channel has been passed to us, assign it for future use
    channel = channel_


    # Declare a set of queues on this channel
    for queue_name in reversed(queue_names):
        channel.queue_declare(queue=queue_name, durable=True,
                              exclusive=False, auto_delete=False,
                              callback=on_queue_declared)
        #print "done making hash"

def on_queue_declared(frame):
    """
    Called when a queue is declared
    """
    global channel

    print "Sending 'Hello World!' on ", frame.method.queue

    # Send a message
    channel.basic_publish(exchange='',
                          routing_key=frame.method.queue,
                          body='Hello World!')


# Create our connection parameters and connect to RabbitMQ
connection = pika.SelectConnection(pika.ConnectionParameters('localhost'), \
                                   on_connected)

# Start our IO/Event loop
try:
    connection.ioloop.start()
except KeyboardInterrupt:
    print "interrupt"
    # Gracefully close the connection
    connection.close()
    # Loop until we're fully closed, will stop on its own
    #connection.ioloop.start()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:19:16+00:00Added an answer on June 6, 2026 at 6:19 pm

    My solution to this was to have a variable keep track of whether all my queues were declared or not.

    In on_queue_declared(), I would check this variable and, if all my queues were declared, then I start publishing messages. I believe attempting to publish messages before getting back all the Queue.DeclareOks was causing the issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to setup ActiveMQ with MySQL which i follow this article http://note19.com/2007/06/23/configure-activemq-with-mysql/ I
I need to display multiple annonation views in MKMapKit..I use this code.. - (void)viewDidLoad
For an event we need the following setup: Multiple computers running a kinda of
I've got a multiple project setup, using Maven and the Findbugs plugin. I need
How would I represent something like this <product> <sku>12452</sku> <attribute name=details>good stuff</attribute> <attribute name=qty>5</attribute>
I need to know how I can have multiple images, when clicked, call/setup a
I need advice if this setup is ok. I have a personal dev server
I need to setup a DNS server only to resolve the name of our
I need to setup a 2 way SSL communication channel between a .NET/WCF application
I need to setup an ASP.Net MVC view with a Date Picker that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.