|
33 | 33 | import org.springframework.messaging.tcp.TcpConnection;
|
34 | 34 | import org.springframework.messaging.tcp.TcpConnectionHandler;
|
35 | 35 | import org.springframework.messaging.tcp.TcpOperations;
|
36 |
| -import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient; |
37 | 36 | import org.springframework.util.Assert;
|
38 | 37 | import org.springframework.util.concurrent.ListenableFuture;
|
39 | 38 | import org.springframework.util.concurrent.ListenableFutureCallback;
|
|
51 | 50 | *
|
52 | 51 | * <p>This class also automatically opens a default "system" TCP connection to the message
|
53 | 52 | * broker that is used for sending messages that originate from the server application (as
|
54 |
| - * opposed to from a client). Such messages are recognized because they are not associated |
55 |
| - * with any client and therefore do not have a session id header. The "system" connection |
56 |
| - * is effectively shared and cannot be used to receive messages. Several properties are |
57 |
| - * provided to configure the "system" connection including the the |
58 |
| - * {@link #setSystemLogin(String) login} {@link #setSystemPasscode(String) passcode}, |
59 |
| - * heartbeat {@link #setSystemHeartbeatSendInterval(long) send} and |
60 |
| - * {@link #setSystemHeartbeatReceiveInterval(long) receive} intervals. |
| 53 | + * opposed to from a client). Such messages are are not associated with any client and |
| 54 | + * therefore do not have a session id header. The "system" connection is effectively |
| 55 | + * shared and cannot be used to receive messages. Several properties are provided to |
| 56 | + * configure the "system" connection including: |
| 57 | + * <ul> |
| 58 | + * <li>{@link #setSystemLogin(String)}</li> |
| 59 | + * <li>{@link #setSystemPasscode(String)}</li> |
| 60 | + * <li>{@link #setSystemHeartbeatSendInterval(long)}</li> |
| 61 | + * <li>{@link #setSystemHeartbeatReceiveInterval(long)}</li> |
| 62 | + * </ul> |
61 | 63 | *
|
62 | 64 | * @author Rossen Stoyanchev
|
63 | 65 | * @author Andy Wilkinson
|
@@ -87,6 +89,10 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
87 | 89 |
|
88 | 90 | private int relayPort = 61613;
|
89 | 91 |
|
| 92 | + private String clientLogin = "guest"; |
| 93 | + |
| 94 | + private String clientPasscode = "guest"; |
| 95 | + |
90 | 96 | private String systemLogin = "guest";
|
91 | 97 |
|
92 | 98 | private String systemPasscode = "guest";
|
@@ -198,33 +204,79 @@ public long getSystemHeartbeatReceiveInterval() {
|
198 | 204 | }
|
199 | 205 |
|
200 | 206 | /**
|
201 |
| - * Set the login for the "system" connection used to send messages to the STOMP |
202 |
| - * broker without having a client session (e.g. REST/HTTP request handling method). |
203 |
| - * <p>See class-level documentation for more information on the "system" connection. |
| 207 | + * Set the login to use when creating connections to the STOMP broker on |
| 208 | + * behalf of connected clients. |
| 209 | + * <p> |
| 210 | + * By default this is set to "guest". |
| 211 | + * @see #setSystemLogin(String) |
| 212 | + */ |
| 213 | + public void setClientLogin(String clientLogin) { |
| 214 | + Assert.hasText(clientLogin, "clientLogin must not be empty"); |
| 215 | + this.clientLogin = clientLogin; |
| 216 | + } |
| 217 | + |
| 218 | + /** |
| 219 | + * @return the configured login to use for connections to the STOMP broker |
| 220 | + * on behalf of connected clients. |
| 221 | + * @see #getSystemLogin() |
| 222 | + */ |
| 223 | + public String getClientLogin() { |
| 224 | + return this.clientLogin; |
| 225 | + } |
| 226 | + |
| 227 | + /** |
| 228 | + * Set the clientPasscode to use to create connections to the STOMP broker on |
| 229 | + * behalf of connected clients. |
| 230 | + * <p> |
| 231 | + * By default this is set to "guest". |
| 232 | + * @see #setSystemPasscode(String) |
| 233 | + */ |
| 234 | + public void setClientPasscode(String clientPasscode) { |
| 235 | + Assert.hasText(clientPasscode, "clientPasscode must not be empty"); |
| 236 | + this.clientPasscode = clientPasscode; |
| 237 | + } |
| 238 | + |
| 239 | + /** |
| 240 | + * @return the configured passocde to use for connections to the STOMP broker on |
| 241 | + * behalf of connected clients. |
| 242 | + * @see #getSystemPasscode() |
| 243 | + */ |
| 244 | + public String getClientPasscode() { |
| 245 | + return this.clientPasscode; |
| 246 | + } |
| 247 | + |
| 248 | + /** |
| 249 | + * Set the login for the shared "system" connection used to send messages to |
| 250 | + * the STOMP broker from within the application, i.e. messages not associated |
| 251 | + * with a specific client session (e.g. REST/HTTP request handling method). |
| 252 | + * <p> |
| 253 | + * By default this is set to "guest". |
204 | 254 | */
|
205 | 255 | public void setSystemLogin(String systemLogin) {
|
206 | 256 | Assert.hasText(systemLogin, "systemLogin must not be empty");
|
207 | 257 | this.systemLogin = systemLogin;
|
208 | 258 | }
|
209 | 259 |
|
210 | 260 | /**
|
211 |
| - * @return the login used by the "system" connection to connect to the STOMP broker |
| 261 | + * @return the login used for the shared "system" connection to the STOMP broker |
212 | 262 | */
|
213 | 263 | public String getSystemLogin() {
|
214 | 264 | return this.systemLogin;
|
215 | 265 | }
|
216 | 266 |
|
217 | 267 | /**
|
218 |
| - * Set the passcode for the "system" connection used to send messages to the STOMP |
219 |
| - * broker without having a client session (e.g. REST/HTTP request handling method). |
220 |
| - * <p>See class-level documentation for more information on the "system" connection. |
| 268 | + * Set the passcode for the shared "system" connection used to send messages to |
| 269 | + * the STOMP broker from within the application, i.e. messages not associated |
| 270 | + * with a specific client session (e.g. REST/HTTP request handling method). |
| 271 | + * <p> |
| 272 | + * By default this is set to "guest". |
221 | 273 | */
|
222 | 274 | public void setSystemPasscode(String systemPasscode) {
|
223 | 275 | this.systemPasscode = systemPasscode;
|
224 | 276 | }
|
225 | 277 |
|
226 | 278 | /**
|
227 |
| - * @return the passcode used by the "system" connection to connect to the STOMP broker |
| 279 | + * @return the passcode used for the shared "system" connection to the STOMP broker |
228 | 280 | */
|
229 | 281 | public String getSystemPasscode() {
|
230 | 282 | return this.systemPasscode;
|
@@ -348,6 +400,8 @@ protected void handleMessageInternal(Message<?> message) {
|
348 | 400 |
|
349 | 401 | if (SimpMessageType.CONNECT.equals(messageType)) {
|
350 | 402 | logger.debug("Processing CONNECT in session=" + sessionId);
|
| 403 | + headers.setLogin(this.clientLogin); |
| 404 | + headers.setPasscode(this.clientPasscode); |
351 | 405 | if (getVirtualHost() != null) {
|
352 | 406 | headers.setHost(getVirtualHost());
|
353 | 407 | }
|
|
0 commit comments