You can write an incoming interceptor and send the corresponding error message to the client.
public class ClientInboundChannelInterceptor extends ChannelInterceptorAdapter {
@Autowired
private SimpMessagingTemplate simpMessagingTemplate;
@Override
public Message<?> preSend(Message message, MessageChannel channel) throws IllegalArgumentException{
StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(message);
logger.debug("logging command " + headerAccessor.getCommand());
try {
} catch (Exception e){
throw new MyCustomException();
}
}
}
UPDATE:
1) When you throw any exception from ClientInboundChannelInterceptor, it will be sent as a frame ERROR, you do not need to do anything special.
2) , - DISCONNECT ( ).
SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.DISCONNECT);
headerAccessor.setSessionId(sessionId);
headerAccessor.setLeaveMutable(true);
template.convertAndSendToUser(destination,new HashMap<>(),headerAccessor.getMessageHeaders());
.
1) ClientInboundChannelInterceptor.
2) Handler/Controller @SubscribeMapping .
@SubscribeMapping("your destination")
public ConnectMessage handleSubscriptions(@DestinationVariable String userID, org.springframework.messaging.Message message){
// this is my custom class
ConnectMessage frame= new ConnectMessage();
// write your logic here
return frame;
}
frame .