Skip to content

Commit c2551b0

Browse files
committed
Add ErrorOnWriteListener property to ConnectionFactory
This way connection recovery triggering on write can be disabled or customised. [#154263515] References #341
1 parent aaa5439 commit c2551b0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main/java/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ public class ConnectionFactory implements Cloneable {
141141
*/
142142
private boolean channelShouldCheckRpcResponseType = false;
143143

144+
/**
145+
* Listener called when a connection gets an IO error trying to write on the socket.
146+
* Default listener triggers connection recovery asynchronously and propagates
147+
* the exception.
148+
* @since 4.5.0
149+
*/
150+
private ErrorOnWriteListener errorOnWriteListener;
151+
144152
/**
145153
* Timeout in ms for work pool enqueuing.
146154
* @since 4.5.0
@@ -984,6 +992,7 @@ public ConnectionParams params(ExecutorService consumerWorkServiceExecutor) {
984992
result.setChannelRpcTimeout(channelRpcTimeout);
985993
result.setChannelShouldCheckRpcResponseType(channelShouldCheckRpcResponseType);
986994
result.setWorkPoolTimeout(workPoolTimeout);
995+
result.setErrorOnWriteListener(errorOnWriteListener);
987996
return result;
988997
}
989998

@@ -1292,7 +1301,9 @@ public boolean isChannelShouldCheckRpcResponseType() {
12921301
* TCP connection failure. Note this shouldn't happen
12931302
* with clients that set appropriate QoS values.
12941303
* Default is no timeout.
1304+
*
12951305
* @param workPoolTimeout timeout in ms
1306+
* @since 4.5.0
12961307
*/
12971308
public void setWorkPoolTimeout(int workPoolTimeout) {
12981309
this.workPoolTimeout = workPoolTimeout;
@@ -1301,4 +1312,17 @@ public void setWorkPoolTimeout(int workPoolTimeout) {
13011312
public int getWorkPoolTimeout() {
13021313
return workPoolTimeout;
13031314
}
1315+
1316+
/**
1317+
* Set a listener to be called when connection gets an IO error trying to write on the socket.
1318+
* Default listener triggers connection recovery asynchronously and propagates
1319+
* the exception. Override the default listener to disable or
1320+
* customise automatic connection triggering on write operations.
1321+
*
1322+
* @param errorOnWriteListener the listener
1323+
* @since 4.5.0
1324+
*/
1325+
public void setErrorOnWriteListener(ErrorOnWriteListener errorOnWriteListener) {
1326+
this.errorOnWriteListener = errorOnWriteListener;
1327+
}
13041328
}

src/main/java/com/rabbitmq/client/impl/ErrorOnWriteListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import java.io.IOException;
2121

2222
/**
23-
* Listener called when a connection gets an error trying to write on the socket.
23+
* Listener called when a connection gets an IO error trying to write on the socket.
2424
* This can be used to trigger connection recovery.
25+
*
26+
* @since 4.5.0
2527
*/
2628
public interface ErrorOnWriteListener {
2729

0 commit comments

Comments
 (0)