本文介绍了Spring Websocket STOMP:发送 RECEIPT 帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基于 Spring 的 Websocket-stomp 服务器及其 SimpleBroker 实现(不使用外部代理).
I have a Websocket-stomp server based on Spring and its SimpleBroker implementation (not utilizing an external broker).
我想启用 STOMP RECEIPT 消息.
I would like to enable STOMP RECEIPT messages.
如何配置我的代码以自动发送这些?
How I could configure my code to send these automatically?
推荐答案
在 STOMP 协议的 Spring 集成测试中,我们有以下代码:
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()));
}
};
}
这篇关于Spring Websocket STOMP:发送 RECEIPT 帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!