Java 从Spring Websocket程序发送STOMP错误

Java 从Spring Websocket程序发送STOMP错误,java,spring,spring-websocket,spring-messaging,Java,Spring,Spring Websocket,Spring Messaging,我有一个springwebsocketstomp应用程序,它接受订阅请求 在应用程序中,我有一个SUBSCRIBE处理程序,即 @Component public class SubscribeStompEventHandler implements ApplicationListener<SessionSubscribeEvent> { @Override public void onApplicationEvent(SessionSubscribeEvent

我有一个springwebsocketstomp应用程序,它接受订阅请求

在应用程序中,我有一个SUBSCRIBE处理程序,即

 @Component
 public class SubscribeStompEventHandler implements ApplicationListener<SessionSubscribeEvent> {

    @Override
    public void onApplicationEvent(SessionSubscribeEvent event) {}
 }
我试着把topic变成一些subsection topic和/队列/错误topic。然而,我并没有看到消息传播到客户端

在客户端中,我使用:

      stompClient.connect(headers
                , function (frame) {
                    console.log("Conn OK " + url);               
                }, function (error) {                       
                    console.log("Conn NOT OK " + url + ": " + JSON.stringify(error));
                });
        }
我的目标是在发送STOMP error时调用函数(error)


请告知我如何准确发送正确的跺脚错误,例如通过跳出通道

您可以发送如下信息:

StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.ERROR);
headerAccessor.setMessage(error.getMessage());
headerAccessor.setSessionId(sessionId);
this.clientOutboundChannel.send(MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders()));
以下内容仅足以插入
clientOutboundChannel

 @Autowired
 @Qualifier("clientOutboundChannel")
 private MessageChannel clientOutboundChannel;
仅仅因为
clientOutboundChannel
bean是在
AbstractMessageBrokerConfiguration
中声明的

更新

STOMP错误总是关闭连接吗?我得到了这个效果。代码1002

是的。请参见
stompsubtocolhandler.sendToClient()


Artem,你能澄清一下吗:STOMP错误总是关闭连接?我得到了这个效果。代码1002。请参阅并更新我的答案。StompClient如何接收错误消息?任何特殊配置?由于
StompCommand.ERROR
始终关闭连接,因此我们没有选择权将错误作为常规
StompCommand.MESSAGE
@ArtemBilan发送到客户端。您知道使用SpringBoot正确发送错误帧并等待一段时间,直到客户端能够处理错误帧的任何替代方法吗?
 @Autowired
 @Qualifier("clientOutboundChannel")
 private MessageChannel clientOutboundChannel;
       if (StompCommand.ERROR.equals(command)) {
            try {
                session.close(CloseStatus.PROTOCOL_ERROR);
            }
            catch (IOException ex) {
                // Ignore
            }
        }