package com.iscas.base.biz.test.controller;
import com.iscas.templet.common.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.user.SimpUser;
import org.springframework.messaging.simp.user.SimpUserRegistry;
import org.springframework.web.bind.annotation.RestController;
import java.security.Principal;
@RestController
public class WebSoketDemoController {
@Autowired
private SimpMessagingTemplate messagingTemplate;
@Autowired
private SimpUserRegistry userRegistry;
@MessageMapping(value = "/P2P")
public void templateTest(Principal principal) {
int i = 1;
for (SimpUser user : userRegistry.getUsers()) {
}
messagingTemplate.convertAndSendToUser(principal.getName(), "/queue/message","服务器主动推的数据");
}
@MessageMapping("/broadcast")
@SendTo("/topic/getResponse")
public ResponseEntity topic() throws Exception {
return new ResponseEntity(200,"success");
}
}
|