Skip to content

Commit

Permalink
Merge pull request #82 from basert/master
Browse files Browse the repository at this point in the history
#75 use a connection factory with automatic recovery disabled by default
  • Loading branch information
michaelklishin authored Oct 4, 2017
2 parents ea47a0e + a838fef commit 3e3a8a2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/net/jodah/lyra/ConnectionOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ConnectionOptions {
private Boolean useNio = false;

public ConnectionOptions() {
factory = new ConnectionFactory();
factory = makeConnectionFactory();
}

/**
Expand All @@ -49,7 +49,7 @@ private ConnectionOptions(ConnectionOptions options) {
nioParams = options.nioParams;
useNio = options.useNio;

factory = new ConnectionFactory();
factory = makeConnectionFactory();
factory.setAutomaticRecoveryEnabled(options.factory.isAutomaticRecoveryEnabled());
factory.setClientProperties(options.factory.getClientProperties());
factory.setConnectionTimeout(options.factory.getConnectionTimeout());
Expand Down Expand Up @@ -86,6 +86,19 @@ public ConnectionOptions copy() {
return new ConnectionOptions(this);
}

/**
* Returns a rabbitmq-java connection factory instance with automatic recovery turned off by default.
* This is necessary as rabbitmq-java > 4.0.0 enables it by default, resulting in two restored consumer in case of
* connection resets.
*
* @return a com.rabbitmq.client.ConnectionFactory with automatic recovery disabled
*/
private ConnectionFactory makeConnectionFactory() {
ConnectionFactory factory = new ConnectionFactory();
factory.setAutomaticRecoveryEnabled(false);
return factory;
}

/**
* Returns the addresses to attempt connections to, in round-robin order.
*
Expand Down

0 comments on commit 3e3a8a2

Please sign in to comment.