Spring Boot 在集成RabbitMQ時(shí),在自定義通道時(shí)如使用以下代碼
@MessageMapping("/chat/{id}")
@SendTo("/topic/chat/{id}")
public Message createMesage(@DestinationVariable String id){
//do something
}
以上代碼在執(zhí)行時(shí)會(huì)報(bào)以下錯(cuò)誤.
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
RabbitMQ 不支持"/"分隔符,可以變通以下,使用如下形式解決以上的問(wèn)題
@MessageMapping("/chat.{id}")
@SendTo("/topic/chat.{id}")
public Message createMesage(@DestinationVariable String id){
//do something
}