can't receive message using JMS

31 views
Skip to first unread message

Mathieu Riendeau

unread,
Mar 12, 2020, 12:43:57 PM3/12/20
to ElasticMQ
I managed to send a message in my fifo queue using JMS without any problem:

        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        SQSQueueDestination queue = (SQSQueueDestination) session.createQueue(TEST_QUEUE_FIFO);
        MessageProducer producer = session.createProducer(queue);

        TextMessage txtMsg = queueSession_.createTextMessage("this is a test");
        txtMsg.setStringProperty("JMSXGroupID", "Default");
        txtMsg.setStringProperty("JMS_SQS_DeduplicationId", UUID.randomUUID().toString());

        producer_.send(txtMsg);

This works perfecly, I have some piece of code that checks the number of messages in the queue and I can see 1!

Problem is if I want to use JMS for receiving the message, the consumer outputs null on receiving().
DOESN'T WORK
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        SQSQueueDestination queue = (SQSQueueDestination) session.createQueue(TEST_QUEUE_FIFO);
        MessageConsumer consumer = session.createConsumer(queue);

        System.out.println(consumer.receive());

I tried using the AmazonSQS client and the CLI to receive the message and it works fine.
WORKS
        AmazonSQS sqs = connection.getAmazonSQSClient();
        final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queue.getQueueUrl());
        final List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
        System.out.println(messages);

WORKS
C:\>aws --endpoint-url http://localhost:9324 sqs receive-message --queue-url http://localhost:9324/queue/testQueue.fifo
{
    "Messages": [
        {
            "MessageId": "22511ffb-3221-467d-a776-aa9ffa65f7b6",
            "ReceiptHandle": "22511ffb-3221-467d-a776-aa9ffa65f7b6#1b0fe493-09c7-4027-b163-496950aaf9bf",
            "MD5OfBody": "54b0c58c7ce9f2a8b551351102ee0938",
            "Body": "this is a test"
        }
    ]
}

Anyone has an idea or suggestions?
Thanks

Mathieu Riendeau

unread,
Mar 12, 2020, 12:54:01 PM3/12/20
to ElasticMQ
BTW, I'm using the embedded version of elasticmq server.

Mathieu Riendeau

unread,
Mar 13, 2020, 3:39:42 PM3/13/20
to ElasticMQ
OK... I found the reason why...  We do not see how I create the SQSConnection but I forgot to call the SQSConnection.start() on the instanciated class. 

    public SQSConnection createConnection() throws Exception {
        SQSConnection connection = connectionFactory.createConnection();
        connection.start(); //<-- This was missing
        return connection;
    }

 
 Seems like only on the receiving of messages that this call is required! 
Reply all
Reply to author
Forward
0 new messages