내 서비스 클래스 중 하나에서 작업이 수행 될 때 특정 레코드의 websocket 구독자에게 메시지를 보내려고합니다.Spring이 Websocket Message Broker에 메시지를 보냅니다.
나는 Spring Websocket documentation을 읽으려고하고 있지만이 모든 것들을 함께 작동시키는 방법에 대해서는 모호합니다.
WebsocketConfiguration.java
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableStompBrokerRelay("/queue/", "/topic/", "/exchange/");
config.setApplicationDestinationPrefixes("/app");
config.setPathMatcher(new AntPathMatcher("."));
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").withSockJS();
}
WebsocketSecurity.java
@Override
protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
messages
// message types other than MESSAGE and SUBSCRIBE
.nullDestMatcher().authenticated()
// matches any destination that starts with /rooms/
.simpDestMatchers("/topic/tracker").hasAuthority(AuthoritiesConstants.ADMIN)
.simpDestMatchers("/topic/**").authenticated()
// (i.e. cannot send messages directly to /topic/, /queue/)
// (i.e. cannot subscribe to /topic/messages/* to get messages sent to
// /topic/messages-user<id>)
.simpTypeMatchers(SimpMessageType.MESSAGE, SimpMessageType.SUBSCRIBE).denyAll()
// catch all
.anyMessage().denyAll();
}
컨트롤러 클래스 (단순 브로커를 구현에서 시도 : 여기
내 설치 파일 (이 BTW jHipster을 확장하고)있다 sockjs를 구독하고 응용 프로그램의 다른 곳에서 생성 된 메시지를 수신하는 방법을 테스트 할 수 있습니다.
@MessageMapping("/ws")
@SendTo("/topic/sendactivity.{id}")
public void activity(@DestinationVariable string id, @Payload String message){
log.debug("Sending command center: "+message);
}
@RequestMapping(value = "/updateactivity", method = RequestMethod.PUT)
public ResponseEntity<Membership> updateMembership(
@RequestBody Membership membership) throws URISyntaxException {
// ...
String testString = "test";
messagingTemplate.convertAndSend("/topic/commandcenter"+membership.getId().toString(), testString);
// ...
}
public void activity
메서드에 중단 점을 적용해도 아무 것도 얻을 수 없습니까?
과 같은 몇 가지 예에서 sockJS 클라이언트 로그를 공유 할 수 있습니까? 어떤 메시지가 전송되었고 어떤 응답을 받았는지 확인할 방법이 없습니다. 또한 org.springframework.web.socket'을 DEBUG에 넣고 관련 로그도 공유 할 수 있습니까? –
@BrianClozel - 아직 채널을 구독하지 않았습니다. 활성화되지 않았습니까?! 나는'convertAndSend'를 실행 한 후에'void activity' 메서드에서 중단 점에 도달해야한다고 생각했습니다. –