Answer the question
In order to leave comments, you need to log in
How to "map" methods by headers in Spring STOMP messages?
The application uses the STOMP protocol to exchange messages in the Websockets environment.
There is a controller in which methods are "mapped":
@Controller
public class UserController {
@Autowired
private UserManager userManager;
@MessageMapping("/users")
@SendTo("/queue/users")
@ResponseBody
public List<User> list() {
return userManager.findAll();
}
@MessageMapping("/users")
@SendTo("/queue/users")
@ResponseBody
public User user(@Payload MessagePayload messagePayload) {
int idUser = Integer.parseInt(messagePayload.getRequestValue("id_user"));
User user = userManager.findUserById(idUser);
if (user == null) {
throw new UserNotFoundException(idUser);
}
return user;
}
}
@MessageMapping("/users")
@Header("command" = "GETLOCALUSER")
@SendTo("/queue/users")
@ResponseBody
public List<User> list() {
return userManager.findAll();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question