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

  • Home
  • SEARCH
  • 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 3233934
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:20:02+00:00 2026-05-17T17:20:02+00:00

I’m using RabbitMQ and trying to refactor my current native java implementation to using

  • 0

I’m using RabbitMQ and trying to refactor my current native java implementation to using the Spring AMQP abstraction.

Declaration of exchanges, queues and their binding using the Spring library is via the AMQPAdmin interface, but I’m not sure when this sort of configuration should happen.

I have a web application that uses Rabbit to produce messages. And another app that consumes these messages. Shocker 🙂

But when show the declaration of the exchanges/queues take place?

Do I deploy the AMQPAdmin with the web applications and do exchange/queue administration within constructors of producers and consumers?

Declaration of these things are a one off, the broke doesn’t need to know about them again, so any code would be a NOOP on subsequent executions.

Do I create a separate application for administration of the broker?

What is the current thinking or best practices here?

  • 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-05-17T17:20:02+00:00Added an answer on May 17, 2026 at 5:20 pm

    It would appear that very few people are using Spring’s AMQP M1 release, so I will answer my own question with what I’ve done.

    In the producer’s constructor I declare the exchange. Then set the exchange on the RabbitTemplate. I also set the routing key on the RabbitTemplate as the queue name, but that isn’t required, but it was the route I would be using.

    @Service("userService")
    public class UserService {
        private final RabbitTemplate rabbitTemplate;
    
        @Autowired
        public UserService(final RabbitAdmin rabbitAdmin,
                           final Exchange exchange,
                           final Queue queue,
                           @Qualifier("appRabbitTemplate") final RabbitTemplate rabbitTemplate) {
    
            this.rabbitTemplate = rabbitTemplate;
    
            rabbitAdmin.declareExchange(exchange);
            rabbitTemplate.setExchange(exchange.getName());
            rabbitTemplate.setRoutingKey(queue.getName());  
        }
    
    
        public void createAccount(final UserAccount userAccount) {
            rabbitTemplate.convertAndSend("Hello message sent at " + new DateTime());
        }
    }
    

    In the consumer’s constructor I declare the queue and create the binding.

    public class Consumer implements ChannelAwareMessageListener<Message> {
    
        public Consumer(final RabbitAdmin rabbitAdmin, final Exchange exchange, final Queue queue) {
            rabbitAdmin.declareQueue(queue);
    
            rabbitAdmin.declareBinding(BindingBuilder.from(queue).to((DirectExchange) exchange).withQueueName());
        }
    
        @Override
        public void onMessage(Message message, Channel channel) throws Exception {
    
            System.out.println(new String(message.getBody()));
    
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
        }
    }
    

    Although the constructors may be run many times, RabbitMQ only declares the exchange, queue and bindings once.

    If you need the whole source for this little example project, ask, and I’ll put it up somewhere for you.

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

Sidebar

Related Questions

No related questions found

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.