我有一个基于Spring的Websocket-stomp服务器及其SimpleBroker实现(不使用外部代理)。
我想启用STOMP RECEIPT消息。
我如何配置我的代码自动发送这些?
I have a Websocket-stomp server based on Spring and its SimpleBroker implementation (not utilizing an external broker).
I would like to enable STOMP RECEIPT messages.
How I could configure my code to send these automatically?
最满意答案
在针对STOMP协议的Spring Integration测试中,我们有以下代码:
//SimpleBrokerMessageHandler doesn't support RECEIPT frame, hence we emulate it this way @Bean public ApplicationListener<SessionSubscribeEvent> webSocketEventListener( final AbstractSubscribableChannel clientOutboundChannel) { return event -> { Message<byte[]> message = event.getMessage(); StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message); if (stompHeaderAccessor.getReceipt() != null) { stompHeaderAccessor.setHeader("stompCommand", StompCommand.RECEIPT); stompHeaderAccessor.setReceiptId(stompHeaderAccessor.getReceipt()); clientOutboundChannel.send( MessageBuilder.createMessage(new byte[0], stompHeaderAccessor.getMessageHeaders())); } }; }https://github.com/spring-projects/spring-integration/blob/master/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java
In Spring Integration test for the STOMP protocol we have this code:
//SimpleBrokerMessageHandler doesn't support RECEIPT frame, hence we emulate it this way @Bean public ApplicationListener<SessionSubscribeEvent> webSocketEventListener( final AbstractSubscribableChannel clientOutboundChannel) { return event -> { Message<byte[]> message = event.getMessage(); StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message); if (stompHeaderAccessor.getReceipt() != null) { stompHeaderAccessor.setHeader("stompCommand", StompCommand.RECEIPT); stompHeaderAccessor.setReceiptId(stompHeaderAccessor.getReceipt()); clientOutboundChannel.send( MessageBuilder.createMessage(new byte[0], stompHeaderAccessor.getMessageHeaders())); } }; }https://github.com/spring-projects/spring-integration/blob/master/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java
更多推荐
发布评论