use of org.springframework.messaging.simp.user.UserDestinationMessageHandler in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method userDestinationMessageHandler.
@Bean
public UserDestinationMessageHandler userDestinationMessageHandler() {
UserDestinationMessageHandler handler = new UserDestinationMessageHandler(clientInboundChannel(), brokerChannel(), userDestinationResolver());
String destination = getBrokerRegistry().getUserDestinationBroadcast();
handler.setBroadcastDestination(destination);
return handler;
}
use of org.springframework.messaging.simp.user.UserDestinationMessageHandler in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method stompBrokerRelayMessageHandler.
@Bean
public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler() {
StompBrokerRelayMessageHandler handler = getBrokerRegistry().getStompBrokerRelay(brokerChannel());
if (handler == null) {
return new NoOpBrokerMessageHandler();
}
Map<String, MessageHandler> subscriptions = new HashMap<>(1);
String destination = getBrokerRegistry().getUserDestinationBroadcast();
if (destination != null) {
subscriptions.put(destination, userDestinationMessageHandler());
}
destination = getBrokerRegistry().getUserRegistryBroadcast();
if (destination != null) {
subscriptions.put(destination, userRegistryMessageHandler());
}
handler.setSystemSubscriptions(subscriptions);
return handler;
}
use of org.springframework.messaging.simp.user.UserDestinationMessageHandler in project spring-framework by spring-projects.
the class TestValidator method stompBrokerRelay.
@Test
public void stompBrokerRelay() {
loadBeanDefinitions("websocket-config-broker-relay.xml");
HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
assertThat(hm).isNotNull();
assertThat(hm).isInstanceOf(SimpleUrlHandlerMapping.class);
SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm;
assertThat(suhm.getUrlMap()).hasSize(1);
assertThat(suhm.getOrder()).isEqualTo(2);
HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo/**");
assertThat(httpRequestHandler).isNotNull();
assertThat(httpRequestHandler).isInstanceOf(SockJsHttpRequestHandler.class);
SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler;
WebSocketHandler wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler());
assertThat(wsHandler).isNotNull();
assertThat(wsHandler).isInstanceOf(SubProtocolWebSocketHandler.class);
assertThat(sockJsHttpRequestHandler.getSockJsService()).isNotNull();
UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
assertThat(userDestResolver).isNotNull();
assertThat(userDestResolver).isInstanceOf(DefaultUserDestinationResolver.class);
DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver;
assertThat(defaultUserDestResolver.getDestinationPrefix()).isEqualTo("/user/");
StompBrokerRelayMessageHandler messageBroker = this.appContext.getBean(StompBrokerRelayMessageHandler.class);
assertThat(messageBroker).isNotNull();
assertThat(messageBroker.getClientLogin()).isEqualTo("clientlogin");
assertThat(messageBroker.getClientPasscode()).isEqualTo("clientpass");
assertThat(messageBroker.getSystemLogin()).isEqualTo("syslogin");
assertThat(messageBroker.getSystemPasscode()).isEqualTo("syspass");
assertThat(messageBroker.getRelayHost()).isEqualTo("relayhost");
assertThat(messageBroker.getRelayPort()).isEqualTo(1234);
assertThat(messageBroker.getVirtualHost()).isEqualTo("spring.io");
assertThat(messageBroker.getSystemHeartbeatReceiveInterval()).isEqualTo(5000);
assertThat(messageBroker.getSystemHeartbeatSendInterval()).isEqualTo(5000);
assertThat(messageBroker.getDestinationPrefixes()).containsExactlyInAnyOrder("/topic", "/queue");
assertThat(messageBroker.isPreservePublishOrder()).isTrue();
List<Class<? extends MessageHandler>> subscriberTypes = Arrays.asList(SimpAnnotationMethodMessageHandler.class, UserDestinationMessageHandler.class, StompBrokerRelayMessageHandler.class);
testChannel("clientInboundChannel", subscriberTypes, 2);
testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
subscriberTypes = Collections.singletonList(SubProtocolWebSocketHandler.class);
testChannel("clientOutboundChannel", subscriberTypes, 2);
testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
subscriberTypes = Arrays.asList(StompBrokerRelayMessageHandler.class, UserDestinationMessageHandler.class);
testChannel("brokerChannel", subscriberTypes, 1);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class));
String destination = "/topic/unresolved-user-destination";
UserDestinationMessageHandler userDestHandler = this.appContext.getBean(UserDestinationMessageHandler.class);
assertThat(userDestHandler.getBroadcastDestination()).isEqualTo(destination);
assertThat(messageBroker.getSystemSubscriptions()).isNotNull();
assertThat(messageBroker.getSystemSubscriptions().get(destination)).isSameAs(userDestHandler);
destination = "/topic/simp-user-registry";
UserRegistryMessageHandler userRegistryHandler = this.appContext.getBean(UserRegistryMessageHandler.class);
assertThat(userRegistryHandler.getBroadcastDestination()).isEqualTo(destination);
assertThat(messageBroker.getSystemSubscriptions()).isNotNull();
assertThat(messageBroker.getSystemSubscriptions().get(destination)).isSameAs(userRegistryHandler);
SimpUserRegistry userRegistry = this.appContext.getBean(SimpUserRegistry.class);
assertThat(userRegistry.getClass()).isEqualTo(MultiServerUserRegistry.class);
String name = "webSocketMessageBrokerStats";
WebSocketMessageBrokerStats stats = this.appContext.getBean(name, WebSocketMessageBrokerStats.class);
String actual = stats.toString();
String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " + "0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)], " + "stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)], " + "stompBrokerRelay\\[0 sessions, relayhost:1234 \\(not available\\), " + "processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)], " + "inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " + "completed tasks = \\d], " + "outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " + "completed tasks = \\d], " + "sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " + "completed tasks = \\d]";
assertThat(actual.matches(expected)).as("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual).isTrue();
}
use of org.springframework.messaging.simp.user.UserDestinationMessageHandler in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method stompBrokerRelayMessageHandler.
@Bean
@Nullable
public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationMessageHandler userDestinationMessageHandler, @Nullable MessageHandler userRegistryMessageHandler, UserDestinationResolver userDestinationResolver) {
MessageBrokerRegistry registry = getBrokerRegistry(clientInboundChannel, clientOutboundChannel);
StompBrokerRelayMessageHandler handler = registry.getStompBrokerRelay(brokerChannel);
if (handler == null) {
return null;
}
Map<String, MessageHandler> subscriptions = new HashMap<>(4);
String destination = registry.getUserDestinationBroadcast();
if (destination != null) {
subscriptions.put(destination, userDestinationMessageHandler);
}
destination = registry.getUserRegistryBroadcast();
if (destination != null) {
subscriptions.put(destination, userRegistryMessageHandler);
}
handler.setSystemSubscriptions(subscriptions);
updateUserDestinationResolver(handler, userDestinationResolver, registry.getUserDestinationPrefix());
return handler;
}
use of org.springframework.messaging.simp.user.UserDestinationMessageHandler in project spring-framework by spring-projects.
the class MessageBrokerConfigurationTests method userBroadcasts.
@Test
public void userBroadcasts() {
ApplicationContext context = loadConfig(BrokerRelayConfig.class);
SimpUserRegistry userRegistry = context.getBean(SimpUserRegistry.class);
assertThat(userRegistry.getClass()).isEqualTo(MultiServerUserRegistry.class);
UserDestinationMessageHandler handler1 = context.getBean(UserDestinationMessageHandler.class);
assertThat(handler1.getBroadcastDestination()).isEqualTo("/topic/unresolved-user-destination");
UserRegistryMessageHandler handler2 = context.getBean(UserRegistryMessageHandler.class);
assertThat(handler2.getBroadcastDestination()).isEqualTo("/topic/simp-user-registry");
StompBrokerRelayMessageHandler relay = context.getBean(StompBrokerRelayMessageHandler.class);
assertThat(relay.getSystemSubscriptions()).isNotNull();
assertThat(relay.getSystemSubscriptions().size()).isEqualTo(2);
assertThat(relay.getSystemSubscriptions().get("/topic/unresolved-user-destination")).isSameAs(handler1);
assertThat(relay.getSystemSubscriptions().get("/topic/simp-user-registry")).isSameAs(handler2);
}
Aggregations