Java Code Examples for org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler#handleMessage()
The following examples show how to use
org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler#handleMessage() .
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 spring-analysis-note with MIT License | 5 votes |
@Test public void clientOutboundChannelUsedBySimpleBroker() { ApplicationContext context = loadConfig(SimpleBrokerConfig.class); TestChannel outboundChannel = context.getBean("clientOutboundChannel", TestChannel.class); SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE); headers.setSessionId("sess1"); headers.setSubscriptionId("subs1"); headers.setDestination("/foo"); Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()); // subscribe broker.handleMessage(createConnectMessage("sess1", new long[] {0,0})); broker.handleMessage(message); headers = StompHeaderAccessor.create(StompCommand.SEND); headers.setSessionId("sess1"); headers.setDestination("/foo"); message = MessageBuilder.createMessage("bar".getBytes(), headers.getMessageHeaders()); // message broker.handleMessage(message); message = outboundChannel.messages.get(1); headers = StompHeaderAccessor.wrap(message); assertEquals(SimpMessageType.MESSAGE, headers.getMessageType()); assertEquals("/foo", headers.getDestination()); assertEquals("bar", new String((byte[]) message.getPayload())); }
Example 2
Source File: MessageBrokerConfigurationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void clientOutboundChannelUsedBySimpleBroker() { ApplicationContext context = loadConfig(SimpleBrokerConfig.class); TestChannel outboundChannel = context.getBean("clientOutboundChannel", TestChannel.class); SimpleBrokerMessageHandler broker = context.getBean(SimpleBrokerMessageHandler.class); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE); headers.setSessionId("sess1"); headers.setSubscriptionId("subs1"); headers.setDestination("/foo"); Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()); // subscribe broker.handleMessage(createConnectMessage("sess1", new long[] {0,0})); broker.handleMessage(message); headers = StompHeaderAccessor.create(StompCommand.SEND); headers.setSessionId("sess1"); headers.setDestination("/foo"); message = MessageBuilder.createMessage("bar".getBytes(), headers.getMessageHeaders()); // message broker.handleMessage(message); message = outboundChannel.messages.get(1); headers = StompHeaderAccessor.wrap(message); assertEquals(SimpMessageType.MESSAGE, headers.getMessageType()); assertEquals("/foo", headers.getDestination()); assertEquals("bar", new String((byte[]) message.getPayload())); }
Example 3
Source File: MessageBrokerConfigurationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void clientOutboundChannelUsedBySimpleBroker() { TestChannel channel = this.simpleBrokerContext.getBean("clientOutboundChannel", TestChannel.class); SimpleBrokerMessageHandler broker = this.simpleBrokerContext.getBean(SimpleBrokerMessageHandler.class); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE); headers.setSessionId("sess1"); headers.setSubscriptionId("subs1"); headers.setDestination("/foo"); Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()); // subscribe broker.handleMessage(message); headers = StompHeaderAccessor.create(StompCommand.SEND); headers.setSessionId("sess1"); headers.setDestination("/foo"); message = MessageBuilder.createMessage("bar".getBytes(), headers.getMessageHeaders()); // message broker.handleMessage(message); message = channel.messages.get(0); headers = StompHeaderAccessor.wrap(message); assertEquals(SimpMessageType.MESSAGE, headers.getMessageType()); assertEquals("/foo", headers.getDestination()); assertEquals("bar", new String((byte[]) message.getPayload())); }