我想在我的項目中使用RabbitMQ作爲代理,我想在客戶端打開套接字時分配目標隊列。 事情是這樣的:http://i.imgur.com/ldB2M0m.pngRabbitMQ的自定義目的地
我設法與SimpleBroker
做到這一點,但是當我嘗試用StompBrokerRelay
我不能assing上RabbitMQ的隊列中來做到這一點,我停止客戶端(http://i.imgur.com/gNaRHCQ.png)上接收消息。
這是我正在做它:
控制器:
@RestController
public class FeedController {
@Autowired
private SimpMessageSendingOperations template;
@RequestMapping(value = "/feed", method = RequestMethod.POST, consumes = "application/json")
public Reference getLeankrReference(@RequestBody Reference ref)
{
this.template.convertAndSendToUser(ref.getChannelId(), "/topic/feed", ref);
return ref;
}
}
WebSocket的配置:
@Configuration
@EnableWebSocketMessageBroker
@EnableScheduling
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config)
{
config.enableStompBrokerRelay("/topic/")
.setAutoStartup(true);
//config.enableSimpleBroker("/user/");
config.setApplicationDestinationPrefixes("/app");
}
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/vision").withSockJS();
}
}
客戶:
function connect() {
var socket = new SockJS('/ws/vision');
var channel = document.getElementById('name').value;
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/user/' + channel + '/feed', function(message) {
showContent(JSON.parse(message.body));
});
});
}
我知道我錯過了一些東西。也許一些經紀人配置?
預先感謝您!
你有沒有錯過配置'/隊列/'旁邊'/ topic /'? –
@ArtemBilan我也試過'/ queue /'。它幫助我訂閱RabbitMQ上的隊列。但是,當我嘗試在客戶端上發佈某些內容時,它不會收到任何消息。 –