Search code examples
spring-jmsspring-websocket

websocket and ActiveMQ


I have a program that send messages using JmsTemplate as below

@Override
    public void send(SonusCDR cdr) {
        jmsTemplate.setPubSubDomain(true);
        jmsTemplate.convertAndSend("cdrserver/calls/" + cdr.getIncomingCallingNumber() , new BaseCDRMessage(cdr));
    }

on another web site (hosting inside tomcat) i am trying to receive the message directly through STOMP

@Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableStompBrokerRelay("/topic", "/queue")
                .setRelayHost("192.168.70.149")
                .setRelayPort(61613);
        config.setApplicationDestinationPrefixes("panel");

    }

now when i try to connect from HTML to /topic/cdrserver/calls/121 , i do receive the message but with empty body

I think the problem is that message is not serialized before being sent to ActiveMQ . What is the best way to overcome this ?


Solution

  • This is what i have done to fix the serialization issue but i am not sure it is the recommended way , may be serializing the message from the beginning is better but for now this is my solution

    @JmsListener(destination = "cdrserver/calls")
    public void receiveMessage1(BaseCDRMessage cdrMessage) {
        cdrMonitorService.sendCDR(cdrMessage);
    }
    
    
    @Override
    public void sendCDR(BaseCDRMessage cdrMessage) {
        messagingTemplate.convertAndSend("/topic/panel/calls/" + cdrMessage.getIncomingCallingNumber(),cdrMessage);
    }