The following examples show how to use
org.springframework.messaging.handler.annotation.DestinationVariable
.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
@MessageMapping("/message/{foo}/{name}")
public void messageMappingDestinationVariable(@DestinationVariable("foo") String param1,
@DestinationVariable("name") String param2) {
this.method = "messageMappingDestinationVariable";
this.arguments.put("foo", param1);
this.arguments.put("name", param2);
@SubscribeMapping("/sub/{foo}/{name}")
public void subscribeEventDestinationVariable(@DestinationVariable("foo") String param1,
@DestinationVariable("name") String param2) {
this.method = "subscribeEventDestinationVariable";
this.arguments.put("foo", param1);
this.arguments.put("name", param2);
@MessageMapping("/message/{foo}/{name}")
public void messageMappingDestinationVariable(@DestinationVariable("foo") String param1,
@DestinationVariable("name") String param2) {
this.method = "messageMappingDestinationVariable";
this.arguments.put("foo", param1);
this.arguments.put("name", param2);
@SubscribeMapping("/sub/{foo}/{name}")
public void subscribeEventDestinationVariable(@DestinationVariable("foo") String param1,
@DestinationVariable("name") String param2) {
this.method = "subscribeEventDestinationVariable";
this.arguments.put("foo", param1);
this.arguments.put("name", param2);
* Serves websocket requests, requesting to start a stream on the given view.
@MessageMapping("/consume/{viewId}")
@Transactional(readOnly = true)
public String newConsumer(
@DestinationVariable final Long viewId,
final ConsumeRequest consumeRequest,
final SimpMessageHeaderAccessor headerAccessor) {
// Retrieve view
final Optional<View> viewOptional = viewRepository.findById(viewId);
if (!viewOptional.isPresent()) {
return "{success: false}";
final View view = viewOptional.get();
// Build a session identifier
final long userId = getLoggedInUserId(headerAccessor);
final String sessionId = headerAccessor.getSessionId();
final SessionIdentifier sessionIdentifier = SessionIdentifier.newStreamIdentifier(userId, sessionId);
// Override settings
// TODO View gets flushed and changes are persisted.
final ViewCustomizer viewCustomizer = new ViewCustomizer(view, consumeRequest);
viewCustomizer.overrideViewSettings();
final List<FilterDefinition> configuredFilters = viewCustomizer.getFilterDefinitions();
// Configure where to start from
final StartingPosition startingPosition = viewCustomizer.getStartingPosition();
webSocketConsumersManager.addNewConsumer(view, configuredFilters, startingPosition, sessionIdentifier);
return "{success: true}";
* Serves web socket requests, requesting to pause a consumer.
@MessageMapping("/pause/{viewId}")
@Transactional(readOnly = true)
public String pauseConsumer(
@DestinationVariable final Long viewId,
final SimpMessageHeaderAccessor headerAccessor) {
// Request a pause
final long userId = getLoggedInUserId(headerAccessor);
final String sessionId = headerAccessor.getSessionId();
webSocketConsumersManager.pauseConsumer(viewId, SessionIdentifier.newStreamIdentifier(userId, sessionId));
return "{success: true}";
* Serves web socket requests, requesting to resume a consumer.
@MessageMapping("/resume/{viewId}")
@Transactional(readOnly = true)
public String resumeConsumer(
@DestinationVariable final Long viewId,
final SimpMessageHeaderAccessor headerAccessor) {
// Request Resume
final long userId = getLoggedInUserId(headerAccessor);
final String sessionId = headerAccessor.getSessionId();
webSocketConsumersManager.resumeConsumer(viewId, SessionIdentifier.newStreamIdentifier(userId, sessionId));
return "{success: true}";
@MessageMapping("/tty/{jobId}/open")
public void open(@DestinationVariable String jobId, MessageHeaders headers) {
TtyCmd.In in = new TtyCmd.In()
.setId(jobId)
.setAction(TtyCmd.Action.OPEN);
validate(in, headers);
ttyService.execute(in);
@MessageMapping("/tty/{jobId}/shell")
public void shell(@DestinationVariable String jobId, @Payload String script, MessageHeaders headers) {
TtyCmd.In in = new TtyCmd.In()
.setId(jobId)
.setAction(TtyCmd.Action.SHELL)
.setInput(script);
validate(in, headers);
ttyService.execute(in);
@MessageMapping("/tty/{jobId}/close")
public void close(@DestinationVariable String jobId, MessageHeaders headers) {
TtyCmd.In in = new TtyCmd.In()
.setId(jobId)
.setAction(TtyCmd.Action.CLOSE);
validate(in, headers);
ttyService.execute(in);
@MessageMapping("/chat/{topic}")
@SendTo("/topic/messages")
public OutputMessage send(@DestinationVariable("topic") String topic,
Message message) throws Exception
return new OutputMessage(message.getFrom(), message.getText(), topic);
@MessageMapping("/message/{foo}/{name}")
public void messageMappingDestinationVariable(@DestinationVariable("foo") String param1,
@DestinationVariable("name") String param2) {
this.method = "messageMappingDestinationVariable";
this.arguments.put("foo", param1);
this.arguments.put("name", param2);
@SubscribeMapping("/sub/{foo}/{name}")
public void subscribeEventDestinationVariable(@DestinationVariable("foo") String param1,
@DestinationVariable("name") String param2) {
this.method = "subscribeEventDestinationVariable";
this.arguments.put("foo", param1);
this.arguments.put("name", param2);
@MessageMapping("/queue/CSM_QUEUE_{queueId}")
@SendTo("/queue/CSM_QUEUE_{queueId}")
public List<StockProduct> sendContent(@Payload List<String> tickers, @DestinationVariable("queueId") String queueId) throws Exception {
String username = extractUserFromQueueId(queueId);
if(!getPrincipal().getUsername().equals(username)){
throw new IllegalAccessError("/queue/CSM_QUEUE_"+queueId);
return stockProductService.gather(username, tickers.toArray(new String[tickers.size()]));
@MessageMapping("/tennis/bet/{clientId}/{matchId}")
public void bet(String winner, @DestinationVariable("clientId") String clientId,
@DestinationVariable("matchId") String matchId) {
Map<String, String> clientBets = matchClientBets.get(matchId);
clientBets.put(clientId, winner);
System.out.println(clientId);
System.out.println(winner);
System.out.println(matchId);
@SubscribeMapping("/get")
public PlayQueueInfo getPlayQueue(@DestinationVariable int playerId, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
return playQueueService.getPlayQueueInfo(player);
@MessageMapping("/start")
public void start(@DestinationVariable int playerId, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.start(player);
@MessageMapping("/stop")
public void stop(@DestinationVariable int playerId, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.stop(player);
@MessageMapping("/toggleStartStop")
public void toggleStartStop(@DestinationVariable int playerId, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.toggleStartStop(player);
@MessageMapping("/skip")
public void skip(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.skip(player, req.getIndex(), req.getOffset());
@MessageMapping("/reloadsearch")
public void reloadSearchCriteria(@DestinationVariable int playerId, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.reloadSearchCriteria(player, headers.getSessionId());
@MessageMapping("/save")
@SendToUser
public int savePlayQueue(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
return playQueueService.savePlayQueue(player, req.getIndex(), req.getOffset());
@MessageMapping("/play/saved")
public void loadSavedPlayQueue(@DestinationVariable int playerId, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.loadSavedPlayQueue(player, headers.getSessionId());
@MessageMapping("/play/mediafile")
public void playMediaFile(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.playMediaFile(player, req.getId(), headers.getSessionId());
@MessageMapping("/play/radio")
public void playInternetRadio(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.playInternetRadio(player, req.getId(), req.getIndex(), headers.getSessionId());
@MessageMapping("/play/playlist")
public void playPlaylist(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.playPlaylist(player, req.getId(), req.getIndex(), headers.getSessionId());
@MessageMapping("/play/topsongs")
public void playTopSong(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.playTopSong(player, req.getId(), req.getIndex(), headers.getSessionId());
@MessageMapping("/play/podcastchannel")
public void playPodcastChannel(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.playPodcastChannel(player, req.getId(), headers.getSessionId());
@MessageMapping("/play/podcastepisode")
public void playPodcastEpisode(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.playPodcastEpisode(player, req.getId(), headers.getSessionId());
@MessageMapping("/play/podcastepisode/newest")
public void playNewestPodcastEpisode(@DestinationVariable int playerId, PlayQueueRequest req, SimpMessageHeaderAccessor headers) throws Exception {
Player player = getPlayer(playerId, headers);
playQueueService.playNewestPodcastEpisode(player, req.getIndex(), headers.getSessionId());