2
votes

I have three project:

  1. Javascript SockJS STOMP client

  2. Spring-boot STOMP endpoint and AMQP

  3. Spring-boot AMQP (RabbitListener) client for testing

    I am using RabbitMQ message broker (+Stomp plugin) and configured amqp and stomp endpoint normally..When I send message to queue with RabbitTemplate and third project (spring-boot amqp client for testing) normally subscribed this message , everything works fine !! But Javascript STOMP client didn't received this message.. P.S. When I send message with SimpMessagingTemplate , JS client receives message fine !

Javascript SockJS STOMP Client

        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-boot STOMP endpoint and 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-boot amqp client for testing

@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);
    }
}

How I can mix amqp and stomp protocols in RabbitMQ ? I want to send message from another project with amqp protocol (RabbitTemplate) and receive this message from JS STOMP client (SockJS) .. Thanks.

1
Are you sure that you have somewhere an enableStompBrokerRelay() in your application configurations: docs.spring.io/spring/docs/5.0.7.RELEASE/…?Artem Bilan
of course.. I implemented RabbitMQ with enableStompBrokerRelay . (host,port,username,password)Seymur Asadov
Any chances that you can share with us some simple project on GitHub to let us to play with it and reproduce what you are worry about? Would be also great to have some README there with an instruction what to do to reproduce.Artem Bilan
Please, try also to figure out what you are missing when you mix AMQP and STOMP protocols: rabbitmq.com/stomp.html. Especially pay attention to the For SEND frames, the message is sent to the amq.topic exchange with the routing key <name>. . So, your rabbitTemplate.convertAndSend("/topic/testqueue", ...) doesn't sound right.Artem Bilan
Thanks Artem , I was changed rabbitTemplate.convertAndSend("/topic/testqueue", ...) to rabbitTemplate.convertAndSend("amqp.topic","testqueue" ...) and everythink works fine )))Seymur Asadov

1 Answers

0
votes

I was changed rabbitTemplate.convertAndSend("/topic/testqueue", ...) to rabbitTemplate.convertAndSend("amq.topic","testqueue" ...) and everythink works fine ))) Especially thanks to Artem Bilan for support. Good Luck