Push Message from ActiveMQ to Spring Controller

时间秒杀一切 提交于 2019-12-11 03:55:22

问题


I'm using Spring MVC, ActiveMQ and WebSocket(via sock.js and stomp.js) to build a real-time data delivery application.

As we know, when a producer(another desktop application) push a message to ActiveMQ, and the onMessage() method will catch it.

public class MessageReceiver implements MessageListener {
    public void onMessage(Message message) {
        System.out.println(message);

        // How to push the message to a Controller in Spring?
    }
}

Most of the tutorials just print the message to the console.

I have another controller called WebSocketController:

@Controller
public class WebSocketController {
    @SubscribeMapping("/getRealTimeResult.action/{submissionId}")
    public Message getRealTimeResultAction(
            @DestinationVariable long submissionId) {
        return new Message("Message content from onMessage() method");
    }
}

I want to push the message received in onMessage() method to the getRealTimeResultAction() method. Can you tell me how to do it?

I know that the ActiveMQ can communicate with the browser using stomp via the port 61613.

I don't want to do this because I think the MQ should be transparent to the user. Also I need to do some authorization in the WebSocketController.


回答1:


Generally speaking an @Controller with @SubscribeMapping and @MessageMapping methods can handle subscriptions and messages from STOMP clients connected over WebSocket.

From your description it's not clear what you're trying to do. Was the message pushed to ActiveMQ via STOMP from a browser client or was it produced by some other back-end JMS client? Also the MessageReceiver receives an actual message while the @Controller method has an @SubscribeMapping method for handling a subscription from a STOMP client. It's not clear what you're trying to do. Please provide more information so I can provide a better answer.



来源:https://stackoverflow.com/questions/30387710/push-message-from-activemq-to-spring-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!