Reactor2TcpClient constructor with address supplier

Issue: SPR-12452
This commit is contained in:
Rossen Stoyanchev
2018-03-20 12:21:45 -04:00
parent 0e28bee0f1
commit 88a17a4b10
3 changed files with 63 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.messaging.tcp.TcpOperations;
import org.springframework.util.Assert;
/**
@@ -51,6 +52,9 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
@Nullable
private String virtualHost;
@Nullable
private TcpOperations<byte[]> tcpClient;
private boolean autoStartup = true;
@Nullable
@@ -166,6 +170,18 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
return this;
}
/**
* Configure a TCP client for managing TCP connections to the STOMP broker.
* <p>By default {@code ReactorNettyTcpClient} is used.
* <p><strong>Note:</strong> when this property is used, any
* {@link #setRelayHost(String) host} or {@link #setRelayPort(int) port}
* specified are effectively ignored.
* @since 4.3.15
*/
public void setTcpClient(TcpOperations<byte[]> tcpClient) {
this.tcpClient = tcpClient;
}
/**
* Configure whether the {@link StompBrokerRelayMessageHandler} should start
* automatically when the Spring ApplicationContext is refreshed.
@@ -239,6 +255,9 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
if (this.virtualHost != null) {
handler.setVirtualHost(this.virtualHost);
}
if (this.tcpClient != null) {
handler.setTcpClient(this.tcpClient);
}
handler.setAutoStartup(this.autoStartup);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -340,6 +340,9 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
/**
* Configure a TCP client for managing TCP connections to the STOMP broker.
* <p>By default {@link ReactorNettyTcpClient} is used.
* <p><strong>Note:</strong> when this property is used, any
* {@link #setRelayHost(String) host} or {@link #setRelayPort(int) port}
* specified are effectively ignored.
*/
public void setTcpClient(@Nullable TcpOperations<byte[]> tcpClient) {
this.tcpClient = tcpClient;
@@ -613,8 +616,8 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
* the TCP connection, failure to send a message, missed heartbeat, etc.
*/
protected void handleTcpConnectionFailure(String error, @Nullable Throwable ex) {
if (logger.isErrorEnabled()) {
logger.error("TCP connection failure in session " + this.sessionId + ": " + error, ex);
if (logger.isWarnEnabled()) {
logger.warn("TCP connection failure in session " + this.sessionId + ": " + error, ex);
}
try {
sendStompErrorFrameToClient(error);