基于python使用tibco ems代码实例

yipeiwu_com5年前Python基础

 这篇文章主要介绍了基于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设计】。

相关文章

Python 详解基本语法_函数_返回值

Python 详解基本语法 概要: 函数的返回值是函数重要的组成部分。函数的根本在于实现程序的部分功能,所以很多时候我们需要将函数执行后的结果返回给程序再由程序作出进一步的操作。可以说是...

python数据清洗系列之字符串处理详解

python数据清洗系列之字符串处理详解

前言 数据清洗是一项复杂且繁琐(kubi)的工作,同时也是整个数据分析过程中最为重要的环节。有人说一个分析项目80%的时间都是在清洗数据,这听起来有些匪夷所思,但在实际的工作中确实如此。...

Python实现计算对象的内存大小示例

本文实例讲述了Python实现计算对象的内存大小。分享给大家供大家参考,具体如下: 一般的sys.getsizeof()显示不了复杂的字典。 查看类中的内容: def dump(ob...

Numpy中stack(),hstack(),vstack()函数用法介绍及实例

1.stack()函数 函数原型为:stack(arrays,axis=0),arrays可以传数组和列表。axis的含义我下面会讲解,我们先来看个例子,然后我会分析输出结果。 im...

Python学习笔记(一)(基础入门之环境搭建)

Python学习笔记(一)(基础入门之环境搭建)

  Python入门       本系列为Python学习相关笔记整理所得,IT人,多学无害,多多探索,激发学习兴趣,开拓思维...