org.springframework.messaging.simp.annotation.SubscribeMapping Java Examples

The following examples show how to use org.springframework.messaging.simp.annotation.SubscribeMapping. 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.
Example #1
Source File: ActivityService.java    From ServiceCutter with Apache License 2.0 5 votes vote down vote up
@SubscribeMapping("/topic/activity")
@SendTo("/topic/tracker")
public ActivityDTO sendActivity(@Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
    activityDTO.setUserLogin(SecurityUtils.getCurrentLogin());
    activityDTO.setUserLogin(principal.getName());
    activityDTO.setSessionId(stompHeaderAccessor.getSessionId());
    activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString());
    activityDTO.setTime(dateTimeFormatter.print(Calendar.getInstance().getTimeInMillis()));
    log.debug("Sending user tracking data {}", activityDTO);
    return activityDTO;
}
 
Example #2
Source File: SubscriptionMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SubscribeMapping("/jsonview")	// not needed for the tests but here for completeness
@JsonView(MyJacksonView1.class)
public JacksonViewBean getJsonView() {
	JacksonViewBean payload = new JacksonViewBean();
	payload.setWithView1("with");
	payload.setWithView2("with");
	payload.setWithoutView("without");
	return payload;
}
 
Example #3
Source File: SimpAnnotationMethodMessageHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #4
Source File: WebSocketController.java    From joal with Apache License 2.0 5 votes vote down vote up
/**
 * This mapping is bypassing the spring WebSocket broker (because of SubscribeMapping) and send the response
 * directly to the client who subscribed, and only him.
 * <b>READ CAREFULLY</b>: since the response is send ignoring the message broker, client will have to provide the
 * application destination prefix (/joal/events/replay)
 *
 * @return an ordered list of all needed event to rebuild the current application state
 */
@SubscribeMapping("/initialize-me")
public List<StompMessage> list() {
    final LinkedList<StompMessage> events = new LinkedList<>();

    // client files list
    events.add(StompMessage.wrap(new ListOfClientFilesPayload(new ListOfClientFilesEvent(this.seedManager.listClientFiles()))));

    // config
    events.addFirst(StompMessage.wrap(new ConfigHasBeenLoadedPayload(new ConfigHasBeenLoadedEvent(this.seedManager.getCurrentConfig()))));

    // torrent files list
    for (final MockedTorrent torrent : this.seedManager.getTorrentFiles()) {
        events.addFirst(StompMessage.wrap(new TorrentFileAddedPayload(new TorrentFileAddedEvent(torrent))));
    }

    // global state
    if (this.seedManager.isSeeding()) {
        events.addFirst(StompMessage.wrap(new GlobalSeedStartedPayload(this.seedManager.getCurrentEmulatedClient())));
    } else {
        events.addFirst(StompMessage.wrap(new GlobalSeedStoppedPayload()));
    }

    // speeds
    final Map<InfoHash, Speed> speedMap = this.seedManager.getSpeedMap();
    if (!speedMap.isEmpty()) {
        events.addFirst(StompMessage.wrap(new SeedingSpeedHasChangedPayload(new SeedingSpeedsHasChangedEvent(speedMap))));
    }

    // Announcers are the most likely to change due to a concurrent access, so we gather them as late as possible, and we put them at the top of the list.
    for (final AnnouncerFacade announcerFacade : this.seedManager.getCurrentlySeedingAnnouncer()) {
        events.addFirst(StompMessage.wrap(new SuccessfullyAnnouncePayload(new SuccessfullyAnnounceEvent(announcerFacade, RequestEvent.STARTED))));
    }
    return events;
}
 
Example #5
Source File: _ActivityService.java    From jhipster-ribbon-hystrix with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeMapping("/topic/activity")
@SendTo("/topic/tracker")
public ActivityDTO sendActivity(@Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
    activityDTO.setUserLogin(SecurityUtils.getCurrentUserLogin());
    activityDTO.setUserLogin(principal.getName());
    activityDTO.setSessionId(stompHeaderAccessor.getSessionId());
    activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString());
    Instant instant = Instant.ofEpochMilli(Calendar.getInstance().getTimeInMillis());
    activityDTO.setTime(dateTimeFormatter.format(ZonedDateTime.ofInstant(instant, ZoneOffset.systemDefault())));
    log.debug("Sending user tracking data {}", activityDTO);
    return activityDTO;
}
 
Example #6
Source File: ActivityService.java    From gpmr with Apache License 2.0 5 votes vote down vote up
@SubscribeMapping("/topic/activity")
@SendTo("/topic/tracker")
public ActivityDTO sendActivity(@Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
    activityDTO.setUserLogin(SecurityUtils.getCurrentUserLogin());
    activityDTO.setUserLogin(principal.getName());
    activityDTO.setSessionId(stompHeaderAccessor.getSessionId());
    activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString());
    Instant instant = Instant.ofEpochMilli(Calendar.getInstance().getTimeInMillis());
    activityDTO.setTime(dateTimeFormatter.format(ZonedDateTime.ofInstant(instant, ZoneOffset.systemDefault())));
    log.debug("Sending user tracking data {}", activityDTO);
    return activityDTO;
}
 
Example #7
Source File: SubscriptionMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SubscribeMapping("/jsonview")	// not needed for the tests but here for completeness
@JsonView(MyJacksonView1.class)
public JacksonViewBean getJsonView() {
	JacksonViewBean payload = new JacksonViewBean();
	payload.setWithView1("with");
	payload.setWithView2("with");
	payload.setWithoutView("without");
	return payload;
}
 
Example #8
Source File: SimpAnnotationMethodMessageHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #9
Source File: SubscriptionMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SubscribeMapping("/jsonview")	// not needed for the tests but here for completeness
@JsonView(MyJacksonView1.class)
public JacksonViewBean getJsonView() {
	JacksonViewBean payload = new JacksonViewBean();
	payload.setWithView1("with");
	payload.setWithView2("with");
	payload.setWithoutView("without");
	return payload;
}
 
Example #10
Source File: TableController.java    From flex-poker with GNU General Public License v2.0 5 votes vote down vote up
@SubscribeMapping("/user/queue/pocketcards")
public List<PocketCardsDTO> fetchPocketCards(Principal principal) {
    var playerId = loginRepository.fetchAggregateIdByUsername(principal.getName());
    var pocketCardsForUser = cardsUsedInHandRepository.fetchAllPocketCardsForUser(playerId);
    return pocketCardsForUser.entrySet().stream()
            .map(x -> new PocketCardsDTO(x.getKey(), x.getValue().getCard1().getId(), x.getValue().getCard2().getId()))
            .collect(Collectors.toList());
}
 
Example #11
Source File: SimpAnnotationMethodMessageHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #12
Source File: BankTransferController.java    From AxonBank with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping("/bank-accounts/{bankAccountId}/bank-transfers")
public Iterable<BankTransferEntry> bankTransfers(@DestinationVariable String bankAccountId) {
    log.info("Retrieve bank transfers for bank account with id {}", bankAccountId);
    return bankTransferRepository.findBySourceBankAccountIdOrDestinationBankAccountId(bankAccountId, bankAccountId);
}
 
Example #13
Source File: PortfolioController.java    From spring4ws-demos with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping("/positions")
public List<PortfolioPosition> getPositions(Principal principal) throws Exception {
	logger.debug("Positions for " + principal.getName());
	Portfolio portfolio = this.portfolioService.findPortfolio(principal.getName());
	return portfolio.getPositions();
}
 
Example #14
Source File: MessageBrokerConfigurationTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping("/foo")
public String handleSubscribe() {
	return "bar";
}
 
Example #15
Source File: TwitterHandler.java    From spring4ws-demos with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping("/queue/tweets")
public Queue<Tweet> subscribe() {
	return this.lastTweets;
}
 
Example #16
Source File: WebSocketMessageBrokerConfigurationSupportTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping("/foo")
public String handleSubscribe() {
	return "bar";
}
 
Example #17
Source File: TableController.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@SubscribeMapping("/topic/game/{gameId}/table/{tableId}")
public TableDTO fetchTable(@DestinationVariable UUID gameId,
        @DestinationVariable UUID tableId) {
    return tableRepository.fetchById(tableId);
}
 
Example #18
Source File: StompWebSocketIntegrationTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping("/number")
public int number() {
	return 42;
}
 
Example #19
Source File: ChatController.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@SubscribeMapping("/topic/chat/game/{gameId}/table/{tableId}")
public List<ChatMessageDTO> fetchAllTableChatMessages(
        @DestinationVariable UUID gameId, @DestinationVariable UUID tableId) {
    return chatRepository.fetchAllTableChatMessages(tableId);
}
 
Example #20
Source File: ChatController.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@SubscribeMapping("/topic/chat/lobby")
public List<ChatMessageDTO> fetchAllLobbyChatMessages() {
    return chatRepository.fetchAllLobbyChatMessages();
}
 
Example #21
Source File: BankAccountController.java    From AxonBank with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping
public Iterable<BankAccountEntry> all() {
    return bankAccountRepository.findAllByOrderByIdAsc();
}
 
Example #22
Source File: BankAccountController.java    From AxonBank with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping("/{id}")
public BankAccountEntry get(@DestinationVariable String id) {
    return bankAccountRepository.findOne(id);
}
 
Example #23
Source File: ChatController.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@SubscribeMapping("/topic/chat/game/{gameId}")
public List<ChatMessageDTO> fetchAllGameChatMessages(@DestinationVariable UUID gameId) {
    return chatRepository.fetchAllGameChatMessages(gameId);
}
 
Example #24
Source File: SubscriptionMethodReturnValueHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.getMethodAnnotation(SubscribeMapping.class) != null &&
			returnType.getMethodAnnotation(SendTo.class) == null &&
			returnType.getMethodAnnotation(SendToUser.class) == null);
}
 
Example #25
Source File: MessageController.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@SubscribeMapping("/users")
public List<String> subscribeMessages() {
	return this.activeUserRepository.findAllActiveUsers();
}
 
Example #26
Source File: GameManagementController.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@SubscribeMapping("/topic/availabletournaments")
public List<GameInListDTO> displayAllGames() {
    return gameRepository.fetchAll();
}
 
Example #27
Source File: GameManagementController.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@SubscribeMapping("/app/opengamesforuser")
public List<OpenGameForUser> displayOpenGames(Principal principal) {
    var playerId = loginRepository.fetchAggregateIdByUsername(principal.getName());
    return openGameForUserRepository.fetchAllOpenGamesForPlayer(playerId);
}
 
Example #28
Source File: StompWebSocketIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@SubscribeMapping("/number")
public int number() {
	return 42;
}
 
Example #29
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeMapping("/readable")
public List<Playlist> getReadablePlaylists(Principal p) {
    return playlistService.getReadablePlaylistsForUser(p.getName());
}
 
Example #30
Source File: PlaylistWSController.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeMapping("/{id}")
public Playlist getPlaylist(Principal p, @DestinationVariable int id) {
    return new PlaylistService.BroadcastedPlaylist(playlistService.getPlaylist(id), true);
}