Spring Boot 自定义通道报[is not a valid topic destination]问题解决

Spring Boot 在集成RabbitMQ时,在自定义通道时如使用以下代码

@MessageMapping("/chat/{id}")
@SendTo("/topic/chat/{id}")
public Message createMesage(@DestinationVariable String id){
    //do something
}

以上代码在执行时会报以下错误.
ERROR 14958 --- [eactor-tcp-io-3] o.s.m.s.s.StompBrokerRelayMessageHandler : Received ERROR {message=[Invalid destination], content-type=[text/plain], version=[1.0,1.1,1.2], content-length=[48]} session=uxmho5lj text/plain payload='/chat/*' is not a valid topic destination

你可参考这里
Stomp client fails to connect to a dynamic controller destination that has a @DestinationVariable when I switch to use a StompBrokerRelay but it works with SimpleBroker

RabbitMQ 不支持"/"分隔符,可以变通以下,使用如下形式解决以上的问题

@MessageMapping("/chat.{id}")
@SendTo("/topic/chat.{id}")
public Message createMesage(@DestinationVariable String id){
    //do something
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,438评论 0 10
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,908评论 18 139
  • https://mp.weixin.qq.com/s/aW86woiQczKDq0xY2RPA6g 痛是成长的一部...
    龚金发阅读 215评论 0 0
  • 1 什么是幸福的婚姻? 幸福的婚姻,是爸爸爱妈妈,妈妈也爱爸爸。 温暖亲密的关系是美好生活的最重要开场,会让孩子受...
    简儿的十年阅读 824评论 4 20
  • 当接到田田姐的电话时,没有很吃惊,因为随时沟通已经是我们的约定了。但她总是会很细心的问我,下班了吗,有没有打扰工作...
    海鸥ing阅读 278评论 0 1