- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个使用消息代理 (activemq) 的带有 spring 和 websockets 的 webapp。
这是我的配置类:
@Configuration
@EnableWebSocketMessageBroker
@EnableScheduling
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableStompBrokerRelay("/topic","/queue/");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/hello").withSockJS();
}
}
我有一个计划任务不断向用户名“StanTheMan”推送消息:
@Scheduled(fixedDelay = 1000)
public void sendGreetings() {
HelloMessage hello = new HelloMessage();
hello.setContent("timeStamp:" + System.currentTimeMillis());
String queueMapping = "/queue/greetings";
template.convertAndSendToUser(
"DannyD",
queueMapping,
hello);
}
目前,如果用户没有通过 websocket 连接到服务器 - 他的所有消息都没有被排队等待,它们只是丢弃。每当他连接时 - 新消息正在为他排队。我是否可以通过任何方式将消息“convertAndSendToUser”发送给离线用户?我想为离线用户加入过期时间的消息,以便稍后在他们再次连接且过期时间未结束时推送。
我怎样才能做到这一点?显然,使用真正的消息代理 (activemq) 应该有助于实现这一目标,但如何实现呢?
谢谢!
最佳答案
事实上,此功能只能用于向(当前)连接的用户发送消息。
我们计划提供更好的方法来跟踪失败的消息(参见 SPR-10891)。同时,作为一种解决方法,您可以将 UserSessionRegistry
注入(inject)到您的 @Scheduled 组件中,并检查 getSessionIds 方法是否返回非空 Set。这将表明用户已连接。
一种替代方法可能是使用您自己的队列名称约定,每个用户都可以订阅该队列名称(可能基于他们的用户名或其他足够独特的名称)以便接收持久消息。 ActiveMQ STOMP page有一个关于持久消息和过期时间的部分。
关于java - Spring websockets : sending a message to an offline user - messages not enqueued in message broker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23782390/
我正在从不同来源获取新闻提要并添加到数据库,但我遇到异常 Error: Cannot enqueue Handshake after already enqueuing a Handshake. at
嘿,大家好,我只是想制作一个简单的表单,将数据发送到 mySQL 数据库。我的问题是提交后我无法再提交另一份。它只允许我提交表单一次,然后在第二次提交后,我收到此错误“错误:在已经排队握手后无法排队握
我每 5 秒查询一个表并向用户显示。我使用的是mysql 8。应用程序是nodejs。 var con = mysql.createConnection({ host: "localhost",
我正在尝试创建两个函数,一个从 SQL 数据库检索对象,另一个将对象保存到同一个 SQL 数据库。我使用 node.js 和 mysql 来执行此操作。我有两个函数,fetchEmployee 和 E
我需要一个具有固定容量但始终允许线程将项目添加到开头的 Java 列表。如果它已满,它应该从末尾删除一个项目以腾出空间。没有其他进程会删除项目,但其他进程会希望迭代这些项目。 JDK 中有什么东西可以
我在 tensorflow 中构建了一个卷积神经网络。它经过培训,现在我正在打开它并进行评估。 import main import Process import Input eval_dir = "
如果last会变成x,为什么last.next会被分配给x?我不明白将 x 分配给 last.next 有何影响。这是队列的完整上下文:http://introcs.cs.princeton.edu/
我在创建具有双因素身份验证的应用程序时遇到了一些麻烦。我决定使用 twilio 作为我的短信网关,并决定遵循他们的教程。然而,尽管已经导入了我需要的内容,但我遇到了无法解决排队问题。 import a
注册样式表然后将其入队与直接入队有何不同? 我在这里注册然后排队。 function calling_script(){ wp_register_style('bootstrap',
假设我有一个模块,其中有一个队列。 对于其他实体入队,它们必须通过一个函数: public sub InsertIntoQueue(Obj) MyQueue.Enqueue(Obj) end
我有一个包含 6 个库的列表,我想加载到我的 WordPress 插件/主题中。目前它们都像这样添加到主题的标题中。 我正在构建一个插件,它有自己的脚本,依赖于这些库。我想运行我提出的这个解决方案,
只需要一些关于 WP en 队列的信息,我已经在各个网站上学习了一些教程,因为我是一个非常基础的网页设计师,我主要使用 HTML CSS 至少这是我最了解的。 我无法最好地解释我哪里出了问题,但我可以
有没有办法在一定时间后重定向队列中的调用? 我在 Twiml 中知道 您可以设置超时。 有没有办法在 中做到这一点?甚至 作为它的一部分 waitURL 现在我正在做这样的事情:
目前正在准备考试,无法弄清楚示例代码中 queue[rear*] = new_node 背后的原因。 你不是把 new_node 的地址而不是值放进去吗? 还有,这个队列是不是Node**队列,因为它
我是编程新手。尝试编写一个函数来接收列表的头部 + 要插入的数据 - 并传回列表的新头部。我已经通过将元素添加到列表的头部来完成很多工作,但出于某种原因,我无法理解这个细微的差别。 #include
我是队列实现的新手,需要一些帮助来练习。 假设我正在使用 enqueue 对 4 个人进行排队,并且我想向输出添加一个函数,以显示 1 到 10 之间的随机数“x”4 次,并符合以下条件: 如果“x”
首先,我将解释一个简短的场景; 当来自某些设备的信号触发时,一个类型为 Alarm 的对象被添加到队列中。每隔一段时间检查队列,并针对队列中的每个警报触发一个方法。 但是,我遇到的问题是,如果在遍历队
有人可以解释一下主要区别吗?我对任何语言的编程中的这些功能都没有清楚的了解。 最佳答案 C 和 C++ 等编程语言中的一些基本数据结构是堆栈和队列。 堆栈数据结构遵循“先进后出”策略 (FILO),其
private Queue _queueObject = new Queue(); private static Queue _queueItem = new Queue(); private sta
我在CircularArrayQueue类中遇到了enqueue()方法: public void enqueue (T element) { if (size() == queue.length){
我是一名优秀的程序员,十分优秀!