This content has been marked as final.
Show 3 replies
-
1. Re: How to make sure a message is delivered no more than onc
darranl Jul 12, 2005 5:13 AM (in response to radix_zero)Are you sure that you are using a queue and not a topic?
-
2. Re: How to make sure a message is delivered no more than onc
radix_zero Jul 12, 2005 11:46 AM (in response to radix_zero)yes, it is a Queue. I am a little suprised at this problem, although I have never done a Queue before usually always dealing with topics.
I need to distribute a process. a queue with multiple consumers seemed the perfect answer, because each task passed along could get grabbed by exactly one consumer.<mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=uncategorizedpages"> <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends> </mbean>
The code uses Queue in the usual way:Context ctx = new InitialContext(config); QueueConnectionFactory queueFactory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory"); Destination queueDestination = (Destination) ctx.lookup(unitQueueName); QueueConnection queueConnection = (QueueConnection) queueFactory.createConnection(unitQueueUser, unitPagesQueuePass); Session queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); List<UnitVO> batch = loadBatch(0); // for each page in the batch for (UnitVO unit : batch) { MessageProducer producer = queueSession.createProducer(queueDestination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); ObjectMessage msg = queueSession.createObjectMessage(page); producer.send(msg); producer.close(); } queueSession.close(); queueConnection.close();
Context ctx = new InitialContext(this.config); QueueConnectionFactory queueConnnectionFactory = (QueueConnectionFactory) ctx.lookup(connectionFactoryJNDIName); QueueConnection queueConnection = queueConnnectionFactory.createQueueConnection(unitQueueUser, unitQueuePass); QueueSession unitSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue unitQueue = (Queue) ctx.lookup(unitQueueName); QueueReceiver receiver = unitSession.createReceiver(unitQueue); queueConnection.start(); // until we are told to stop while (!shutdown) { Message msg = receiver.receive(1000); if (msg != null && msg instanceof ObjectMessage) { UnitVO page = (UnitVO) ((ObjectMessage) msg).getObject(); System.out.println(unit.getId()); } else { shutdown=true; } }
-
3. Re: How to make sure a message is delivered no more than onc
radix_zero Jul 12, 2005 12:36 PM (in response to radix_zero)As I experiment with this more I find that it is a time delay in removing the message from the queue.
If i sleep the consumer thread for a small random interval it helps break things up. But I still get duplicates on each consumer.