Skip to content

Commit b25637e

Browse files
committed
Make setTaskScheduler and setTcpClient chaining-friendly
Closes gh-26049
1 parent 0c34776 commit b25637e

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
5656
@Nullable
5757
private TcpOperations<byte[]> tcpClient;
5858

59+
@Nullable
60+
private TaskScheduler taskScheduler;
61+
5962
private boolean autoStartup = true;
6063

6164
@Nullable
@@ -64,8 +67,6 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
6467
@Nullable
6568
private String userRegistryBroadcast;
6669

67-
@Nullable
68-
private TaskScheduler taskScheduler;
6970

7071
public StompBrokerRelayRegistration(SubscribableChannel clientInboundChannel,
7172
MessageChannel clientOutboundChannel, String[] destinationPrefixes) {
@@ -181,8 +182,27 @@ public StompBrokerRelayRegistration setVirtualHost(String virtualHost) {
181182
* specified are effectively ignored.
182183
* @since 4.3.15
183184
*/
184-
public void setTcpClient(TcpOperations<byte[]> tcpClient) {
185+
public StompBrokerRelayRegistration setTcpClient(TcpOperations<byte[]> tcpClient) {
185186
this.tcpClient = tcpClient;
187+
return this;
188+
}
189+
190+
/**
191+
* Some STOMP clients (e.g. stomp-js) always send heartbeats at a fixed rate
192+
* but others (Spring STOMP client) do so only when no other messages are
193+
* sent. However messages with a non-broker {@link #getDestinationPrefixes()
194+
* destination prefix} aren't forwarded and as a result the broker may deem
195+
* the connection inactive.
196+
* <p>When this {@link TaskScheduler} is set, it is used to reset a count of
197+
* the number of messages sent from client to broker since the beginning of
198+
* the current heartbeat period. This is then used to decide whether to send
199+
* a heartbeat to the broker when ignoring a message with a non-broker
200+
* destination prefix.
201+
* @since 5.3
202+
*/
203+
public StompBrokerRelayRegistration setTaskScheduler(@Nullable TaskScheduler taskScheduler) {
204+
this.taskScheduler = taskScheduler;
205+
return this;
186206
}
187207

188208
/**
@@ -228,26 +248,6 @@ public StompBrokerRelayRegistration setUserRegistryBroadcast(String destination)
228248
return this;
229249
}
230250

231-
/**
232-
* Some STOMP clients (e.g. stomp-js) always send heartbeats at a fixed rate
233-
* but others (Spring STOMP client) do so only when no other messages are
234-
* sent. However messages with a non-broker {@link #getDestinationPrefixes()
235-
* destination prefix} aren't forwarded and as a result the broker may deem
236-
* the connection inactive.
237-
*
238-
* <p>When this {@link TaskScheduler} is set, it is used to reset a count of
239-
* the number of messages sent from client to broker since the beginning of
240-
* the current heartbeat period. This is then used to decide whether to send
241-
* a heartbeat to the broker when ignoring a message with a non-broker
242-
* destination prefix.
243-
*
244-
* @param taskScheduler the scheduler to use
245-
* @since 5.3
246-
*/
247-
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler) {
248-
this.taskScheduler = taskScheduler;
249-
}
250-
251251
@Nullable
252252
protected String getUserRegistryBroadcast() {
253253
return this.userRegistryBroadcast;
@@ -256,7 +256,6 @@ protected String getUserRegistryBroadcast() {
256256

257257
@Override
258258
protected StompBrokerRelayMessageHandler getMessageHandler(SubscribableChannel brokerChannel) {
259-
260259
StompBrokerRelayMessageHandler handler = new StompBrokerRelayMessageHandler(
261260
getClientInboundChannel(), getClientOutboundChannel(),
262261
brokerChannel, getDestinationPrefixes());

0 commit comments

Comments
 (0)