使用SimpMessagingTemplate发送消息

 

使用org.springframework.messaging.simp.SimpMessagingTemplate类可以在服务端的任意地方给客户端发送消息。此外,在我们配置Spring支持STOMP后SimpMessagingTemplate类就会被自动装配到Spring的上下文中,因此我们只需要在想要使用的地方使用@Autowired注解注入SimpMessagingTemplate即可使用

 

需要说明的是,SimpMessagingTemplate有两个重要的方法,它们分别是:

public void convertAndSend(D destination, Object payload):给监听了路径destination的所有客户端发送消息payload

 

public void convertAndSendToUser(String user, String destination, Object payload):给监听了路径destination的用户user发送消息payload

 

 

 

文献来源于:https://www.zifangsky.cn/1359.html

相关文章:

  • 2021-12-04
  • 2021-06-20
  • 2021-10-01
  • 2021-10-15
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2021-12-07
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案