Сообщение Spring WebSocket не переходит к @messagemappings на подключении к топ -топкеJAVA

Программисты JAVA общаются здесь
Anonymous
Сообщение Spring WebSocket не переходит к @messagemappings на подключении к топ -топке

Сообщение Anonymous »

Я использую Spring Boot с Stomp Over Websocket. Подключение Stomp невыполнено успешно, и сообщения, отправленные от клиента, никогда не достигают моего @messagemapping методов.
контроллер:
@Controller
@Slf4j
@MessageMapping("/api/v1")
public class LeaderboardController {
private final ScoreServiceImpl scoreServiceImpl;
private final SimpMessagingTemplate simpMessagingTemplate;

LeaderboardController(ScoreServiceImpl scoreServiceImpl, SimpMessagingTemplate simpMessagingTemplate) {
this.scoreServiceImpl = scoreServiceImpl;
this.simpMessagingTemplate = simpMessagingTemplate;
}

@MessageMapping("/leaderboard/{lb}")
public void changes(@Payload Message request, @DestinationVariable String lb, Principal principal){
log.info("Saving scores for {}", request);
ScoreResponse scoreResponse = scoreServiceImpl.saveScore(request.getPayload(), lb);
simpMessagingTemplate.convertAndSend("/topic/leaderboard/" + lb, scoreResponse);
simpMessagingTemplate.convertAndSendToUser(principal.getName(), "/queue/my-score/" + lb, scoreResponse);
log.info("pushed messages for {}", request);

}
}

клиент с использованием клиента WebSocket King:
CONNECT
accept-version:1.2
host:localhost

^@
SUBSCRIBE
id:sub-0
destination:/topic/update/racers

^@
SEND
destination:/api/v1/leaderboard/racers
content-type:application/json

{"name":"alex","score":42} ^@

Конфигурация WebSocket:
@Slf4j
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry.enableSimpleBroker("/topic", "/queue");

}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/web-socket/connect")
.addInterceptors(new CustomHandshakeInterceptorFromQuery())
.setHandshakeHandler(new CustomUsernameFromQueryHandshakeHandler())
.setAllowedOriginPatterns("*")
// .withSockJS()
;
}

@Bean
public SimpMessagingTemplate simpMessagingTemplate(MessageChannel clientOutboundChannel){
return new SimpMessagingTemplate(clientOutboundChannel);
}
}

Пользовательский перехватчик и ручный обработчик-это пользователь регистрации без жесткой логики безопасности и выполняйте именно то, как они назвали.[MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 0]


Подробнее здесь: https://stackoverflow.com/questions/797 ... connection

Вернуться в «JAVA»