当前位置: 首页>>代码示例>>Java>>正文


Java SendTo类代码示例

本文整理汇总了Java中org.springframework.messaging.handler.annotation.SendTo的典型用法代码示例。如果您正苦于以下问题:Java SendTo类的具体用法?Java SendTo怎么用?Java SendTo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SendTo类属于org.springframework.messaging.handler.annotation包,在下文中一共展示了SendTo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMessageToAllUsers

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
/**
 * Send the given message to all users after checking the authorization of the user.
 * @param message The message to be sent.
 * @param accessToken The oauth2 accessToken of the user.
 * @return the message to the topic
 * @throws Exception Thrown if not authorized for instance.
 */
@MessageMapping("/user-messages")
@SendTo("/topic/user-messages")
public MessageDto sendMessageToAllUsers(MessageDto message, 
    @Header("access_token") String accessToken) throws Exception {
  OAuth2AccessToken oauth2accessToken = tokenStore.readAccessToken(accessToken);
  if (oauth2accessToken != null) {
    OAuth2Authentication authentication = tokenStore.readAuthentication(oauth2accessToken);
    if (authentication != null && authentication.getAuthorities().contains(
        new SimpleGrantedAuthority("ROLE_ADMIN"))) {
      message.setSender(authentication.getUserAuthentication().getName());
      log.debug("Sending message from {} to all users", message.getSender()); 
      return message;        
    }
  }
  log.error("Unauthorized message from {} with content: {}", 
      message.getSender(), message.getText());
  throw new SessionAuthenticationException("No valid access token found!");
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:26,代码来源:UserMessagesController.java

示例2: echo

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@JmsListener(destination = "testQueue")
@SendTo("anotherQueue")
public Message<String> echo(String input, JmsMessageHeaderAccessor headerAccessor) {
	logger.info("Sending back: " + input + " (messageId=" + headerAccessor.getMessageId() + ")");
	return MessageBuilder.withPayload(input)
			.setHeader("myCustomHeader", "foo")
			.setHeader(JmsHeaders.TYPE, "myJmsType")
			.build();
}
 
开发者ID:snicoll,项目名称:scratches,代码行数:10,代码来源:DemoService.java

示例3: logoutput

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
/**
 * Gets logs.
 *
 * @return the log output
 * @throws Exception the exception
 */

@SendTo("/logs/logoutput")
public String logoutput() throws Exception {
    synchronized (LOCK) {
        final String log = LOG_OUTPUT.toString();
        LOG_OUTPUT = new StringBuilder();
        return log;
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:16,代码来源:LoggingOutputSocketMessagingController.java

示例4: say

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@MessageMapping("/welcome")//
@SendTo("/topic/getResponse")//
public BroserResponse say(MyMessage message) throws Exception{
    Thread.sleep(3000);
    System.out.println(message.getName());
    return new BroserResponse("Welcome," + message.getName()+"!");
}
 
开发者ID:shuaishuaila,项目名称:java_springboot,代码行数:8,代码来源:BMController.java

示例5: sendActivity

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@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;
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:13,代码来源:ActivityService.java

示例6: scoringNegative

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@StreamListener(CreditDecisionChannels.SCORING_NEGATIVE)
@SendTo(CreditDecisionChannels.APPLICATION_DECLINED_OUT)
public ApplicationDeclinedEvent scoringNegative(ScoringPerformedEvent event) {
	DecisionMemo decisionMemo = loadOrCreateDecisionMemo(event.getApplicationNumber());
	decisionMemo.setScoredPositive(false);
	decisionMemo.setApproved(false);
	decisionMemo.setLastUpdate(new Date());
	decisionMemoRepository.save(decisionMemo);
	return new ApplicationDeclinedEvent(event.getApplicationNumber(), "Scoring negative, auto declined");
}
 
开发者ID:mploed,项目名称:event-driven-spring-boot,代码行数:11,代码来源:IncomingMessageListener.java

示例7: sendActivity

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@SubscribeMapping("/topic/activity")
@SendTo("/topic/tracker")
public ActivityDTO sendActivity(@Payload ActivityDTO activityDTO, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
    activityDTO.setUserLogin(principal.getName());
    activityDTO.setSessionId(stompHeaderAccessor.getSessionId());
    activityDTO.setIpAddress(stompHeaderAccessor.getSessionAttributes().get(IP_ADDRESS).toString());
    activityDTO.setTime(Instant.now());
    log.debug("Sending user tracking data {}", activityDTO);
    return activityDTO;
}
 
开发者ID:xm-online,项目名称:xm-gate,代码行数:11,代码来源:ActivityService.java

示例8: send

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@MessageMapping("/chat")
@SendTo("/topic/messages")
public OutputMessage send(Message message) throws Exception {
    if(message.getFrom().toLowerCase().equals("mis bot") || message.getFrom().toLowerCase().equals("server")) {
        throw new Exception("Illegal sender username");
    }
    String time = new SimpleDateFormat("HH:mm").format(new Date());
    OutputMessage om = new OutputMessage(message.getFrom(), message.getText(), time);
    if(!om.getFrom().equals("Alert") && !om.getFrom().equals("MIS Bot") && !om.text.trim().equals("")) MongoDBInterface.addCollection(om);
    return new OutputMessage(message.getFrom(), message.getText(), time);
}
 
开发者ID:LithiumSR,项目名称:media_information_service,代码行数:12,代码来源:WebSocketController.java

示例9: getFeedback

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@MessageMapping("/chat_feedback")
@SendTo("/topic/messages")
public OutputMessage getFeedback(Message message) throws Exception {
    String time = new SimpleDateFormat("HH:mm").format(new Date());
    if(message.getText().trim().startsWith("!feedback ")) {
        String s = message.getText().substring(message.getText().indexOf(" "));
        RabbitSend.sendFeedback(message.getFrom(),s);
        Thread.sleep(1000);
        return new OutputMessage("MIS Bot","Thank you for your feedback :)",time);
    }
    else {
        Thread.sleep(1000);
        return new OutputMessage("MIS Bot","You can't leave a feedback without text :(",time);
        }
    }
 
开发者ID:LithiumSR,项目名称:media_information_service,代码行数:16,代码来源:WebSocketController.java

示例10: showOffer

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@MessageMapping("/book")
@SendTo("/topic/showOffer")
public Result showOffer(MyBook myBook) throws Exception {
	System.out.println(myBook.getBookName());

	Result result = new Result();
	result.getOffer(myBook.getBookName());
	return result;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:10,代码来源:WebSocketController.java

示例11: createMesage

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的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;
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:16,代码来源:ConversationController.java

示例12: send

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的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);
   }
 
开发者ID:jaysridhar,项目名称:spring-websocket-server,代码行数:8,代码来源:ChatController.java

示例13: supportsReturnType

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@Override
public boolean supportsReturnType(MethodParameter returnType) {
	if (returnType.getMethodAnnotation(SendTo.class) != null ||
			returnType.getMethodAnnotation(SendToUser.class) != null) {
		return true;
	}
	return (!this.annotationRequired);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:SendToMethodReturnValueHandler.java

示例14: handleAndSendToJsonView

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
@SendTo("/dest")
@JsonView(MyJacksonView1.class)
public JacksonViewBean handleAndSendToJsonView() {
	JacksonViewBean payload = new JacksonViewBean();
	payload.setWithView1("with");
	payload.setWithView2("with");
	payload.setWithoutView("without");
	return payload;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:SendToMethodReturnValueHandlerTests.java

示例15: getDefaultResponseDestination

import org.springframework.messaging.handler.annotation.SendTo; //导入依赖的package包/类
/**
 * Return the default response destination, if any.
 */
protected String getDefaultResponseDestination() {
	Method specificMethod = getMostSpecificMethod();
	SendTo ann = AnnotationUtils.getAnnotation(specificMethod, SendTo.class);
	if (ann != null) {
		Object[] destinations = ann.value();
		if (destinations.length != 1) {
			throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '" +
					specificMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
		}
		return resolve((String) destinations[0]);
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:MethodJmsListenerEndpoint.java


注:本文中的org.springframework.messaging.handler.annotation.SendTo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。