【发布时间】:2015-07-15 20:44:37
【问题描述】:
我正在使用 node js stompit 库 (https://github.com/gdaws/node-stomp) 通过 stomp 从 activemq 发送接收消息。
问题:- 有一种情况,我想安排一条消息在 n 分钟后发送。我看不出有任何方法可以使用这个库(或任何其他 nodejs 库)设置这个 AMQ_SCHEDULED_DELAY 标头
有人使用这些消息属性进行调度吗?
【问题讨论】:
我正在使用 node js stompit 库 (https://github.com/gdaws/node-stomp) 通过 stomp 从 activemq 发送接收消息。
问题:- 有一种情况,我想安排一条消息在 n 分钟后发送。我看不出有任何方法可以使用这个库(或任何其他 nodejs 库)设置这个 AMQ_SCHEDULED_DELAY 标头
有人使用这些消息属性进行调度吗?
【问题讨论】:
计划的消息值直接映射到同名的字符串值,因此 AMQ_SCHEDULED_DELAY 常量映射到消息属性中的“AMQ_SCHEDULED_DELAY”。这意味着在 STOMP 中安排消息很简单。
这是来自 ActiveMQ 的示例单元测试。
@Test
public void testSendMessageWithDelay() throws Exception {
MessageConsumer consumer = session.createConsumer(queue);
String frame = "CONNECT\n" + "login:system\n" + "passcode:manager\n\n" + Stomp.NULL;
stompConnection.sendFrame(frame);
frame = stompConnection.receiveFrame();
assertTrue(frame.startsWith("CONNECTED"));
frame = "SEND\n" + "AMQ_SCHEDULED_DELAY:2000\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World" + Stomp.NULL;
stompConnection.sendFrame(frame);
TextMessage message = (TextMessage)consumer.receive(1000);
assertNull(message);
message = (TextMessage)consumer.receive(2500);
assertNotNull(message);
}
【讨论】: