@Bean public UserDestinationMessageHandler userDestinationMessageHandler() { UserDestinationMessageHandler handler = new UserDestinationMessageHandler(clientInboundChannel(), brokerChannel(), userDestinationResolver()); String destination = getBrokerRegistry().getUserDestinationBroadcast(); if (destination != null) { handler.setBroadcastDestination(destination); } return handler; }
@Test public void handleMessageWithoutActiveSession() { this.handler.setBroadcastDestination("/topic/unresolved"); given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", "/user/joe/queue/foo")); ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class); Mockito.verify(this.brokerChannel).send(captor.capture()); Message message = captor.getValue(); SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(message); assertEquals("/topic/unresolved", accessor.getDestination()); assertEquals("/user/joe/queue/foo", accessor.getFirstNativeHeader(ORIGINAL_DESTINATION)); // Should ignore our own broadcast to brokerChannel this.handler.handleMessage(message); Mockito.verifyNoMoreInteractions(this.brokerChannel); }
@Test public void handleMessageFromBrokerWithoutActiveSession() { this.handler.setBroadcastDestination("/topic/unresolved"); given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.MESSAGE); accessor.setSessionId("system123"); accessor.setDestination("/topic/unresolved"); accessor.setNativeHeader(ORIGINAL_DESTINATION, "/user/joe/queue/foo"); accessor.setLeaveMutable(true); byte[] payload = "payload".getBytes(StandardCharsets.UTF_8); this.handler.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders())); // No re-broadcast verifyNoMoreInteractions(this.brokerChannel); }
@Test public void handleMessageFromBrokerWithActiveSession() { TestSimpUser simpUser = new TestSimpUser("joe"); simpUser.addSessions(new TestSimpSession("123")); when(this.registry.getUser("joe")).thenReturn(simpUser); this.handler.setBroadcastDestination("/topic/unresolved"); given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.MESSAGE); accessor.setSessionId("system123"); accessor.setDestination("/topic/unresolved"); accessor.setNativeHeader(ORIGINAL_DESTINATION, "/user/joe/queue/foo"); accessor.setNativeHeader("customHeader", "customHeaderValue"); accessor.setLeaveMutable(true); byte[] payload = "payload".getBytes(StandardCharsets.UTF_8); this.handler.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders())); ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class); Mockito.verify(this.brokerChannel).send(captor.capture()); assertNotNull(captor.getValue()); SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(captor.getValue()); assertEquals("/queue/foo-user123", headers.getDestination()); assertEquals("/user/queue/foo", headers.getFirstNativeHeader(ORIGINAL_DESTINATION)); assertEquals("customHeaderValue", headers.getFirstNativeHeader("customHeader")); assertArrayEquals(payload, (byte[]) captor.getValue().getPayload()); }
@Bean public UserDestinationMessageHandler userDestinationMessageHandler() { UserDestinationMessageHandler handler = new UserDestinationMessageHandler(clientInboundChannel(), brokerChannel(), userDestinationResolver()); String destination = getBrokerRegistry().getUserDestinationBroadcast(); if (destination != null) { handler.setBroadcastDestination(destination); } return handler; }
@Bean public UserDestinationMessageHandler userDestinationMessageHandler() { UserDestinationMessageHandler handler = new UserDestinationMessageHandler(clientInboundChannel(), brokerChannel(), userDestinationResolver()); String destination = getBrokerRegistry().getUserDestinationBroadcast(); if (destination != null) { handler.setBroadcastDestination(destination); } return handler; }
@Bean public UserDestinationMessageHandler userDestinationMessageHandler() { UserDestinationMessageHandler handler = new UserDestinationMessageHandler(clientInboundChannel(), brokerChannel(), userDestinationResolver()); String destination = getBrokerRegistry().getUserDestinationBroadcast(); if (destination != null) { handler.setBroadcastDestination(destination); } return handler; }