MessageConsumer is not consuming messages

Viewed 7765

My application is running on Jboss 7.1.1. I have a scheduler that runs every one minute and needs to check if there are messages in the DLQ and do some updates in the DB.

I wrote a message consumer that listens to a predefined custom DLQ. The problem is that i can see that there are messages in the custom DLQ but consumer.receiveNoWait() always return null.

Here is the code for creating the consumer:

/*this is running fine and creating the consumer*/
public DestinationHandlerImpl(ConnectionFactory connectionFactory,
    Destination destination, boolean useTransaction, int delMode,
    boolean isProducer) throws JMSException {
    connection = connectionFactory.createConnection();
    consumer = session.createConsumer(destination);
}

Here is the code that consumes the message (runs every one minute):

/*this always return null, event when there are messages in the queue*/
public <T extends BaseEvent> T recieveMessage()
        throws JMSException {

    Message message = consumer.receiveNoWait(); // ----> always return null!!!

    if (message != null && !(message instanceof ObjectMessage)) {
        throw new IllegalArgumentException(
                "message object has to be of type ObjectMessage");
    }

    // Extract the object from the message
    return message == null ? null : (T) ((ObjectMessage) message).getObject();

}

I've used debug mode and i can see the consumer destination property is set to the right queue, so what am i doing wrong?

2 Answers
Related