Topic Destinations
For simple topic destinations which deliver a copy
of each message to all active subscribers, destinations of the form
/topic/<name> can be used. Topic destinations support all the routing
patterns of AMQP topic exchanges.
Messages sent to a topic destination that has no active subscribers
are simply discarded.
@Secured(User.ROLE_USER)
@MessageMapping("/comment/{liveid}")
@SendTo("/topic/comment-{liveid}")
public CommentMessage userComment(@DestinationVariable("liveid") String liveid,
@AuthenticationPrincipal UserDetails activeUser, UserComment userComment) {
logger.debug("Receiving comment message '{}' of live '{}' from user '{}'.",
userComment,liveid, activeUser.getUsername());
final User user = userService.findByUsername(activeUser.getUsername()).get();
return CommentMessage.builder().content(userComment.getContent()).sender(user.getNickname())
.senderAvatar(user.getAvatar()).build();
} $stomp.subscribe('/topic/comment-' + $scope.lives[i].id, function(payload, headers, res) {
// do something
}, {
'durable': true,
'auto-delete': false
}); @Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractSessionWebSocketMessageBrokerConfigurer<ExpiringSession> {
@Value("${stompBroker.host:localhost}")
String brokerHost;
@Value("${stompBroker.port:61613}")
int brokerPort;
@Value("${stompBroker.login:guest}")
String brokerLogin;
@Value("${stompBroker.passcode:guest}")
String brokerPasscode;
@Value("${stompBroker.vhost:myvhost}")
String brokerVHost;
@Override
protected void configureStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/live/ws").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableStompBrokerRelay("/topic/").setRelayHost(brokerHost).setRelayPort(
brokerPort).setSystemLogin(brokerLogin).setSystemPasscode(brokerPasscode).setVirtualHost(brokerVHost);
/**
* Both of two subscribers can receive the message if using simple broker
registry.enableSimpleBroker("/topic/");
*/
registry.setApplicationDestinationPrefixes("/app");
}
@Configuration
public class WebSocketSecurityConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer {
@Override
protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
messages.simpDestMatchers("/app/*").hasRole("USER");
}
@Override
protected boolean sameOriginDisabled() {
return true;
}
}
}live_f84730c.js:36 Opening Web Socket...live_f84730c.js:36 Web Socket Opened...live_f84730c.js:36 >>> CONNECTaccept-version:1.1,1.0heart-beat:10000,10000
live_f84730c.js:36 <<< CONNECTEDserver:RabbitMQ/3.6.6session:session-Xu-7aNTIE6W30AgSEZQJAwheart-beat:10000,10000version:1.1user-name:58b7e71f1dc9e83c4b2f1a7e
live_f84730c.js:36 connected to server RabbitMQ/3.6.6live_f84730c.js:36 send PING every 10000mslive_f84730c.js:36 check PONG every 10000mslive_f84730c.js:36 <<< PONGlive_f84730c.js:36 >>> SUBSCRIBEdurable:trueauto-delete:falseid:sub-0destination:/topic/watchinfo-581820bb19ed180005322ed6
live_f84730c.js:36 >>> SUBSCRIBEdurable:trueauto-delete:falseid:sub-1destination:/topic/comment-581820bb19ed180005322ed6
live_f84730c.js:36 >>> SENDpriority:9destination:/app/watch/581820bb19ed180005322ed6content-length:2
{}live_f84730c.js:36 <<< PONGlive_f84730c.js:36 >>> PINGlive_f84730c.js:36 <<< PONGlive_f84730c.js:36 >>> SENDpriority:9destination:/app/comment/581820bb19ed180005322ed6content-length:27
{"content":"first message"}live_f84730c.js:36 >>> PINGlive_f84730c.js:36 >>> SENDpriority:9destination:/app/comment/581820bb19ed180005322ed6content-length:28
{"content":"second message"}live_f84730c.js:36 <<< MESSAGEsubscription:sub-1destination:/topic/comment-581820bb19ed180005322ed6message-id:T_sub-1@@session-Xu-7aNTIE6W30AgSEZQJAw@@1redelivered:falsecontent-type:application/json;charset=UTF-8content-length:64
{"content":"second message","sender":"小琦","senderAvatar":""}2live_f84730c.js:36 <<< PONGlive_f84730c.js:36 >>> PINGlive_f84730c.js:36 <<< PONGlive_f84730c.js:36 >>> PING<<< MESSAGE
subscription:sub-1
destination:/topic/comment-581820bb19ed180005322ed6
message-id:T_sub-1@@session-XjhlhlhhXoASjCkMf1_SBg@@8
redelivered:false
content-type:application/json;charset=UTF-8
content-length:63
{"content":"first message","sender":"小琦","senderAvatar":""}�--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
MKStaff Software Engineer, Pivotal/RabbitMQ
--You received this message because you are subscribed to a topic in the Google Groups "rabbitmq-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rabbitmq-users/H7BPkN3YuUg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rabbitmq-users+unsubscribe@googlegroups.com.