problem with receiving queue events
justin Dec 12, 2001 7:22 PMHi guys,
I'm sorry to bother you with such basic question, but ...
I wrote two simple java apps. JMS sender and JMS receiver (see code below). Sender just send one event into 'queue/testQueue', receiver tryies to read that. Problem is - it does not work. I mean I can successfully send events but can not property receive them.
- There are no exceptions during executions.
- I can see that JBoss receive events - content of db/jbossmq/.. is updated.
- I can see that receiver is up and running (lots of dots '.' on the screen, see code).
- there are no transactions.
- I tried to run it on Win2000 and Solaris boxes with jboss2.4.4 and jboss3.0.a (both clients and servers).
- jdk1.3.1
- tried blocking receive result is the same
Any ideas? Thanks!
//
// Receiver
InitialContext ctx = new InitialContext();
Object ref = ctx.lookup("ConnectionFactory");
QueueConnectionFactory queueFactory = (QueueConnectionFactory)javax.rmi.PortableRemoteObject.narrow(ref, QueueConnectionFactory.class);
QueueConnection queueConnection = queueFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
Queue queue = (javax.jms.Queue)ctx.lookup("queue/testQueue");
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
while(!shouldStop) {
Message message = queueReceiver.receiveNoWait();
if(message!=null) log.debug("Message received ["+message+"]");
else System.out.print(".");
}
queueReceiver.close();
queueSession.close();
queueConnection.close();
ctx.close();
// Sender
InitialContext ctx = new InitialContext();
Object ref = ctx.lookup("ConnectionFactory");
QueueConnectionFactory queueFactory = (QueueConnectionFactory)javax.rmi.PortableRemoteObject.narrow(ref, QueueConnectionFactory.class);
QueueConnection queueConnection = queueFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
queue = (javax.jms.Queue)ctx.lookup("queue/testQueue");
QueueSender queueSender = queueSession.createSender(queue);
TextMessage message = queueSession.createTextMessage();
message.setText("Hello World");
queueSender.send(queue, message);
queueSender.close();
queueSession.close();
queueConnection.close();
ctx.close();