Search code examples
node.jsactivemq-classicstomp

How to delay activemq message using Stomp (AMQ_SCHEDULED_DELAY)


i am using sending receiving messages from activemq over stomp using node js stompit library (https://github.com/gdaws/node-stomp).

Issue:- There is a case where i want to schedule a message to be send after n minutes. I don't see any way i can set this AMQ_SCHEDULED_DELAY header using this library (or any other nodejs library)

Has anybody used these message properties for scheduling.


Solution

  • The scheduled message values map directly to string values of the same name so the AMQ_SCHEDULED_DELAY constant maps to "AMQ_SCHEDULED_DELAY" in the message properties. This means it is simple to schedule a message in STOMP.

    Here is a sample unit test from 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);
    }