Sam
Sam

Reputation: 6910

I send a scheduled message to activemq broker but two message shown in web console

I wrote a simple ActiveMQ client program for produce a message as following:

public static void main(String[] args) throws Throwable
{
    final ActiveMQConnectionFactory conFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    final QueueConnection connection = conFactory.createQueueConnection();
    final Session session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    final Destination destination = new ActiveMQQueue("MJ_SAF");
    final MessageProducer producer = session.createProducer(destination);

    Message message = session.createTextMessage("test");
    message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, 20);
    message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1);
    message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
    producer.send(message);
}

when this program executed I expect a message stored in scheduled part of ActiveMQ and after 20 second send for MJ_SAF queue but when I connect to web consol saw following result:

enter image description here

stored two messages at MJ_SAF and it's not correct but when I normally send message (without scheduling), I see a message in web console.

public static void main(String[] args) throws Throwable
{
    final ActiveMQConnectionFactory conFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    final QueueConnection connection = conFactory.createQueueConnection();
    final Session session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    final Destination destination = new ActiveMQQueue("MJ_SAF");
    final MessageProducer producer = session.createProducer(destination);

    Message message = session.createTextMessage("test");
    producer.send(message);
}

by above code all things is nice:

enter image description here

I don't understand this behavior. Does anyone know reasons of this?

Upvotes: 0

Views: 2069

Answers (1)

BruteForce
BruteForce

Reputation: 301

You have the property ScheduledMessage.AMQ_SCHEDULED_REPEAT set to 1, so it will repeat 1 time giving you a total of 2 messages.

See here for the descriptions of the properties. As I understand it, your current set up will wait 20 milliseconds, publish 1 message, wait 1 millisecond, and publish a second message, then end.

Upvotes: 4

Related Questions