将Spring Websocket添加到服务时未使用Spring Cloud Stream的自定义MessageConverter

问题描述 投票:0回答:1

我有一个Scs微服务,它使用来自一系列Kafka主题的消息,这些主题都共享相同的抽象类。

我已经注册了一个自定义MessageConverter,以反序列化使用此抽象类的JSON消息。

我想通过网络套接字将我从Kafka收到的这些消息推送到前端UI。一旦添加了websocket代理的配置,便不再使用MessageConverter for Scs。看来注册用于websocket的MessageConverters优先于我注册用于Scs的MessageConverters。

我在https://github.com/jarebudev/scs-websocket-messageconverter-demo处创建了一个缩减示例以演示该问题-请参阅提供的单元测试。

spring-cloud-stream spring-websocket
1个回答
0
投票
Spring Websocket的自动配置正在干扰Spring Cloud Stream的MessageConverter

已修复,请参见https://github.com/spring-cloud/spring-cloud-stream/commit/eee1b1385c2864a32370a8e4758294d5efbe4cd5

同时,我通过在Spring Websocket之前应用我的Spring Cloud Stream配置(包含自定义@BeanMessageConverter)来解决此问题。

就我而言,我的两个配置类都在同一包中。

之前:

com.example.demo.config AppWebsocketConfig ScsConfig

之后:

com.example.demo.config

  ScsConfig
  WebsocketConfig
© www.soinside.com 2019 - 2024. All rights reserved.