gpt4 book ai didi

java - Spring Websocket STOMP : send RECEIPT frames

转载 作者:搜寻专家 更新时间:2023-11-01 01:49:28 28 4
gpt4 key购买 nike

我有一个基于 Spring 及其 SimpleBroker 实现的 Websocket-stomp 服务器(不使用外部代理)。

我想启用 STOMP RECEIPT 消息。

我如何配置我的代码以自动发送这些?

最佳答案

在 STOMP 协议(protocol)的 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

关于java - Spring Websocket STOMP : send RECEIPT frames,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46193012/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com