org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler Java Examples
The following examples show how to use
org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageBrokerBeanDefinitionParser.java From spring-analysis-note with MIT License | 6 votes |
private void registerWebSocketMessageBrokerStats(RootBeanDefinition broker, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, ParserContext context, @Nullable Object source) { RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketMessageBrokerStats.class); RuntimeBeanReference webSocketHandler = new RuntimeBeanReference(WEB_SOCKET_HANDLER_BEAN_NAME); beanDef.getPropertyValues().add("subProtocolWebSocketHandler", webSocketHandler); if (StompBrokerRelayMessageHandler.class == broker.getBeanClass()) { beanDef.getPropertyValues().add("stompBrokerRelay", broker); } String name = inChannel.getBeanName() + "Executor"; if (context.getRegistry().containsBeanDefinition(name)) { beanDef.getPropertyValues().add("inboundChannelExecutor", context.getRegistry().getBeanDefinition(name)); } name = outChannel.getBeanName() + "Executor"; if (context.getRegistry().containsBeanDefinition(name)) { beanDef.getPropertyValues().add("outboundChannelExecutor", context.getRegistry().getBeanDefinition(name)); } Object scheduler = WebSocketNamespaceUtils.registerScheduler(SCHEDULER_BEAN_NAME, context, source); beanDef.getPropertyValues().add("sockJsTaskScheduler", scheduler); registerBeanDefByName("webSocketMessageBrokerStats", beanDef, context, source); }
Example #2
Source File: MessageBrokerConfigurationTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void userBroadcasts() { ApplicationContext context = loadConfig(BrokerRelayConfig.class); SimpUserRegistry userRegistry = context.getBean(SimpUserRegistry.class); assertEquals(MultiServerUserRegistry.class, userRegistry.getClass()); UserDestinationMessageHandler handler1 = context.getBean(UserDestinationMessageHandler.class); assertEquals("/topic/unresolved-user-destination", handler1.getBroadcastDestination()); UserRegistryMessageHandler handler2 = context.getBean(UserRegistryMessageHandler.class); assertEquals("/topic/simp-user-registry", handler2.getBroadcastDestination()); StompBrokerRelayMessageHandler relay = context.getBean(StompBrokerRelayMessageHandler.class); assertNotNull(relay.getSystemSubscriptions()); assertEquals(2, relay.getSystemSubscriptions().size()); assertSame(handler1, relay.getSystemSubscriptions().get("/topic/unresolved-user-destination")); assertSame(handler2, relay.getSystemSubscriptions().get("/topic/simp-user-registry")); }
Example #3
Source File: WebSocketMessageBrokerConfigurationSupport.java From java-technology-stack with MIT License | 6 votes |
@Bean public WebSocketMessageBrokerStats webSocketMessageBrokerStats() { AbstractBrokerMessageHandler relayBean = stompBrokerRelayMessageHandler(); // Ensure STOMP endpoints are registered stompWebSocketHandlerMapping(); WebSocketMessageBrokerStats stats = new WebSocketMessageBrokerStats(); stats.setSubProtocolWebSocketHandler((SubProtocolWebSocketHandler) subProtocolWebSocketHandler()); if (relayBean instanceof StompBrokerRelayMessageHandler) { stats.setStompBrokerRelay((StompBrokerRelayMessageHandler) relayBean); } stats.setInboundChannelExecutor(clientInboundChannelExecutor()); stats.setOutboundChannelExecutor(clientOutboundChannelExecutor()); stats.setSockJsTaskScheduler(messageBrokerTaskScheduler()); return stats; }
Example #4
Source File: MessageBrokerBeanDefinitionParser.java From java-technology-stack with MIT License | 6 votes |
private void registerWebSocketMessageBrokerStats(RootBeanDefinition broker, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, ParserContext context, @Nullable Object source) { RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketMessageBrokerStats.class); RuntimeBeanReference webSocketHandler = new RuntimeBeanReference(WEB_SOCKET_HANDLER_BEAN_NAME); beanDef.getPropertyValues().add("subProtocolWebSocketHandler", webSocketHandler); if (StompBrokerRelayMessageHandler.class == broker.getBeanClass()) { beanDef.getPropertyValues().add("stompBrokerRelay", broker); } String name = inChannel.getBeanName() + "Executor"; if (context.getRegistry().containsBeanDefinition(name)) { beanDef.getPropertyValues().add("inboundChannelExecutor", context.getRegistry().getBeanDefinition(name)); } name = outChannel.getBeanName() + "Executor"; if (context.getRegistry().containsBeanDefinition(name)) { beanDef.getPropertyValues().add("outboundChannelExecutor", context.getRegistry().getBeanDefinition(name)); } Object scheduler = WebSocketNamespaceUtils.registerScheduler(SCHEDULER_BEAN_NAME, context, source); beanDef.getPropertyValues().add("sockJsTaskScheduler", scheduler); registerBeanDefByName("webSocketMessageBrokerStats", beanDef, context, source); }
Example #5
Source File: AbstractMessageBrokerConfiguration.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Bean public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler() { StompBrokerRelayMessageHandler handler = getBrokerRegistry().getStompBrokerRelay(brokerChannel()); if (handler == null) { return new NoOpBrokerMessageHandler(); } Map<String, MessageHandler> subscriptions = new HashMap<String, MessageHandler>(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; }
Example #6
Source File: AbstractMessageBrokerConfiguration.java From java-technology-stack with MIT License | 6 votes |
@Bean @Nullable public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler() { StompBrokerRelayMessageHandler handler = getBrokerRegistry().getStompBrokerRelay(brokerChannel()); if (handler == null) { return null; } Map<String, MessageHandler> subscriptions = new HashMap<>(4); String destination = getBrokerRegistry().getUserDestinationBroadcast(); if (destination != null) { subscriptions.put(destination, userDestinationMessageHandler()); } destination = getBrokerRegistry().getUserRegistryBroadcast(); if (destination != null) { subscriptions.put(destination, userRegistryMessageHandler()); } handler.setSystemSubscriptions(subscriptions); updateUserDestinationResolver(handler); return handler; }
Example #7
Source File: WebSocketMessageBrokerConfigurationSupport.java From spring-analysis-note with MIT License | 6 votes |
@Bean public WebSocketMessageBrokerStats webSocketMessageBrokerStats() { AbstractBrokerMessageHandler relayBean = stompBrokerRelayMessageHandler(); // Ensure STOMP endpoints are registered stompWebSocketHandlerMapping(); WebSocketMessageBrokerStats stats = new WebSocketMessageBrokerStats(); stats.setSubProtocolWebSocketHandler((SubProtocolWebSocketHandler) subProtocolWebSocketHandler()); if (relayBean instanceof StompBrokerRelayMessageHandler) { stats.setStompBrokerRelay((StompBrokerRelayMessageHandler) relayBean); } stats.setInboundChannelExecutor(clientInboundChannelExecutor()); stats.setOutboundChannelExecutor(clientOutboundChannelExecutor()); stats.setSockJsTaskScheduler(messageBrokerTaskScheduler()); return stats; }
Example #8
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void userBroadcasts() { ApplicationContext context = loadConfig(BrokerRelayConfig.class); SimpUserRegistry userRegistry = context.getBean(SimpUserRegistry.class); assertEquals(MultiServerUserRegistry.class, userRegistry.getClass()); UserDestinationMessageHandler handler1 = context.getBean(UserDestinationMessageHandler.class); assertEquals("/topic/unresolved-user-destination", handler1.getBroadcastDestination()); UserRegistryMessageHandler handler2 = context.getBean(UserRegistryMessageHandler.class); assertEquals("/topic/simp-user-registry", handler2.getBroadcastDestination()); StompBrokerRelayMessageHandler relay = context.getBean(StompBrokerRelayMessageHandler.class); assertNotNull(relay.getSystemSubscriptions()); assertEquals(2, relay.getSystemSubscriptions().size()); assertSame(handler1, relay.getSystemSubscriptions().get("/topic/unresolved-user-destination")); assertSame(handler2, relay.getSystemSubscriptions().get("/topic/simp-user-registry")); }
Example #9
Source File: MessageBrokerConfigurationTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void userBroadcasts() throws Exception { SimpUserRegistry userRegistry = this.brokerRelayContext.getBean(SimpUserRegistry.class); assertEquals(MultiServerUserRegistry.class, userRegistry.getClass()); UserDestinationMessageHandler handler1 = this.brokerRelayContext.getBean(UserDestinationMessageHandler.class); assertEquals("/topic/unresolved-user-destination", handler1.getBroadcastDestination()); UserRegistryMessageHandler handler2 = this.brokerRelayContext.getBean(UserRegistryMessageHandler.class); assertEquals("/topic/simp-user-registry", handler2.getBroadcastDestination()); StompBrokerRelayMessageHandler relay = this.brokerRelayContext.getBean(StompBrokerRelayMessageHandler.class); assertNotNull(relay.getSystemSubscriptions()); assertEquals(2, relay.getSystemSubscriptions().size()); assertSame(handler1, relay.getSystemSubscriptions().get("/topic/unresolved-user-destination")); assertSame(handler2, relay.getSystemSubscriptions().get("/topic/simp-user-registry")); }
Example #10
Source File: WebSocketMessageBrokerConfigurationSupport.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Bean public WebSocketMessageBrokerStats webSocketMessageBrokerStats() { AbstractBrokerMessageHandler relayBean = stompBrokerRelayMessageHandler(); StompBrokerRelayMessageHandler brokerRelay = (relayBean instanceof StompBrokerRelayMessageHandler ? (StompBrokerRelayMessageHandler) relayBean : null); // Ensure STOMP endpoints are registered stompWebSocketHandlerMapping(); WebSocketMessageBrokerStats stats = new WebSocketMessageBrokerStats(); stats.setSubProtocolWebSocketHandler((SubProtocolWebSocketHandler) subProtocolWebSocketHandler()); stats.setStompBrokerRelay(brokerRelay); stats.setInboundChannelExecutor(clientInboundChannelExecutor()); stats.setOutboundChannelExecutor(clientOutboundChannelExecutor()); stats.setSockJsTaskScheduler(messageBrokerTaskScheduler()); return stats; }
Example #11
Source File: MessageBrokerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void registerWebSocketMessageBrokerStats(RootBeanDefinition broker, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, ParserContext context, Object source) { RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketMessageBrokerStats.class); RuntimeBeanReference webSocketHandler = new RuntimeBeanReference(WEB_SOCKET_HANDLER_BEAN_NAME); beanDef.getPropertyValues().add("subProtocolWebSocketHandler", webSocketHandler); if (StompBrokerRelayMessageHandler.class == broker.getBeanClass()) { beanDef.getPropertyValues().add("stompBrokerRelay", broker); } String name = inChannel.getBeanName() + "Executor"; if (context.getRegistry().containsBeanDefinition(name)) { beanDef.getPropertyValues().add("inboundChannelExecutor", context.getRegistry().getBeanDefinition(name)); } name = outChannel.getBeanName() + "Executor"; if (context.getRegistry().containsBeanDefinition(name)) { beanDef.getPropertyValues().add("outboundChannelExecutor", context.getRegistry().getBeanDefinition(name)); } name = SCHEDULER_BEAN_NAME; if (context.getRegistry().containsBeanDefinition(name)) { beanDef.getPropertyValues().add("sockJsTaskScheduler", context.getRegistry().getBeanDefinition(name)); } registerBeanDefByName("webSocketMessageBrokerStats", beanDef, context, source); }
Example #12
Source File: AbstractMessageBrokerConfiguration.java From spring-analysis-note with MIT License | 6 votes |
@Bean @Nullable public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler() { StompBrokerRelayMessageHandler handler = getBrokerRegistry().getStompBrokerRelay(brokerChannel()); if (handler == null) { return null; } Map<String, MessageHandler> subscriptions = new HashMap<>(4); String destination = getBrokerRegistry().getUserDestinationBroadcast(); if (destination != null) { subscriptions.put(destination, userDestinationMessageHandler()); } destination = getBrokerRegistry().getUserRegistryBroadcast(); if (destination != null) { subscriptions.put(destination, userRegistryMessageHandler()); } handler.setSystemSubscriptions(subscriptions); updateUserDestinationResolver(handler); return handler; }
Example #13
Source File: MessageBrokerConfigurationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void brokerChannelWithBrokerRelay() { ApplicationContext context = loadConfig(BrokerRelayConfig.class); TestChannel channel = context.getBean("brokerChannel", TestChannel.class); Set<MessageHandler> handlers = channel.getSubscribers(); assertEquals(2, handlers.size()); assertTrue(handlers.contains(context.getBean(UserDestinationMessageHandler.class))); assertTrue(handlers.contains(context.getBean(StompBrokerRelayMessageHandler.class))); }
Example #14
Source File: MessageBrokerConfigurationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void clientInboundChannelWithBrokerRelay() { TestChannel channel = this.brokerRelayContext.getBean("clientInboundChannel", TestChannel.class); Set<MessageHandler> handlers = channel.getSubscribers(); assertEquals(3, handlers.size()); assertTrue(handlers.contains(brokerRelayContext.getBean(SimpAnnotationMethodMessageHandler.class))); assertTrue(handlers.contains(brokerRelayContext.getBean(UserDestinationMessageHandler.class))); assertTrue(handlers.contains(brokerRelayContext.getBean(StompBrokerRelayMessageHandler.class))); }
Example #15
Source File: StompBrokerRelayRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void test() { SubscribableChannel inChannel = new StubMessageChannel(); MessageChannel outChannel = new StubMessageChannel(); String[] prefixes = new String[] { "/foo", "/bar" }; StompBrokerRelayRegistration registration = new StompBrokerRelayRegistration(inChannel, outChannel, prefixes); registration.setClientLogin("clientlogin"); registration.setClientPasscode("clientpasscode"); registration.setSystemLogin("syslogin"); registration.setSystemPasscode("syspasscode"); registration.setSystemHeartbeatReceiveInterval(123); registration.setSystemHeartbeatSendInterval(456); registration.setVirtualHost("example.org"); StompBrokerRelayMessageHandler handler = registration.getMessageHandler(new StubMessageChannel()); assertArrayEquals(prefixes, handler.getDestinationPrefixes().toArray(new String[2])); assertEquals("clientlogin", handler.getClientLogin()); assertEquals("clientpasscode", handler.getClientPasscode()); assertEquals("syslogin", handler.getSystemLogin()); assertEquals("syspasscode", handler.getSystemPasscode()); assertEquals(123, handler.getSystemHeartbeatReceiveInterval()); assertEquals(456, handler.getSystemHeartbeatSendInterval()); assertEquals("example.org", handler.getVirtualHost()); }
Example #16
Source File: StompBrokerRelayRegistration.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected StompBrokerRelayMessageHandler getMessageHandler(SubscribableChannel brokerChannel) { StompBrokerRelayMessageHandler handler = new StompBrokerRelayMessageHandler( getClientInboundChannel(), getClientOutboundChannel(), brokerChannel, getDestinationPrefixes()); handler.setRelayHost(this.relayHost); handler.setRelayPort(this.relayPort); handler.setClientLogin(this.clientLogin); handler.setClientPasscode(this.clientPasscode); handler.setSystemLogin(this.systemLogin); handler.setSystemPasscode(this.systemPasscode); if (this.systemHeartbeatSendInterval != null) { handler.setSystemHeartbeatSendInterval(this.systemHeartbeatSendInterval); } if (this.systemHeartbeatReceiveInterval != null) { handler.setSystemHeartbeatReceiveInterval(this.systemHeartbeatReceiveInterval); } if (this.virtualHost != null) { handler.setVirtualHost(this.virtualHost); } handler.setAutoStartup(this.autoStartup); return handler; }
Example #17
Source File: MessageBrokerConfigurationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void brokerChannelWithBrokerRelay() { TestChannel channel = this.brokerRelayContext.getBean("brokerChannel", TestChannel.class); Set<MessageHandler> handlers = channel.getSubscribers(); assertEquals(2, handlers.size()); assertTrue(handlers.contains(brokerRelayContext.getBean(UserDestinationMessageHandler.class))); assertTrue(handlers.contains(brokerRelayContext.getBean(StompBrokerRelayMessageHandler.class))); }
Example #18
Source File: MessageBrokerRegistry.java From spring-analysis-note with MIT License | 5 votes |
@Nullable protected StompBrokerRelayMessageHandler getStompBrokerRelay(SubscribableChannel brokerChannel) { if (this.brokerRelayRegistration != null) { StompBrokerRelayMessageHandler relay = this.brokerRelayRegistration.getMessageHandler(brokerChannel); relay.setPreservePublishOrder(this.preservePublishOrder); return relay; } return null; }
Example #19
Source File: MessageBrokerConfigurationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void clientInboundChannelWithBrokerRelay() { ApplicationContext context = loadConfig(BrokerRelayConfig.class); TestChannel channel = context.getBean("clientInboundChannel", TestChannel.class); Set<MessageHandler> handlers = channel.getSubscribers(); assertEquals(3, handlers.size()); assertTrue(handlers.contains(context.getBean(SimpAnnotationMethodMessageHandler.class))); assertTrue(handlers.contains(context.getBean(UserDestinationMessageHandler.class))); assertTrue(handlers.contains(context.getBean(StompBrokerRelayMessageHandler.class))); }
Example #20
Source File: StompBrokerRelayRegistrationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void test() { SubscribableChannel inChannel = new StubMessageChannel(); MessageChannel outChannel = new StubMessageChannel(); String[] prefixes = new String[] { "/foo", "/bar" }; StompBrokerRelayRegistration registration = new StompBrokerRelayRegistration(inChannel, outChannel, prefixes); registration.setClientLogin("clientlogin"); registration.setClientPasscode("clientpasscode"); registration.setSystemLogin("syslogin"); registration.setSystemPasscode("syspasscode"); registration.setSystemHeartbeatReceiveInterval(123); registration.setSystemHeartbeatSendInterval(456); registration.setVirtualHost("example.org"); StompBrokerRelayMessageHandler handler = registration.getMessageHandler(new StubMessageChannel()); assertArrayEquals(prefixes, StringUtils.toStringArray(handler.getDestinationPrefixes())); assertEquals("clientlogin", handler.getClientLogin()); assertEquals("clientpasscode", handler.getClientPasscode()); assertEquals("syslogin", handler.getSystemLogin()); assertEquals("syspasscode", handler.getSystemPasscode()); assertEquals(123, handler.getSystemHeartbeatReceiveInterval()); assertEquals(456, handler.getSystemHeartbeatSendInterval()); assertEquals("example.org", handler.getVirtualHost()); }
Example #21
Source File: StompBrokerRelayRegistration.java From java-technology-stack with MIT License | 5 votes |
protected StompBrokerRelayMessageHandler getMessageHandler(SubscribableChannel brokerChannel) { StompBrokerRelayMessageHandler handler = new StompBrokerRelayMessageHandler( getClientInboundChannel(), getClientOutboundChannel(), brokerChannel, getDestinationPrefixes()); handler.setRelayHost(this.relayHost); handler.setRelayPort(this.relayPort); handler.setClientLogin(this.clientLogin); handler.setClientPasscode(this.clientPasscode); handler.setSystemLogin(this.systemLogin); handler.setSystemPasscode(this.systemPasscode); if (this.systemHeartbeatSendInterval != null) { handler.setSystemHeartbeatSendInterval(this.systemHeartbeatSendInterval); } if (this.systemHeartbeatReceiveInterval != null) { handler.setSystemHeartbeatReceiveInterval(this.systemHeartbeatReceiveInterval); } if (this.virtualHost != null) { handler.setVirtualHost(this.virtualHost); } if (this.tcpClient != null) { handler.setTcpClient(this.tcpClient); } handler.setAutoStartup(this.autoStartup); return handler; }
Example #22
Source File: MessageBrokerRegistry.java From java-technology-stack with MIT License | 5 votes |
@Nullable protected StompBrokerRelayMessageHandler getStompBrokerRelay(SubscribableChannel brokerChannel) { if (this.brokerRelayRegistration != null) { StompBrokerRelayMessageHandler relay = this.brokerRelayRegistration.getMessageHandler(brokerChannel); relay.setPreservePublishOrder(this.preservePublishOrder); return relay; } return null; }
Example #23
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void brokerChannelWithBrokerRelay() { ApplicationContext context = loadConfig(BrokerRelayConfig.class); TestChannel channel = context.getBean("brokerChannel", TestChannel.class); Set<MessageHandler> handlers = channel.getSubscribers(); assertEquals(2, handlers.size()); assertTrue(handlers.contains(context.getBean(UserDestinationMessageHandler.class))); assertTrue(handlers.contains(context.getBean(StompBrokerRelayMessageHandler.class))); }
Example #24
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void clientInboundChannelWithBrokerRelay() { ApplicationContext context = loadConfig(BrokerRelayConfig.class); TestChannel channel = context.getBean("clientInboundChannel", TestChannel.class); Set<MessageHandler> handlers = channel.getSubscribers(); assertEquals(3, handlers.size()); assertTrue(handlers.contains(context.getBean(SimpAnnotationMethodMessageHandler.class))); assertTrue(handlers.contains(context.getBean(UserDestinationMessageHandler.class))); assertTrue(handlers.contains(context.getBean(StompBrokerRelayMessageHandler.class))); }
Example #25
Source File: StompBrokerRelayRegistrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void test() { SubscribableChannel inChannel = new StubMessageChannel(); MessageChannel outChannel = new StubMessageChannel(); String[] prefixes = new String[] { "/foo", "/bar" }; StompBrokerRelayRegistration registration = new StompBrokerRelayRegistration(inChannel, outChannel, prefixes); registration.setClientLogin("clientlogin"); registration.setClientPasscode("clientpasscode"); registration.setSystemLogin("syslogin"); registration.setSystemPasscode("syspasscode"); registration.setSystemHeartbeatReceiveInterval(123); registration.setSystemHeartbeatSendInterval(456); registration.setVirtualHost("example.org"); StompBrokerRelayMessageHandler handler = registration.getMessageHandler(new StubMessageChannel()); assertArrayEquals(prefixes, StringUtils.toStringArray(handler.getDestinationPrefixes())); assertEquals("clientlogin", handler.getClientLogin()); assertEquals("clientpasscode", handler.getClientPasscode()); assertEquals("syslogin", handler.getSystemLogin()); assertEquals("syspasscode", handler.getSystemPasscode()); assertEquals(123, handler.getSystemHeartbeatReceiveInterval()); assertEquals(456, handler.getSystemHeartbeatSendInterval()); assertEquals("example.org", handler.getVirtualHost()); }
Example #26
Source File: StompBrokerRelayRegistration.java From spring-analysis-note with MIT License | 5 votes |
protected StompBrokerRelayMessageHandler getMessageHandler(SubscribableChannel brokerChannel) { StompBrokerRelayMessageHandler handler = new StompBrokerRelayMessageHandler( getClientInboundChannel(), getClientOutboundChannel(), brokerChannel, getDestinationPrefixes()); handler.setRelayHost(this.relayHost); handler.setRelayPort(this.relayPort); handler.setClientLogin(this.clientLogin); handler.setClientPasscode(this.clientPasscode); handler.setSystemLogin(this.systemLogin); handler.setSystemPasscode(this.systemPasscode); if (this.systemHeartbeatSendInterval != null) { handler.setSystemHeartbeatSendInterval(this.systemHeartbeatSendInterval); } if (this.systemHeartbeatReceiveInterval != null) { handler.setSystemHeartbeatReceiveInterval(this.systemHeartbeatReceiveInterval); } if (this.virtualHost != null) { handler.setVirtualHost(this.virtualHost); } if (this.tcpClient != null) { handler.setTcpClient(this.tcpClient); } handler.setAutoStartup(this.autoStartup); return handler; }
Example #27
Source File: WebSocketMessageBrokerStats.java From java-technology-stack with MIT License | 4 votes |
public void setStompBrokerRelay(StompBrokerRelayMessageHandler stompBrokerRelay) { this.stompBrokerRelay = stompBrokerRelay; }
Example #28
Source File: MessageBrokerBeanDefinitionParserTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void stompBrokerRelay() { loadBeanDefinitions("websocket-config-broker-relay.xml"); HandlerMapping hm = this.appContext.getBean(HandlerMapping.class); assertNotNull(hm); assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class)); SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm; assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(1)); assertThat(suhm.getUrlMap().values(), Matchers.hasSize(1)); assertEquals(2, suhm.getOrder()); HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo/**"); assertNotNull(httpRequestHandler); assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class)); SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler; WebSocketHandler wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler()); assertNotNull(wsHandler); assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class)); assertNotNull(sockJsHttpRequestHandler.getSockJsService()); UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class); assertNotNull(userDestResolver); assertThat(userDestResolver, Matchers.instanceOf(DefaultUserDestinationResolver.class)); DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver; assertEquals("/user/", defaultUserDestResolver.getDestinationPrefix()); StompBrokerRelayMessageHandler messageBroker = this.appContext.getBean(StompBrokerRelayMessageHandler.class); assertNotNull(messageBroker); assertEquals("clientlogin", messageBroker.getClientLogin()); assertEquals("clientpass", messageBroker.getClientPasscode()); assertEquals("syslogin", messageBroker.getSystemLogin()); assertEquals("syspass", messageBroker.getSystemPasscode()); assertEquals("relayhost", messageBroker.getRelayHost()); assertEquals(1234, messageBroker.getRelayPort()); assertEquals("spring.io", messageBroker.getVirtualHost()); assertEquals(5000, messageBroker.getSystemHeartbeatReceiveInterval()); assertEquals(5000, messageBroker.getSystemHeartbeatSendInterval()); assertThat(messageBroker.getDestinationPrefixes(), Matchers.containsInAnyOrder("/topic","/queue")); assertTrue(messageBroker.isPreservePublishOrder()); 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); try { this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class); fail("expected exception"); } catch (NoSuchBeanDefinitionException ex) { // expected } String destination = "/topic/unresolved-user-destination"; UserDestinationMessageHandler userDestHandler = this.appContext.getBean(UserDestinationMessageHandler.class); assertEquals(destination, userDestHandler.getBroadcastDestination()); assertNotNull(messageBroker.getSystemSubscriptions()); assertSame(userDestHandler, messageBroker.getSystemSubscriptions().get(destination)); destination = "/topic/simp-user-registry"; UserRegistryMessageHandler userRegistryHandler = this.appContext.getBean(UserRegistryMessageHandler.class); assertEquals(destination, userRegistryHandler.getBroadcastDestination()); assertNotNull(messageBroker.getSystemSubscriptions()); assertSame(userRegistryHandler, messageBroker.getSystemSubscriptions().get(destination)); SimpUserRegistry userRegistry = this.appContext.getBean(SimpUserRegistry.class); assertEquals(MultiServerUserRegistry.class, userRegistry.getClass()); 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\\]"; assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected)); }
Example #29
Source File: MessageBrokerRegistry.java From spring4-understanding with Apache License 2.0 | 4 votes |
protected StompBrokerRelayMessageHandler getStompBrokerRelay(SubscribableChannel brokerChannel) { if (this.brokerRelayRegistration != null) { return this.brokerRelayRegistration.getMessageHandler(brokerChannel); } return null; }
Example #30
Source File: MessageBrokerBeanDefinitionParserTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void stompBrokerRelay() { loadBeanDefinitions("websocket-config-broker-relay.xml"); HandlerMapping hm = this.appContext.getBean(HandlerMapping.class); assertNotNull(hm); assertThat(hm, Matchers.instanceOf(SimpleUrlHandlerMapping.class)); SimpleUrlHandlerMapping suhm = (SimpleUrlHandlerMapping) hm; assertThat(suhm.getUrlMap().keySet(), Matchers.hasSize(1)); assertThat(suhm.getUrlMap().values(), Matchers.hasSize(1)); assertEquals(2, suhm.getOrder()); HttpRequestHandler httpRequestHandler = (HttpRequestHandler) suhm.getUrlMap().get("/foo/**"); assertNotNull(httpRequestHandler); assertThat(httpRequestHandler, Matchers.instanceOf(SockJsHttpRequestHandler.class)); SockJsHttpRequestHandler sockJsHttpRequestHandler = (SockJsHttpRequestHandler) httpRequestHandler; WebSocketHandler wsHandler = unwrapWebSocketHandler(sockJsHttpRequestHandler.getWebSocketHandler()); assertNotNull(wsHandler); assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class)); assertNotNull(sockJsHttpRequestHandler.getSockJsService()); UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class); assertNotNull(userDestResolver); assertThat(userDestResolver, Matchers.instanceOf(DefaultUserDestinationResolver.class)); DefaultUserDestinationResolver defaultUserDestResolver = (DefaultUserDestinationResolver) userDestResolver; assertEquals("/user/", defaultUserDestResolver.getDestinationPrefix()); StompBrokerRelayMessageHandler messageBroker = this.appContext.getBean(StompBrokerRelayMessageHandler.class); assertNotNull(messageBroker); assertEquals("clientlogin", messageBroker.getClientLogin()); assertEquals("clientpass", messageBroker.getClientPasscode()); assertEquals("syslogin", messageBroker.getSystemLogin()); assertEquals("syspass", messageBroker.getSystemPasscode()); assertEquals("relayhost", messageBroker.getRelayHost()); assertEquals(1234, messageBroker.getRelayPort()); assertEquals("spring.io", messageBroker.getVirtualHost()); assertEquals(5000, messageBroker.getSystemHeartbeatReceiveInterval()); assertEquals(5000, messageBroker.getSystemHeartbeatSendInterval()); assertThat(messageBroker.getDestinationPrefixes(), Matchers.containsInAnyOrder("/topic","/queue")); assertTrue(messageBroker.isPreservePublishOrder()); 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); try { this.appContext.getBean("brokerChannelExecutor", ThreadPoolTaskExecutor.class); fail("expected exception"); } catch (NoSuchBeanDefinitionException ex) { // expected } String destination = "/topic/unresolved-user-destination"; UserDestinationMessageHandler userDestHandler = this.appContext.getBean(UserDestinationMessageHandler.class); assertEquals(destination, userDestHandler.getBroadcastDestination()); assertNotNull(messageBroker.getSystemSubscriptions()); assertSame(userDestHandler, messageBroker.getSystemSubscriptions().get(destination)); destination = "/topic/simp-user-registry"; UserRegistryMessageHandler userRegistryHandler = this.appContext.getBean(UserRegistryMessageHandler.class); assertEquals(destination, userRegistryHandler.getBroadcastDestination()); assertNotNull(messageBroker.getSystemSubscriptions()); assertSame(userRegistryHandler, messageBroker.getSystemSubscriptions().get(destination)); SimpUserRegistry userRegistry = this.appContext.getBean(SimpUserRegistry.class); assertEquals(MultiServerUserRegistry.class, userRegistry.getClass()); 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\\]"; assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected)); }