【问题标题】:How to delay activemq message using Stomp (AMQ_SCHEDULED_DELAY)如何使用 Stomp (AMQ_SCHEDULED_DELAY) 延迟 activemq 消息
【发布时间】:2015-07-15 20:44:37
【问题描述】:

我正在使用 node js stompit 库 (https://github.com/gdaws/node-stomp) 通过 stomp 从 activemq 发送接收消息。

问题:- 有一种情况,我想安排一条消息在 n 分钟后发送。我看不出有任何方法可以使用这个库(或任何其他 nodejs 库)设置这个 AMQ_SCHEDULED_DELAY 标头

有人使用这些消息属性进行调度吗?

【问题讨论】:

    标签: node.js activemq stomp


    【解决方案1】:

    计划的消息值直接映射到同名的字符串值,因此 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-15
      • 2016-06-20
      • 2015-09-29
      • 1970-01-01
      • 2021-11-22
      • 2014-09-27
      • 1970-01-01
      • 2019-09-29
      相关资源
      最近更新 更多