类org.springframework.messaging.simp.annotation.SubscribeMapping源码实例Demo

下面列出了怎么用org.springframework.messaging.simp.annotation.SubscribeMapping的API类实例代码及写法,或者点击链接到github查看源代码。

@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);
}
 
@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;
}
 
@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);
}
 
@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;
}
 
源代码5 项目: joal   文件: WebSocketController.java
/**
 * 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;
}
 
@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);
}
 
@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;
}
 
@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;
}
 
源代码9 项目: gpmr   文件: ActivityService.java
@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;
}
 
源代码10 项目: ServiceCutter   文件: ActivityService.java
@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;
}
 
源代码11 项目: flex-poker   文件: TableController.java
@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());
}
 
源代码12 项目: airsonic-advanced   文件: PlayQueueWSController.java
@SubscribeMapping("/get")
public PlayQueueInfo getPlayQueue(@DestinationVariable int playerId, SimpMessageHeaderAccessor headers) throws Exception {
    Player player = getPlayer(playerId, headers);
    return playQueueService.getPlayQueueInfo(player);
}
 
源代码13 项目: airsonic-advanced   文件: PlaylistWSController.java
@SubscribeMapping("/readable")
public List<Playlist> getReadablePlaylists(Principal p) {
    return playlistService.getReadablePlaylistsForUser(p.getName());
}
 
源代码14 项目: airsonic-advanced   文件: PlaylistWSController.java
@SubscribeMapping("/{id}")
public Playlist getPlaylist(Principal p, @DestinationVariable int id) {
    return new PlaylistService.BroadcastedPlaylist(playlistService.getPlaylist(id), true);
}
 
源代码15 项目: airsonic-advanced   文件: NowPlayingWSController.java
@SubscribeMapping("/nowPlaying/current")
public List<NowPlayingInfo> getActivePlays() {
    return statusService.getActivePlays();
}
 
源代码16 项目: airsonic-advanced   文件: NowPlayingWSController.java
@SubscribeMapping("/nowPlaying/recent")
public List<NowPlayingInfo> getInactivePlays() {
    return statusService.getInactivePlays();
}
 
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.hasMethodAnnotation(SubscribeMapping.class) &&
			!returnType.hasMethodAnnotation(SendTo.class) &&
			!returnType.hasMethodAnnotation(SendToUser.class));
}
 
@SubscribeMapping("/data") // not needed for the tests but here for completeness
private String getData() {
	return PAYLOAD;
}
 
@SubscribeMapping("/data") // not needed for the tests but here for completeness
@SendTo("/sendToDest")
private String getDataAndSendTo() {
	return PAYLOAD;
}
 
@SubscribeMapping("/foo")
public String handleSubscribe() {
	return "bar";
}
 
@SubscribeMapping("/foo")
public String handleSubscribe() {
	return "bar";
}
 
@SubscribeMapping("/number")
public int number() {
	return 42;
}
 
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.hasMethodAnnotation(SubscribeMapping.class) &&
			!returnType.hasMethodAnnotation(SendTo.class) &&
			!returnType.hasMethodAnnotation(SendToUser.class));
}
 
@SubscribeMapping("/data") // not needed for the tests but here for completeness
private String getData() {
	return PAYLOAD;
}
 
@SubscribeMapping("/data") // not needed for the tests but here for completeness
@SendTo("/sendToDest")
private String getDataAndSendTo() {
	return PAYLOAD;
}
 
@SubscribeMapping("/foo")
public String handleSubscribe() {
	return "bar";
}
 
@SubscribeMapping("/foo")
public String handleSubscribe() {
	return "bar";
}
 
@SubscribeMapping("/number")
public int number() {
	return 42;
}
 
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	return (returnType.getMethodAnnotation(SubscribeMapping.class) != null &&
			returnType.getMethodAnnotation(SendTo.class) == null &&
			returnType.getMethodAnnotation(SendToUser.class) == null);
}
 
@SubscribeMapping("/data") // not needed for the tests but here for completeness
private String getData() {
	return PAYLOAD;
}
 
 类方法
 同包方法