Configuring an exchange

Now, we need to create an AMQP exchange, to which a message producer will send a message. The Exchange interface represents an AMQP exchange. There are four implementations of the Exchange interface type: DirectExchange, TopicExchange, FanoutExchange, and HeadersExchange. We can use any exchange type based on our requirements. We will use DirectExchange using the following code:

@Bean
public DirectExchange exchange() {
return new DirectExchange(RABBIT_MESSAGE_EXCHANGE);
}

The exchange() method creates DirectExchange with a specific name defined under RABBIT_MESSAGE_EXCHANGE. We can also set the durability using the durable flag. We need to pass it along with the second constructor argument as a Boolean type.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset