go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  How it works -- how the broker wire the publish-subscribe mapping internally?
 
Subject: How it works -- how the broker wire the publish-subscribe mapping internally?
Author: WebSpider
In response to: Configuration
Posted on: 07/11/2020 12:59:42 AM

@Controller
public class WebSocketController {

	// publisher send message to --> "/channel/chat"
	//       --> broker relay it to --> "/topic/messages"
        //       --> broker push it to all subscribers
	@MessageMapping("/chat")
	@SendTo("/topic/messages")
	public OutputMessage send(Message message) throws Exception {
	    String time = new SimpleDateFormat("HH:mm").format(new Date());
	    return new OutputMessage(message.getFrom(), message.getText(), time);
	}
}


 

> On 07/11/2020 12:58:05 AM WebSpider wrote:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
 
    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic", "/queue");
        config.setApplicationDestinationPrefixes("/channel");
    }
 
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
         registry.addEndpoint("/stomp").withSockJS(); 
    }
}


As the annoation @EnableWebSocketMessageBroker suggests, it will enable MESSAGE handling backed by a broker. Here:
  • ".enableSimpleBroker" -- the simple built-in IN-MEMORY (Simple) message broker (Kafka can be a broker for production);
  • "/topic" -- the destination for subscribers -- a folder holding multiple sub-topics
  • "/channel" -- the destination for publishers -- a folder holding multiple sub-channels
  • "/stomp" -- the STOMP's endpoint for connection (STOMP: Simple Text-Orientated Messaging Protocol)
  • ".withSockJS()" -- with SockJS as fallback if WebSocket is not supported by browser.




    References:

  •  


     
    Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
     
    Get your own forum today. It's easy and free.