本文整理匯總了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!");
}
示例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();
}
示例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;
}
}
示例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()+"!");
}
示例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;
}
示例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");
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}