Browse Source

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
pull/466/head
Brian Clozel 12 years ago
parent
commit
1dedb67fbc
  1. 18
      spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java
  2. 2
      spring-messaging/src/test/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistrationTests.java

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

@ -45,6 +45,8 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
private Long systemHeartbeatReceiveInterval; private Long systemHeartbeatReceiveInterval;
private String virtualHost;
private boolean autoStartup = true; private boolean autoStartup = true;
@ -146,6 +148,19 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
return this; return this;
} }
/**
* Set the value of the "host" header to use in STOMP CONNECT frames. When this
* property is configured, a "host" header will be added to every STOMP frame sent to
* the STOMP broker. This may be useful for example in a cloud environment where the
* actual host to which the TCP connection is established is different from the host
* providing the cloud-based STOMP service.
* <p>By default this property is not set.
*/
public StompBrokerRelayRegistration setVirtualHost(String virtualHost) {
this.virtualHost = virtualHost;
return this;
}
/** /**
* Configure whether the {@link StompBrokerRelayMessageHandler} should start * Configure whether the {@link StompBrokerRelayMessageHandler} should start
* automatically when the Spring ApplicationContext is refreshed. * automatically when the Spring ApplicationContext is refreshed.
@ -177,6 +192,9 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {
if (this.systemHeartbeatReceiveInterval != null) { if (this.systemHeartbeatReceiveInterval != null) {
handler.setSystemHeartbeatReceiveInterval(this.systemHeartbeatReceiveInterval); handler.setSystemHeartbeatReceiveInterval(this.systemHeartbeatReceiveInterval);
} }
if(this.virtualHost != null) {
handler.setVirtualHost(this.virtualHost);
}
handler.setAutoStartup(this.autoStartup); handler.setAutoStartup(this.autoStartup);

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

@ -53,6 +53,7 @@ public class StompBrokerRelayRegistrationTests {
registration.setSystemPasscode("syspasscode"); registration.setSystemPasscode("syspasscode");
registration.setSystemHeartbeatReceiveInterval(123); registration.setSystemHeartbeatReceiveInterval(123);
registration.setSystemHeartbeatSendInterval(456); registration.setSystemHeartbeatSendInterval(456);
registration.setVirtualHost("example.org");
StompBrokerRelayMessageHandler relayMessageHandler = registration.getMessageHandler(brokerChannel); StompBrokerRelayMessageHandler relayMessageHandler = registration.getMessageHandler(brokerChannel);
@ -63,6 +64,7 @@ public class StompBrokerRelayRegistrationTests {
assertEquals("syspasscode", relayMessageHandler.getSystemPasscode()); assertEquals("syspasscode", relayMessageHandler.getSystemPasscode());
assertEquals(123, relayMessageHandler.getSystemHeartbeatReceiveInterval()); assertEquals(123, relayMessageHandler.getSystemHeartbeatReceiveInterval());
assertEquals(456, relayMessageHandler.getSystemHeartbeatSendInterval()); assertEquals(456, relayMessageHandler.getSystemHeartbeatSendInterval());
assertEquals("example.org", relayMessageHandler.getVirtualHost());
} }
} }

Loading…
Cancel
Save