将消息从ActiveMQ推送到Spring Controller [英] Push Message from ActiveMQ to Spring Controller

查看:270
本文介绍了将消息从ActiveMQ推送到Spring Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring MVC,ActiveMQ和WebSocket(通过 sock.js stomp.js

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

我们知道,当生产者(另一个桌面应用程序)将消息推送到ActiveMQ时, onMessage()方法将捕获它。

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.

我还有一个名为 WebSocketController 的控制器:

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

我想推送在<$ c中收到的消息$ c> onMessage()方法添加到 getRealTimeResultAction()方法中。你能告诉我怎么做吗?

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

我知道ActiveMQ可以通过 stomp 与浏览器进行通信端口 61613

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

我不想这样做,因为我认为MQ对用户应该是透明的。另外,我还需要在 WebSocketController 中做一些授权。

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.

推荐答案

通常用@SubscribeMapping和@MessageMapping方法讲@Controller可以处理来自通过WebSocket连接的STOMP客户端的订阅和消息。

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

根据您的描述,您不清楚要做什么。消息是从浏览器客户端通过STOMP推送到ActiveMQ还是由其他后端JMS客户端生成?当@Controller方法具有用于处理来自STOMP客户端的订阅的@SubscribeMapping方法时,MessageReceiver还会接收实际消息。目前尚不清楚您要做什么。请提供更多信息,以便我提供更好的答案。

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.

这篇关于将消息从ActiveMQ推送到Spring Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆