I have three project:
Javascript SockJS STOMP client
Spring-boot STOMP endpoint and AMQP
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.
enableStompBrokerRelay()
in your application configurations: docs.spring.io/spring/docs/5.0.7.RELEASE/…? – Artem BilanFor SEND frames, the message is sent to the amq.topic exchange with the routing key <name>.
. So, yourrabbitTemplate.convertAndSend("/topic/testqueue", ...)
doesn't sound right. – Artem Bilan