您好,登錄后才能下訂單哦!
tibco ems怎么在python項目中使用?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
TIBCO Enterprise Message Service 是一個消息服務器產品
完全支持JMS的通訊協議,在運行速度和消息吞吐量上表現非常出色,
對于Windows、Linux、Mac、AIX平臺都提供支持
代碼如下
#encoding=utf-8 import jpype jvmpath=r"C:\Program Files\Java\jre1.8.0_161\bin\server\jvm.dll" class EmsHelper(object): def __init__(self, server= "tcp://localhost:7222",user="admin",pwd=""): gemsjar = r"E:\EDriver\software\JAVA\jar\Gems.jar;D:\tibco\bw5\ems\8.2\lib\tibjms.jar;D:\tibco\bw5\ems\8.2\lib\tibcrypt.jar;D:\tibco\bw5\ems\8.2\lib\slf4j-api-1.4.2.jar;D:\tibco\bw5\ems\8.2\lib\slf4j-simple-1.4.2.jar;D:\tibco\bw5\ems\8.2\lib\tibjmsadmin.jar;D:\tibco\bw5\ems\8.2\lib\jms-2.0.jar;D:\tibco\bw5\ems\8.2\lib\jndi.jar" #gemsjar = r"D:\tibco\bw5\ems\8.2\lib\jms-2.0.jar;E:\EDriver\software\JAVA\jar\tibjms.jar" jvmArg = "-Djava.class.path=.;%s" % gemsjar jpype.startJVM(jvmpath,jvmArg) self.TibjmsConnection = jpype.JClass('com.tibco.tibjms.TibjmsConnection') self.TibjmsConnectionFactory = jpype.JClass('com.tibco.tibjms.TibjmsConnectionFactory') def SendQueueMsg(self,qname="testq",msgstr=str({'id':1,'name':"tname"})): connfac = self.TibjmsConnectionFactory(server) conn=connfac.createConnection(user,pwd) session=conn.createSession(0,1) dest=session.createQueue(qname) msgProducer = session.createProducer(None) msg = session.createTextMessage() msg.setText(msgstr) msgProducer.send(dest, msg) conn.close() def ShowQueueMsg(self,qname="testq",maxlen=5): connfac = self.TibjmsConnectionFactory(server) conn=connfac.createConnection(user,pwd) session=conn.createSession() queue = session.createQueue(qname) browser = session.createBrowser(queue) msgs = browser.getEnumeration() num = 0 while(msgs.hasMoreElements()): num+=1 message =msgs.nextElement() print message.getText() if(num>=maxlen): break browser.close() conn.close() def HandleOneQueueMsg(self,qname="testq"): connfac = self.TibjmsConnectionFactory(server) conn=connfac.createConnection(user,pwd) session=conn.createSession() queue = session.createQueue(qname) dest=session.createQueue(qname) msgConsumer = session.createConsumer(dest) conn.start() msg = msgConsumer.receive() msg.acknowledge() self.HandleMsg(msg.getText()) conn.close() def HandleMsg(self,msgstr): print "message is : ",msgstr if __name__ == '__main__': server,user,pwd,qname,msgstr="tcp://localhost:7222","admin","","testq",str({'id':1,'name':"tname"}) eh=EmsHelper(server,user,pwd) eh.HandleQueueMsg()
看完上述內容,你們掌握tibco ems怎么在python項目中使用的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。