Skip to content

Commit d8ba3e8

Browse files
authored
Merge pull request #671 from rabbitmq/rabbitmq-java-client-670
Make channels instantiated with a user-provided number recoverable
2 parents ee8af1a + a7bd239 commit d8ba3e8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ public Channel createChannel() throws IOException {
176176
*/
177177
@Override
178178
public Channel createChannel(int channelNumber) throws IOException {
179-
return delegate.createChannel(channelNumber);
179+
RecoveryAwareChannelN ch = (RecoveryAwareChannelN) delegate.createChannel(channelNumber);
180+
// No Sonar: the channel could be null
181+
if (ch == null) { //NOSONAR
182+
return null;
183+
} else {
184+
return this.wrapChannel(ch);
185+
}
180186
}
181187

182188
/**

src/test/java/com/rabbitmq/client/test/functional/ConnectionRecovery.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,22 @@ public void handleUnblocked() throws IOException {
281281
expectChannelRecovery(ch2);
282282
}
283283

284+
@Test public void channelRecoveryWithUserProvidedChannelIDs() throws IOException, InterruptedException {
285+
int n1 = 11;
286+
Channel ch1 = connection.createChannel(n1);
287+
int n2 = 22;
288+
Channel ch2 = connection.createChannel(n2);
289+
290+
assertThat(ch1.isOpen()).isTrue();
291+
assertThat(ch2.isOpen()).isTrue();
292+
closeAndWaitForRecovery();
293+
expectChannelRecovery(ch1);
294+
expectChannelRecovery(ch2);
295+
296+
assertThat(ch1.getChannelNumber()).isEqualTo(n1);
297+
assertThat(ch2.getChannelNumber()).isEqualTo(n2);
298+
}
299+
284300
@Test public void returnListenerRecovery() throws IOException, InterruptedException {
285301
final CountDownLatch latch = new CountDownLatch(1);
286302
channel.addReturnListener(new ReturnListener() {

0 commit comments

Comments
 (0)