from javax.naming import Context, InitialContext from weblogic.jndi import WLInitialContextFactory from javax.jms import QueueSession, Queue, Session properties = Properties() properties[Context.PROVIDER_URL] = "t3://localhost:7001" properties[Context.INITIAL_CONTEXT_FACTORY] = WLInitialContextFactory.name ctx = InitialContext(properties) connectionFactory = ctx.lookup("weblogic/jms/XAConnectionFactory" ) queueCon = connectionFactory.createQueueConnection(); queueSession = queueCon.createQueueSession( false, Session.AUTO_ACKNOWLEDGE ); queue = ctx.lookup( "jms/testme") sender = queueSession.createSender( queue ); msg = queueSession.createTextMessage( "I am a pig " ); sender.send( msg );
If you want to resubmit to a JMS queue all the files in a folder, use this:
from javax.naming import Context, InitialContext from weblogic.jndi import WLInitialContextFactory from javax.jms import QueueSession, Queue, Session import os cfjndi="PVOSBTESTCF" queuejndi="PV_OSB_TESTQ" PROVIDER_URL="t3://acme.com:10001,acme.com:10003" filespath="/opt/oracle/scripts/retrieveErrors/thefilesfailed" properties = Properties() properties[Context.PROVIDER_URL] = PROVIDER_URL properties[Context.INITIAL_CONTEXT_FACTORY] = WLInitialContextFactory.name properties[Context.SECURITY_PRINCIPAL] = "weblogic" properties[Context.SECURITY_CREDENTIALS] = "mypassword" ctx = InitialContext(properties) connectionFactory = ctx.lookup(cfjndi) queueCon = connectionFactory.createQueueConnection(); queueSession = queueCon.createQueueSession( false, Session.AUTO_ACKNOWLEDGE ); queue = ctx.lookup(queuejndi) sender = queueSession.createSender( queue ); for file in os.listdir(filespath): current_file = os.path.join(filespath, file) data = open(current_file, "rb") msg = queueSession.createTextMessage( data.read()); print "processing ", current_file sender.send( msg ); print "done processing ", current_file
No comments:
Post a Comment