Java Spring 践踏 AMQP

Java Spring Stomp AMQP

我有三个项目:

  1. Javascript SockJS STOMP 客户端

  2. Spring-启动STOMP端点和AMQP

  3. Spring-启动 AMQP (RabbitListener) 客户端进行测试

    我正在使用 RabbitMQ 消息代理(+Stomp 插件)并配置了 amqp stomp endpoint normally..When I send message to queue with RabbitTemplate and third project (spring-boot amqp client for testing) 正常订阅了这条消息,一切正常!!但是 Javascript STOMP 客户端没有收到这条消息.. P.S。当我使用 SimpMessagingTemplate 发送消息时,JS 客户端可以正常接收消息!

Javascript SockJS STOMP 客户端

        var socket = new SockJS('http://localhost:8090/hello');
        stompClient = Stomp.over(socket);
        stompClient.connect('guest','guest', function(frame) {
            setConnected(true);
            console.log('Connected: ' + frame);
            stompClient.subscribe('/topic/testqueue', function(greeting){
                showGreeting(JSON.parse(greeting.body).content);
            });
        });

spring-启动STOMP端点和AMQP

    @Controller
    public class SampleController {
        Logger logger = Logger.getLogger(SampleController.class);
    
        @Autowired
        private RabbitTemplate rabbitTemplate;
    
        private SimpMessagingTemplate messagingTemplate;
    
        @Autowired
        public SampleController(SimpMessagingTemplate messagingTemplate) {
            this.messagingTemplate = messagingTemplate;
        }
    
        @GetMapping("/emit/{message}")
        @ResponseBody
        String queue1(@PathVariable("message") String message) throws Exception {
            logger.info("Emit to testqueue");
            rabbitTemplate.convertAndSend("/topic/testqueue", new Greeting("Salam olsun " + message));
            Thread.sleep(60000); // simulated delay
            return "Emit to testqueue";
        }
}

spring-启动amqp客户端进行测试

@Component
public class RabbitMqListener {
    Logger logger = Logger.getLogger(RabbitMqListener.class);

    @RabbitListener(queues = "/topic/testqueue")
    public void processQueue1(String message) {
        logger.info("Received from queue : " + message);
    }
}

如何在 RabbitMQ 中混合使用 amqp 和 stomp 协议?我想使用 amqp 协议 (RabbitTemplate) 从另一个项目发送消息,并从 JS STOMP 客户端 (SockJS) 接收此消息。谢谢。

我被更改为 rabbitTemplate.convertAndSend("/topic/testqueue", ...)rabbitTemplate.convertAndSend("amq.topic","testqueue" ...) 一切都很好)))特别感谢 Artem Bilan 的支持。祝你好运