- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有以下代码:
@Controller
@EnableScheduling
public class QuoteController {
@Scheduled(fixedDelay=5000)
@SendTo(value="/topic/quote")
public String sendPrice() {
return "message from scheduler";
}
}
它不会将消息发送到 channel 。但是下面的代码有效:
@Controller
@EnableScheduling
public class QuoteController {
@Autowired
public SimpMessageSendingOperations messagingTemplate;
@Scheduled(fixedDelay=5000)
public String sendPrice() {
messagingTemplate.convertAndSend("/topic/quote", "message from scheduler");
}
}
最佳答案
我们应该只在 websocket 调用的函数中使用 @SendTo
注释,它是指使用 @MessageMapping
注释的函数。
如果您想以其他方式将消息发送到队列,您应该使用messagingTemplate.convertAndSend
。
@SendTo
示例:
@MessageMapping("/hello") // from websocket
@SendTo("/topic/bla")
public String foo1(String message) {
return message;
}
.convertAndSend
示例:
@Autowired
private SimpMessagingTemplate template;
@GetMapping("/{msg}") //from GET request
public void foo2(@PathVariable String msg) {
template.convertAndSend("/topic/bla", msg);
}
关于java - convertAndSend 与 Send To 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53179604/
我正在阅读 Spring Framework reference ,关于 JMS 集成的章节。有一些发送文本消息和异步接收它们(通过监听器)的示例。还有一个 JmsTemplate 函数 conver
我有以下代码: @Controller @EnableScheduling public class QuoteController { @Scheduled(fixedDelay=5000)
我正在使用 RabbitMQ 将消息发送到队列,在消费者中我得到它,但我无法转换它。 当我发送它时,我会这样做。 rabbitTemplate.convertAndSend("myExchange",
我是 Spring boot websocket 和消息传递语义的新手。目前我可以使用以下代码发送私有(private)消息。 String queueName = "/user/" + userna
这是一个小的 Spring 程序,它希望将一条消息插入到 rabbitmq 队列中: public class Main { public static void main(String [] a
我正在使用带有 RabbitMQ 的 Spring STOMP over Websocket。一切正常,但 simpMessagingTemplate.convertAndSend 工作速度很慢,调用
我在尝试使用 RabbitTemplate.convertAndSend 发布消息时随机遇到 NullPointerException 我尝试了 spring-amqp:1.7.6 和 spring-
对于 Spring Websocket 我有以下内容并且工作正常: private final SimpMessagingTemplate simpMessagingTemplate; ... @Sc
我正在尝试测试 RabbitTemplate#convertAndSend编写为 lambda 的方法,如下所示: // other stuff omitted for brevity
我是一名优秀的程序员,十分优秀!