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
}

你可能感兴趣的:(Spring Boot 自定义通道报[is not a valid topic destination]问题解决)