The following code snippet (standalone Java-application) will never find any messages on the queue while the same client, when implemented using message listeners, does (Using Glassfish 3.1):
ctx = new InitialContext();
connectionFactory = (ConnectionFactory) ctx.lookup("foo.Factory");
partsQueue = (Queue) ctx.lookup("foo.PartsQueue");
conn = connectionFactory.createConnection();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(partsQueue);
conn.start();
Message msg = null;
int cnt = -1;
do {
cnt++;
msg = consumer.receiveNoWait();
} while (msg != null);
System.out.println("cnt: " + cnt);
If I use the following code after creating the consumer, the listener will find the messages and consume them successfully:
listener = new AssemblerListener(this);
consumer.setMessageListener(listener);
System.out.println("waiting for msgs...");
conn.start();
As mentioned, standalone Java client, I’m not trying to do something in MDBs synchronously. Any ideas? Did not find any hints why synchronous read should not work here. Using message listeners is not the best option in this case as I have to read two messages using different filters sometimes.
This is the way i receive Meessages: