我有一个 JMS 监听器,我必须接收消息,对其进行操作,然后使用 websocket 将其重定向到一个页面。
好吧,我只是对配置感到困惑,我已经配置了WebSocketConfig:
@Configuration
@EnableWebSocketMessageBroker
@EnableScheduling
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic", "/queue");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws/firstep/").withSockJS();
registry.addEndpoint("/ws/secondep/").withSockJS();
}
这应该是正确的,然后我的网页是:
var socket = new SockJS("/myapp-web/api/ws/secondep/",undefined,options);
var stompClient = Stomp.over(socket);
stompClient.connect({
company : "xxx"
}, function(frame) {
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/register', function(message){
console.log('message: ' + message);
});
stompClient.subscribe('/topic/update', function(message){
console.log('message: ' + message);
});
并且连接有效。
现在在我的 jms 监听器上,我尝试以这种方式发送消息:
public class ImporterListener implements MessageListener {
Logger logger = LoggerFactory.getLogger(ImporterListner.class);
@SendTo("/topic/register")
private String TestMessage() {
return "TestMessage";
}
@Override
public void onMessage(Message message) {
logger.info("Request on message");
if (message instanceof MapMessage) {
MapMessage t = (MapMessage) message;
TestMessage(); //<--- have to send the message here
但它不起作用。问题是:
- 如何发送消息?
- 发送消息时,我必须在哪里指定结束点 (secondep)?
谢谢!任何帮助表示赞赏!