本文整理汇总了Java中org.springframework.messaging.handler.annotation.DestinationVariable类的典型用法代码示例。如果您正苦于以下问题:Java DestinationVariable类的具体用法?Java DestinationVariable怎么用?Java DestinationVariable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DestinationVariable类属于org.springframework.messaging.handler.annotation包,在下文中一共展示了DestinationVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessages
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
/**
* Receive and send messages via websockets.
* <p>
* Note: public and private chats work the same way. The permission handling is
* done at the SUBSCRIBE event as part of the AuthenticationInterceptor.
*
* @param roomId String
* @param message Message
* @param traveler Traveler
* @return Message
* @throws Exception
*/
@MessageMapping("/chat/{roomId}")
public Message handleMessages(@DestinationVariable("roomId") String roomId, @Payload Message message, Traveler traveler) throws Exception {
System.out.println("Message received for room: " + roomId);
System.out.println("User: " + traveler.toString());
// store message in database
message.setAuthor(traveler);
message.setChatRoomId(Integer.parseInt(roomId));
int id = MessageRepository.getInstance().save(message);
message.setId(id);
return message;
}
示例2: mix
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@WampCallListener(value = "messageMethod/{id}")
public String mix(String param1, CallMessage message, int param2,
WampSession wampSession, @Headers Map<String, Object> headers,
@Header(value = "WAMP_MESSAGE_TYPE") WampMessageType wampMessageType,
float param3, @DestinationVariable("id") int id, String param4) {
assertThat(param1).isEqualTo("param1");
assertThat(message).isNotNull();
assertThat(message.getDestination()).isEqualTo("messageMethod/23");
assertThat(param2).isEqualTo(2);
assertThat(wampSession).isNotNull();
assertThat(headers).hasSize(5);
assertThat(wampMessageType).isEqualTo(WampMessageType.CALL);
assertThat(param3).isEqualTo(3.3f);
assertThat(id).isEqualTo(23);
assertThat(param4).isEqualTo("param4");
return "mix";
}
示例3: submissionSyntaxChecker
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@MessageMapping("/javaparser/{taskInstanceId}")
public List<SyntaxError> submissionSyntaxChecker(
@DestinationVariable Long taskInstanceId, String submissionCode) {
logger.debug("Javaparser received message");
return JavaSyntaxChecker
.getSyntaxErrors(submissionCode)
.orElse(new ArrayList<>());
}
示例4: rateTask
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@MessageMapping("/rate/{taskInstanceId}")
public String rateTask(@DestinationVariable Long taskInstanceId, Integer rating) {
logger.debug("Rating task");
boolean rated = gameplayService
.rate(rating, taskInstanceId);
if (!rated) {
logger.debug("Rating failed!");
return "FAILED";
}
logger.debug("Rating ok!");
return "OK";
}
示例5: newConsumer
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
/**
* Serves websocket requests, requesting to start a stream on the given view.
*/
@MessageMapping("/consume/{viewId}")
@Transactional
public String newConsumer(
@DestinationVariable final Long viewId,
final ConsumeRequest consumeRequest,
final SimpMessageHeaderAccessor headerAccessor) {
// Retrieve view
final View view = viewRepository.findOne(viewId);
if (view == null) {
return "{success: false}";
}
// Build a session identifier
final long userId = getLoggedInUserId(headerAccessor);
final String sessionId = headerAccessor.getSessionId();
final SessionIdentifier sessionIdentifier = new SessionIdentifier(userId, sessionId);
// Override settings
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}";
}
示例6: pauseConsumer
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
/**
* Serves web socket requests, requesting to pause a consumer.
*/
@MessageMapping("/pause/{viewId}")
@Transactional
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, new SessionIdentifier(userId, sessionId));
return "{success: true}";
}
示例7: resumeConsumer
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
/**
* Serves web socket requests, requesting to resume a consumer.
*/
@MessageMapping("/resume/{viewId}")
@Transactional
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, new SessionIdentifier(userId, sessionId));
return "{success: true}";
}
示例8: createMesage
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@MessageMapping("/chat/{conversationId}")
@SendTo("/topic/chat/{conversationId}")
public ConversationMessage createMesage(
@Payload CreateMessage message,
@DestinationVariable String conversationId) {
log.info("handleMessage {}", message);
ConversationMessage conversationMessage = conversationService.create( message );
if(conversationMessage.isUserMessage()){
publisher.publishEvent(new UserMessageCreatedEvent(conversationMessage));
}
return conversationMessage;
}
示例9: send
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@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);
}
示例10: messageMappingDestinationVariable
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@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);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:SimpAnnotationMethodMessageHandlerTests.java
示例11: subscribeEventDestinationVariable
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@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);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:SimpAnnotationMethodMessageHandlerTests.java
示例12: sendContent
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@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()]));
}
示例13: atualizaRetrospectiva
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@MessageMapping("/retrospectiva/asndjkahsdjhds/{retrospectivaId}/{nomeUsuario}")
@SendTo("/message/retrospectiva/asndjkahsdjhds/{retrospectivaId}")
public ConteudoJson atualizaRetrospectiva(ConteudoJson conteudo, @DestinationVariable("retrospectivaId") Integer retrospectivaId, @DestinationVariable("nomeUsuario") String nomeUsuario) {
Retrospectiva retrospectiva = retrospectivaDao.loadWebSocket(retrospectivaId);
if(retrospectiva.isPublica() || (!nomeUsuario.isEmpty() && retrospectiva.isUsuarioAutorizado(usuarioDao.buscaPorNome(nomeUsuario)))) {
atualizaRetrospectiva.atualiza(retrospectiva, conteudo);
return conteudo;
} else {
return null;
}
}
示例14: handle
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@MessageMapping("/queue/channel/{channelPrivateId}")
public void handle(Message message, @DestinationVariable("channelPrivateId") String channelPrivateId, SimpMessageHeaderAccessor headerAccessor) throws IOException {
String sessionId = (String) headerAccessor.getSessionAttributes().get(HTTP_SESSION_ID_ATTR_NAME);
Channel channel = channelsManager.findByPrivateId(channelPrivateId).orElse(null);
//Find Channel
if (channel != null) {
Map map = objectMapper.readValue((byte[]) message.getPayload(), Map.class);
//Get target
String toPublicId = (String) map.get("toPublicId");
//Check if target is registered on the channel
if (channel.findUserByPublicId(toPublicId).isPresent()) {
usersManager.findUserBySessionId(sessionId).ifPresent(sender -> {
Map newMsg = builder()
.put("channel", channel)
.put("author", sender.getName())
.put("message", map.get("message"))
.put("date", System.currentTimeMillis()).build();
usersManager.findUserByPublicId((String) map.get("toPublicId")).ifPresent(u -> {
try {
this.messagingTemplate.convertAndSend("/queue/" + u.getPrivateId() + "/message", objectMapper.writeValueAsString(newMsg));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
});
});
}
}
}
示例15: subscribe
import org.springframework.messaging.handler.annotation.DestinationVariable; //导入依赖的package包/类
@WampSubscribeListener("/topic/{id}")
public void subscribe(SubscribeMessage subscribeMessage,
@DestinationVariable("id") Integer clientId) {
this.eventMessenger.sendToDirect("/topic", "join:" + clientId,
this.wsToId.keySet());
this.eventMessenger.sendTo("/topic", "IGNORED join:" + clientId,
this.wsToId.keySet());
this.wsToId.put(subscribeMessage.getWebSocketSessionId(), clientId);
}