Newsletter – Week 12, 2024

News

Articles

Videos

Title image by PublicDomainPictures from Pixabay

Newsletter – Week 11, 2024

News

Articles

Videos

Title image by Salvatore Chiarolanza from Pixabay

Newsletter – Week 10, 2024

News

Articles

Videos

Title image by Tom from Pixabay

AddressShuffleMode in Spring AMQP

There is an important configuration parameter in the Spring AMQP project CachingConnectionFactory class to understand how your application will connect to the RabbitMQ cluster. Let’s talk a little bit about this parameter.

AddressShuffleMode configuration parameter is used to specify the strategy used to connect the client library to the RabbitMQ cluster. This parameter is actual only when you have multiple host names provided in the spring.rabbitmq.addresses configuration property and it defines in which order the client will try to connect the nodes provided.

This configuration parameter has 3 possible values:

ValueDescriptionComment
INORDERShuffle the addresses after opening a connection, moving the first address to the end.available since version 2.3
NONEDo not shuffle the addresses before or after opening a connection; attempt connections in a fixed order.default before version 3.0
RANDOMRandomly shuffle the addresses before opening a connection; attempt connections in the new order.default starting version 3.0

You can define the required mode while creating CachingConnectionFactory instance:

@Bean
public CachingConnectionFactory ccf() {
    CachingConnectionFactory ccf = new CachingConnectionFactory();
    ccf.setAddresses("host1:5672,host2:5672,host3:5672");
    ccf.setAddressShuffleMode(AddressShuffleMode.INORDER);
    return ccf;
}

Each of these modes has its own benefits and drawbacks. Let’s review them now.

ModeBenefitsDrawbacks
INORDERguarantee all addresses are attempted before retrying the firstif the first address is not available for some reason will trigger the error before
retrying to the next one
NONEsimple and predictable behavior

good when you have specific knowledge about the RabbitMQ nodes health status or you have specific RabbitMQ cluster configuration
if the first address is not available for some reason will trigger the error before retrying to the next one

the first address can be overloaded with all connections coming there
RANDOMspreads connection attempts across all available addresses, potentially improving the chances of successful connectionintroduces non-deterministic behavior, making troubleshooting potential connection issues more difficult

Now, with all these details you can decide which AddressShuffleMode configuration is more applicable to your particular scenario. This parameter is equally important to understand from both the consumer and producer sides to make sure the configurations used for the producer and consumer are compatible and provide the best possible result.

Title image by Wolfgang Weiser from Pixabay

Newsletter – Week 09, 2024

News

Articles

Videos

Title image by 青釉 from Pixabay