Skip to content

Commit 1dedb67

Browse files
committed
Set virtualHost on StompBrokerRelayRegistration
Prior to this commit, one couldn't set the virtualHost property on StompBrokerRelayMessageHandler via JavaConfig, since StompBrokerRelayRegistration's API didn't offer that possibility. This commit adds a new method in StompBrokerRelayRegistration's fluent API to set the virtualHost used by StompBrokerRelayMessageHandler. Note: this property is already configurable via xml config. Issue: SPR-11433
1 parent bde4964 commit 1dedb67

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
4545

4646
private Long systemHeartbeatReceiveInterval;
4747

48+
private String virtualHost;
49+
4850
private boolean autoStartup = true;
4951

5052

@@ -146,6 +148,19 @@ public StompBrokerRelayRegistration setSystemHeartbeatReceiveInterval(long heart
146148
return this;
147149
}
148150

151+
/**
152+
* Set the value of the "host" header to use in STOMP CONNECT frames. When this
153+
* property is configured, a "host" header will be added to every STOMP frame sent to
154+
* the STOMP broker. This may be useful for example in a cloud environment where the
155+
* actual host to which the TCP connection is established is different from the host
156+
* providing the cloud-based STOMP service.
157+
* <p>By default this property is not set.
158+
*/
159+
public StompBrokerRelayRegistration setVirtualHost(String virtualHost) {
160+
this.virtualHost = virtualHost;
161+
return this;
162+
}
163+
149164
/**
150165
* Configure whether the {@link StompBrokerRelayMessageHandler} should start
151166
* automatically when the Spring ApplicationContext is refreshed.
@@ -177,6 +192,9 @@ protected StompBrokerRelayMessageHandler getMessageHandler(SubscribableChannel b
177192
if (this.systemHeartbeatReceiveInterval != null) {
178193
handler.setSystemHeartbeatReceiveInterval(this.systemHeartbeatReceiveInterval);
179194
}
195+
if(this.virtualHost != null) {
196+
handler.setVirtualHost(this.virtualHost);
197+
}
180198

181199
handler.setAutoStartup(this.autoStartup);
182200

spring-messaging/src/test/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistrationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public void test() {
5353
registration.setSystemPasscode("syspasscode");
5454
registration.setSystemHeartbeatReceiveInterval(123);
5555
registration.setSystemHeartbeatSendInterval(456);
56+
registration.setVirtualHost("example.org");
5657

5758
StompBrokerRelayMessageHandler relayMessageHandler = registration.getMessageHandler(brokerChannel);
5859

@@ -63,6 +64,7 @@ public void test() {
6364
assertEquals("syspasscode", relayMessageHandler.getSystemPasscode());
6465
assertEquals(123, relayMessageHandler.getSystemHeartbeatReceiveInterval());
6566
assertEquals(456, relayMessageHandler.getSystemHeartbeatSendInterval());
67+
assertEquals("example.org", relayMessageHandler.getVirtualHost());
6668
}
6769

6870
}

0 commit comments

Comments
 (0)