基于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设计】。

相关文章

Python3之字节串bytes与字节数组bytearray的使用详解

字节串bytes 字节串也叫字节序列,是不可变的序列,存储以字节为单位的数据 字节串表示方法: b"ABCD" b"\x41\x42" ... 字节串的构造函数: bytes()...

利用Python校准本地时间的方法教程

利用Python校准本地时间的方法教程

1. 概念 1.1 基本概念 时间,对于我们来说很重要,什么时候做什么?什么时候发生什么?没有时间的概念,生活就乱了。 在日常的运维当中,我们更关注告警的时间:什么时候发生、什么事故...

Python中查看变量的类型内存地址所占字节的大小

Python中查看变量的类型,内存地址,所占字节的大小 查看变量的类型 #利用内置type()函数 >>> nfc=["Packers","49"] >>...

python基于递归解决背包问题详解

递归是个好东西,任何具有递归性质的问题通过函数递归调用会变得很简单。一个很复杂的问题,几行代码就能搞定。   最简单的递归问题:现有重量为weight的包,有若干重量分别为W1...

python链接oracle数据库以及数据库的增删改查实例

初次使用python链接oracle,所以想记录下我遇到的问题,便于向我这样初次尝试的朋友能够快速的配置好环境进入开发环节。 1.首先,python链接oracle数据库需要配置好环境。...