• python 使用 tibco ems


    emshelper.py

    #encoding=utf-8
    import jpype
    
    
    jvmpath=r"C:Program FilesJavajre1.8.0_161inserverjvm.dll"
    
    class EmsHelper(object):
        def __init__(self, server= "tcp://localhost:7222",user="admin",pwd=""):
            gemsjar = r"E:EDriversoftwareJAVAjarGems.jar;D:	ibcow5ems8.2lib	ibjms.jar;D:	ibcow5ems8.2lib	ibcrypt.jar;D:	ibcow5ems8.2libslf4j-api-1.4.2.jar;D:	ibcow5ems8.2libslf4j-simple-1.4.2.jar;D:	ibcow5ems8.2lib	ibjmsadmin.jar;D:	ibcow5ems8.2libjms-2.0.jar;D:	ibcow5ems8.2libjndi.jar" 
            #gemsjar = r"D:	ibcow5ems8.2libjms-2.0.jar;E:EDriversoftwareJAVAjar	ibjms.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()
  • 相关阅读:
    Kafka写入流程和副本策略
    Kafka消费分组和分区分配策略
    Kafka安装和常用操作命令
    面试:谈谈你对大数据的理解
    HDFS写数据和读数据流程
    java笔记之分支、循环语句
    java笔记之分支、循环语句
    java笔记之运算符
    java笔记之运算符
    java笔记之java内存结构
  • 原文地址:https://www.cnblogs.com/sui84/p/8515799.html
Copyright © 2020-2023  润新知