from javax.naming import Context, InitialContext from weblogic.jndi import WLInitialContextFactory from javax.jms import QueueSession, Queue, Session msservers=["myhost1:8001", "myhost2:8001", "myhost3:8001", "myhost4:8001"] jmsservers=["CommonJmsServer1", "CommonJmsServer2", "CommonJmsServer3", "CommonJmsServer4"] jmsQueueJNDIs=["jms.jndi.dq.AQ", "jms.jndi.dq.BQ"]; for i in range(len(msservers)): msserver = msservers[i] jmsserver = jmsservers[i] properties = Properties() properties[Context.PROVIDER_URL] = "t3://" + msserver properties[Context.INITIAL_CONTEXT_FACTORY] = WLInitialContextFactory.name print "connecting to " + msserver + "..." ctx = InitialContext(properties) print "successfully connected to ", msserver connectionFactory = ctx.lookup("weblogic/jms/XAConnectionFactory" ) queueCon = connectionFactory.createQueueConnection(); queueCon.start() queueSession = queueCon.createQueueSession( false, Session.AUTO_ACKNOWLEDGE ); for jmsqueue in jmsQueueJNDIs: theJNDI = jmsserver + "@" + jmsqueue queue = ctx.lookup(theJNDI) queueReceiver = queueSession.createReceiver(queue) # "ISTEST='true'" condition = True print "deleting messages from " + theJNDI while (condition): message = queueReceiver.receiveNoWait() if (message != None): print 'ack on message' message.acknowledge(); condition = (message != None)
See also
http://docs.oracle.com/javaee/6/api/javax/jms/Message.html
http://docs.oracle.com/javaee/6/api/javax/jms/Queue.html
http://docs.oracle.com/javaee/6/api/javax/jms/Session.html
http://docs.oracle.com/javaee/6/api/javax/jms/QueueSession.html
http://docs.oracle.com/javaee/6/api/javax/jms/MessageConsumer.html
No comments:
Post a Comment