Skip to content

Commit 052e922

Browse files
Make exception handler configurable via ConnectionFactory
1 parent 0374452 commit 052e922

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import com.rabbitmq.client.impl.AMQConnection;
3535
import com.rabbitmq.client.impl.ConnectionParams;
36+
import com.rabbitmq.client.impl.DefaultExceptionHandler;
37+
import com.rabbitmq.client.impl.ExceptionHandler;
3638
import com.rabbitmq.client.impl.FrameHandler;
3739
import com.rabbitmq.client.impl.FrameHandlerFactory;
3840
import com.rabbitmq.client.impl.recovery.AutorecoveringConnection;
@@ -90,6 +92,7 @@ public class ConnectionFactory implements Cloneable {
9092
private SaslConfig saslConfig = DefaultSaslConfig.PLAIN;
9193
private ExecutorService sharedExecutor;
9294
private SocketConfigurator socketConf = new DefaultSocketConfigurator();
95+
private ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
9396

9497
private boolean automaticRecovery = false;
9598
private boolean topologyRecovery = true;
@@ -426,6 +429,25 @@ public void setSharedExecutor(ExecutorService executor) {
426429
this.sharedExecutor = executor;
427430
}
428431

432+
/**
433+
* Get the exception handler.
434+
*
435+
* @see com.rabbitmq.client.impl.ExceptionHandler
436+
*/
437+
public ExceptionHandler getExceptionHandler() {
438+
return exceptionHandler;
439+
}
440+
441+
/**
442+
* Set the exception handler to use by default for newly created connections.
443+
*
444+
* @see com.rabbitmq.client.impl.ExceptionHandler
445+
*/
446+
447+
public void setExceptionHandler(ExceptionHandler exceptionHandler) {
448+
this.exceptionHandler = exceptionHandler;
449+
}
450+
429451
public boolean isSSL(){
430452
return getSocketFactory() instanceof SSLSocketFactory;
431453
}
@@ -557,7 +579,7 @@ public Connection newConnection(ExecutorService executor, Address[] addrs)
557579
public ConnectionParams params(ExecutorService executor) {
558580
return new ConnectionParams(username, password, executor, virtualHost, getClientProperties(),
559581
requestedFrameMax, requestedChannelMax, requestedHeartbeat, saslConfig,
560-
networkRecoveryInterval, topologyRecovery);
582+
networkRecoveryInterval, topologyRecovery, exceptionHandler);
561583
}
562584

563585
/**

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static final Map<String, Object> defaultClientProperties() {
110110
private volatile boolean _running = false;
111111

112112
/** Handler for (uncaught) exceptions that crop up in the {@link MainLoop}. */
113-
private final ExceptionHandler _exceptionHandler;
113+
private ExceptionHandler _exceptionHandler;
114114

115115
/** Object used for blocking main application thread when doing all the necessary
116116
* connection shutdown operations
@@ -214,6 +214,7 @@ public AMQConnection(ConnectionParams params, FrameHandler frameHandler)
214214
this.saslConfig = params.getSaslConfig();
215215

216216
this._workService = new ConsumerWorkService(params.getExecutor());
217+
this._exceptionHandler = params.getExceptionHandler();
217218
this._channelManager = null;
218219

219220
this._heartbeatSender = new HeartbeatSender(frameHandler);

src/com/rabbitmq/client/impl/ConnectionParams.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ public class ConnectionParams {
3232
* @param saslConfig sasl configuration hook
3333
* @param networkRecoveryInterval interval used when recovering from network failure
3434
* @param topologyRecovery should topology (queues, exchanges, bindings, consumers) recovery be performed?
35+
* @param exceptionHandler
3536
*/
3637
public ConnectionParams(String username, String password, ExecutorService executor,
3738
String virtualHost, Map<String, Object> clientProperties,
3839
int requestedFrameMax, int requestedChannelMax, int requestedHeartbeat,
3940
SaslConfig saslConfig, int networkRecoveryInterval,
40-
boolean topologyRecovery) {
41+
boolean topologyRecovery, ExceptionHandler exceptionHandler) {
4142
this.username = username;
4243
this.password = password;
4344
this.executor = executor;

0 commit comments

Comments
 (0)