'How to setup multiple topics in a RabbitMQ Java config class using Spring Framework?

I'm trying to create a RabbitMQ configuration class using Spring Framework. The documentation does not say anything on how to setup multiple topics in a TopicExchange. How do I do that? So far, I have this Java code but I'm not clear on how to setup multiple topics in the binding method below since it only returns one binding. Would I not need multiple bindings if I need multiple topics?

@Configuration
@EnableRabbit
public class MessageReceiverConfiguration {

    final static String queueName = "identity";
    final static String topic1 = "NewUserSignedUp";
    final static String topic2 = "AccountCreated";

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Bean
    Queue queue() {
        return new Queue(queueName, false);
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange("DomainEvents");
    }   

    @Bean
    Binding binding(Queue queue, TopicExchange exchange) {
        // How to setup multiple topics?
        return BindingBuilder.bind(queue).to(exchange).with(topic1);
    }

    @Bean
    SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {

        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();

        container.setConnectionFactory(connectionFactory);
        container.setQueueNames(queueName);
        container.setMessageListener(listenerAdapter);
        container.setAcknowledgeMode(AcknowledgeMode.AUTO);

        return container;
    }

    @Bean
    MessageReceiver receiver() {
        return new MessageReceiver();
    }

    @Bean
    MessageListenerAdapter listenerAdapter(MessageReceiver receiver) {
        return new MessageListenerAdapter(receiver, "receiveMessage");
    }    

}


Solution 1:[1]

List<Binding> bindings() not supported by spring boot 2.+ versions. This one works;

@Bean
public Declarables bindings() {

    return new Declarables(
            BindingBuilder
                    .bind(bookingAddQueue())
                    .to(bookingExchange())
                    .with("add")
                    .noargs(),
            BindingBuilder
                    .bind(bookingEditQueue())
                    .to(bookingExchange())
                    .with("edit")
                    .noargs());
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1