org.springframework.messaging.simp.user.SimpUserRegistry Java Examples
The following examples show how to use
org.springframework.messaging.simp.user.SimpUserRegistry.
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: 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 #2
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 #3
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 #4
Source File: AbstractMessageBrokerConfiguration.java From spring-analysis-note with MIT License | 5 votes |
@Bean @SuppressWarnings("deprecation") public SimpUserRegistry userRegistry() { SimpUserRegistry registry = createLocalUserRegistry(); if (registry == null) { registry = createLocalUserRegistry(getBrokerRegistry().getUserRegistryOrder()); } boolean broadcast = getBrokerRegistry().getUserRegistryBroadcast() != null; return (broadcast ? new MultiServerUserRegistry(registry) : registry); }
Example #5
Source File: WebSocketMessageBrokerConfigurationSupport.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("deprecation") protected SimpUserRegistry createLocalUserRegistry() { org.springframework.messaging.simp.user.UserSessionRegistry sessionRegistry = userSessionRegistry(); if (sessionRegistry != null) { return new UserSessionRegistryAdapter(sessionRegistry); } return new DefaultSimpUserRegistry(); }
Example #6
Source File: MessageBrokerConfigurationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void userBroadcastsDisabledWithSimpleBroker() throws Exception { SimpUserRegistry registry = this.simpleBrokerContext.getBean(SimpUserRegistry.class); assertNotNull(registry); assertNotEquals(MultiServerUserRegistry.class, registry.getClass()); UserDestinationMessageHandler handler = this.simpleBrokerContext.getBean(UserDestinationMessageHandler.class); assertNull(handler.getBroadcastDestination()); String name = "userRegistryMessageHandler"; MessageHandler messageHandler = this.simpleBrokerContext.getBean(name, MessageHandler.class); assertNotEquals(UserRegistryMessageHandler.class, messageHandler.getClass()); }
Example #7
Source File: WebSocketMessageBrokerConfigurationSupport.java From java-technology-stack with MIT License | 5 votes |
@Override protected SimpUserRegistry createLocalUserRegistry(@Nullable Integer order) { DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry(); if (order != null) { registry.setOrder(order); } return registry; }
Example #8
Source File: MessageBrokerConfigurationTests.java From java-technology-stack with MIT License | 5 votes |
@Override protected SimpUserRegistry createLocalUserRegistry(@Nullable Integer order) { TestUserRegistry registry = new TestUserRegistry(); if (order != null) { registry.setOrder(order); } return registry; }
Example #9
Source File: MessageBrokerConfigurationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void userBroadcastsDisabledWithSimpleBroker() { ApplicationContext context = loadConfig(SimpleBrokerConfig.class); SimpUserRegistry registry = context.getBean(SimpUserRegistry.class); assertNotNull(registry); assertNotEquals(MultiServerUserRegistry.class, registry.getClass()); UserDestinationMessageHandler handler = context.getBean(UserDestinationMessageHandler.class); assertNull(handler.getBroadcastDestination()); Object nullBean = context.getBean("userRegistryMessageHandler"); assertTrue(nullBean.equals(null)); }
Example #10
Source File: MessageBrokerConfigurationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customUserRegistryOrder() { ApplicationContext context = loadConfig(CustomConfig.class); SimpUserRegistry registry = context.getBean(SimpUserRegistry.class); assertTrue(registry instanceof TestUserRegistry); assertEquals(99, ((TestUserRegistry) registry).getOrder()); }
Example #11
Source File: AbstractMessageBrokerConfiguration.java From java-technology-stack with MIT License | 5 votes |
@Bean @SuppressWarnings("deprecation") public SimpUserRegistry userRegistry() { SimpUserRegistry registry = createLocalUserRegistry(); if (registry == null) { registry = createLocalUserRegistry(getBrokerRegistry().getUserRegistryOrder()); } boolean broadcast = getBrokerRegistry().getUserRegistryBroadcast() != null; return (broadcast ? new MultiServerUserRegistry(registry) : registry); }
Example #12
Source File: AbstractMessageBrokerConfiguration.java From spring-analysis-note with MIT License | 5 votes |
@Bean @Nullable public MessageHandler userRegistryMessageHandler() { if (getBrokerRegistry().getUserRegistryBroadcast() == null) { return null; } SimpUserRegistry userRegistry = userRegistry(); Assert.isInstanceOf(MultiServerUserRegistry.class, userRegistry, "MultiServerUserRegistry required"); return new UserRegistryMessageHandler((MultiServerUserRegistry) userRegistry, brokerMessagingTemplate(), getBrokerRegistry().getUserRegistryBroadcast(), messageBrokerTaskScheduler()); }
Example #13
Source File: WebSocketMessageBrokerConfigurationSupport.java From spring-analysis-note with MIT License | 5 votes |
@Override protected SimpUserRegistry createLocalUserRegistry(@Nullable Integer order) { DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry(); if (order != null) { registry.setOrder(order); } return registry; }
Example #14
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 5 votes |
@Override protected SimpUserRegistry createLocalUserRegistry(@Nullable Integer order) { TestUserRegistry registry = new TestUserRegistry(); if (order != null) { registry.setOrder(order); } return registry; }
Example #15
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void userBroadcastsDisabledWithSimpleBroker() { ApplicationContext context = loadConfig(SimpleBrokerConfig.class); SimpUserRegistry registry = context.getBean(SimpUserRegistry.class); assertNotNull(registry); assertNotEquals(MultiServerUserRegistry.class, registry.getClass()); UserDestinationMessageHandler handler = context.getBean(UserDestinationMessageHandler.class); assertNull(handler.getBroadcastDestination()); Object nullBean = context.getBean("userRegistryMessageHandler"); assertTrue(nullBean.equals(null)); }
Example #16
Source File: MessageBrokerConfigurationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void customUserRegistryOrder() { ApplicationContext context = loadConfig(CustomConfig.class); SimpUserRegistry registry = context.getBean(SimpUserRegistry.class); assertTrue(registry instanceof TestUserRegistry); assertEquals(99, ((TestUserRegistry) registry).getOrder()); }
Example #17
Source File: AbstractMessageBrokerConfiguration.java From java-technology-stack with MIT License | 5 votes |
@Bean @Nullable public MessageHandler userRegistryMessageHandler() { if (getBrokerRegistry().getUserRegistryBroadcast() == null) { return null; } SimpUserRegistry userRegistry = userRegistry(); Assert.isInstanceOf(MultiServerUserRegistry.class, userRegistry, "MultiServerUserRegistry required"); return new UserRegistryMessageHandler((MultiServerUserRegistry) userRegistry, brokerMessagingTemplate(), getBrokerRegistry().getUserRegistryBroadcast(), messageBrokerTaskScheduler()); }
Example #18
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 #19
Source File: MessageBrokerBeanDefinitionParserTests.java From spring4-understanding with Apache License 2.0 | 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")); List<Class<? extends MessageHandler>> subscriberTypes = Arrays.<Class<? extends MessageHandler>>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, 1); testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60); subscriberTypes = Arrays.<Class<? extends MessageHandler>>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\\], " + "outboundChannelpool 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 #20
Source File: MessageBrokerConfigurationTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override protected SimpUserRegistry createLocalUserRegistry() { return mock(SimpUserRegistry.class); }
Example #21
Source File: AbstractMessageBrokerConfiguration.java From spring-analysis-note with MIT License | 4 votes |
/** * Create the user registry that provides access to local users. * @deprecated as of 5.1 in favor of {@link #createLocalUserRegistry(Integer)} */ @Deprecated @Nullable protected SimpUserRegistry createLocalUserRegistry() { return null; }
Example #22
Source File: AbstractMessageBrokerConfiguration.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Bean public SimpUserRegistry userRegistry() { return (getBrokerRegistry().getUserRegistryBroadcast() != null ? new MultiServerUserRegistry(createLocalUserRegistry()) : createLocalUserRegistry()); }
Example #23
Source File: WebsocketConfig.java From spring-boot-protocol with Apache License 2.0 | 4 votes |
/** * 负责管理用户信息 * @return */ @Bean @ConditionalOnMissingBean(SimpUserRegistry.class) public SimpUserRegistry userRegistry() { return new DefaultSimpUserRegistry(); }
Example #24
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)); }
Example #25
Source File: AbstractMessageBrokerConfiguration.java From java-technology-stack with MIT License | 4 votes |
/** * Create the user registry that provides access to local users. * @deprecated as of 5.1 in favor of {@link #createLocalUserRegistry(Integer)} */ @Deprecated @Nullable protected SimpUserRegistry createLocalUserRegistry() { return null; }
Example #26
Source File: AbstractMessageBrokerConfiguration.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Create the user registry that provides access to the local users. */ protected abstract SimpUserRegistry createLocalUserRegistry();
Example #27
Source File: AbstractMessageBrokerConfiguration.java From spring-analysis-note with MIT License | 2 votes |
/** * Create the user registry that provides access to local users. * @param order the order to use as a {@link SmartApplicationListener}. * @since 5.1 */ protected abstract SimpUserRegistry createLocalUserRegistry(@Nullable Integer order);
Example #28
Source File: AbstractMessageBrokerConfiguration.java From java-technology-stack with MIT License | 2 votes |
/** * Create the user registry that provides access to local users. * @param order the order to use as a {@link SmartApplicationListener}. * @since 5.1 */ protected abstract SimpUserRegistry createLocalUserRegistry(@Nullable Integer order);