基于python使用tibco ems代码实例
更新时间:2019年12月20日 09:36:53 作者:白马酒凉
这篇文章主要介绍了基于python使用tibco ems代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
这篇文章主要介绍了基于python使用tibco ems代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
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()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Python操作excel的方法总结(xlrd、xlwt、openpyxl)
这篇文章主要给大家介绍了关于Python操作excel的一些方法,其中包括xlrd、xlwt、openpyxl的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Python具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧2019-09-09
简单介绍Python的Django框架的dj-scaffold项目
这篇文章主要介绍了简单介绍Python的Django框架的dj-scaffold项目,用于辅助Django框架的目录设置,需要的朋友可以参考下2015-05-05
pyinstaller打包opencv和numpy程序运行错误解决
这篇文章主要介绍了pyinstaller打包opencv和numpy程序运行错误解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2019-08-08
Python数据分析Pandas Dataframe排序操作
这篇文章主要介绍了Python数据分析Pandas Dataframe排序操作,数据的排序是比较常用的操作,DataFrame 的排序分为两种,一种是对索引进行排序,另一种是对值进行排序,接下来就分别都介绍一下,需要的小伙伴可以参考一下2022-05-05


最新评论