コード例 #1
0
ファイル: test_rfh2_put_get.py プロジェクト: comtech-et/pymqi
    def test_put_rfh2_single(self):
        """Create and put a new rfh2 and use get to get it from the queue.  Compare it against know correct message.
        """
        try:

            put_mqmd = pymqi.md()
            put_mqmd["Format"] = CMQC.MQFMT_RF_HEADER_2
            put_mqmd["Encoding"] = 273
            put_mqmd["CodedCharSetId"] = 1208

            put_opts = pymqi.pmo()

            put_rfh2 = pymqi.RFH2()
            put_rfh2["StrucId"] = CMQC.MQRFH_STRUC_ID
            put_rfh2["Version"] = CMQC.MQRFH_VERSION_2
            put_rfh2["StrucLength"] = 188
            put_rfh2["Encoding"] = 273
            put_rfh2["CodedCharSetId"]= 1208
            put_rfh2["Format"] =  CMQC.MQFMT_STRING
            put_rfh2["Flags"] = 0
            put_rfh2["NameValueCCSID"] = 1208
            put_rfh2.add_folder("<psc><Command>RegSub</Command><Topic>$topictree/topiccat/topic</Topic><QMgrName>DebugQM</QMgrName><QName>PUBOUT</QName><RegOpt>PersAsPub</RegOpt></psc>")
            put_rfh2.add_folder("<testFolder><testVar>testValue</testVar></testFolder>")
            put_rfh2.add_folder("<mcd><Msd>xmlnsc</Msd></mcd>")
            put_msg = "<testData><testVar>testValue</testVar></testData>"
            self.put_queue.put_rfh2(put_msg, put_mqmd, put_opts, [put_rfh2])

            get_mqmd = pymqi.md()
            get_opts = pymqi.gmo()
            get_msg = self.get_queue.get(None, get_mqmd, get_opts)

            self.assertEqual(get_msg, self.single_rfh2_message, "Message got from Queue does not match known correct RFH2 message.")
        except Exception as e:
            self.fail(e)
コード例 #2
0
ファイル: test_rfh2_put_get.py プロジェクト: comtech-et/pymqi
    def test_get_rfh2_multiple(self):
        """Use get_rfh2 to get a known correct 3rd party message containing Multiples RFH2 headers.
        """

        try:

            put_mqmd = pymqi.md()
            put_mqmd["Format"] = CMQC.MQFMT_RF_HEADER_2
            put_mqmd["Encoding"] = 273
            put_mqmd["CodedCharSetId"] = 1208
            self.put_queue.put(self.multiple_rfh2_message, put_mqmd)

            get_mqmd = pymqi.md()
            get_opts = pymqi.gmo()
            rfh2_list = []
            msg = self.get_queue.get_rfh2(None, get_mqmd, get_opts, rfh2_list)

            self.assertEqual(len(rfh2_list), 2, "Number of RFH2's incorrect.  Should be 2.  But is %i" % len(rfh2_list))

            rfh2_1 = rfh2_list[0]
            self.assertEqual(len(rfh2_1.get()), 12, "Number of attributes incorrect.  Should be 12? But is %s" % str(len(rfh2_1.get())))
            self.assertEqual(rfh2_1["StrucId"], CMQC.MQRFH_STRUC_ID, "StrucId has incorrect value. Should be: %s But is: %s" % (CMQC.MQRFH_STRUC_ID, str(rfh2_1["StrucId"])))
            self.assertEqual(rfh2_1["Version"], CMQC.MQRFH_VERSION_2, "Version has incorrect value. Should be: %i But is: %s" % (CMQC.MQRFH_VERSION_2, str(rfh2_1["Version"])))
            self.assertEqual(rfh2_1["StrucLength"], 252, "StrucLength has incorrect value. Should be: %i But is: %s" % (284, str(rfh2_1["StrucLength"])))
            self.assertEqual(rfh2_1["Encoding"], 273, "Encoding has incorrect value. Should be: %i But is: %s" % (273, str(rfh2_1["Encoding"])))
            self.assertEqual(rfh2_1["CodedCharSetId"], 1208, "CodedCharSetId has incorrect value. Should be: %i But is: %s" % (1208, str(rfh2_1["CodedCharSetId"])))
            self.assertEqual(rfh2_1["Format"], CMQC.MQFMT_RF_HEADER_2, "Format has incorrect value. Should be: %s But is: %s" % (CMQC.MQFMT_RF_HEADER_2, str(rfh2_1["Format"])))
            self.assertEqual(rfh2_1["Flags"], 0, "Flags has incorrect value. Should be: %i But is: %s" % (0, str(rfh2_1["Flags"])))
            self.assertEqual(rfh2_1["NameValueCCSID"], 1208, "NameValueCCSID has incorrect value. Should be: %i But is: %s" % (1208, str(rfh2_1["NameValueCCSID"])))
            self.assertEqual(rfh2_1["pscLength"], 152, "pscLength has incorrect value. Should be: %i But is: %s" % (152, str(rfh2_1["pscLength"])))
            self.assertEqual(rfh2_1["psc"], "<psc><Command>RegSub</Command><Topic>$topictree/topiccat/topic</Topic><QMgrName>DebugQM</QMgrName><QName>PUBOUT</QName><RegOpt>PersAsPub</RegOpt></psc> ", "psc has incorrect value. Should be: %s But is: %s" % ("<psc><Command>RegSub</Command><Topic>$topictree/topiccat/topic</Topic><QMgrName>DebugQM</QMgrName><QName>PUBOUT</QName><RegOpt>PersAsPub</RegOpt></psc> ", ">" + str(rfh2_1["psc"]) + "<"))
            self.assertEqual(rfh2_1["testFolderLength"], 56, "testFolderLength has incorrect value. Should be: %i But is: %s" % (56, str(rfh2_1["testFolderLength"])))
            self.assertEqual(rfh2_1["testFolder"], "<testFolder><testVar>testValue</testVar></testFolder>   ", "testFolder has incorrect value. Should be: %s But is: %s" % ("<testFolder><testVar>testValue</testVar></testFolder>   ", str(rfh2_1["testFolder"])))

            rfh2_2 = rfh2_list[1]
            self.assertEqual(len(rfh2_2.get()), 14, "Number of attributes incorrect.  Should be 14? But is %s" % str(len(rfh2_2.get())))
            self.assertEqual(rfh2_2["StrucId"], CMQC.MQRFH_STRUC_ID, "StrucId has incorrect value. Should be: %s But is: %s" % (CMQC.MQRFH_STRUC_ID, str(rfh2_2["StrucId"])))
            self.assertEqual(rfh2_2["Version"], CMQC.MQRFH_VERSION_2, "Version has incorrect value. Should be: %i But is: %s" % (CMQC.MQRFH_VERSION_2, str(rfh2_2["Version"])))
            self.assertEqual(rfh2_2["StrucLength"], 284, "StrucLength has incorrect value. Should be: %i But is: %s" % (284, str(rfh2_2["StrucLength"])))
            self.assertEqual(rfh2_2["Encoding"], 273, "Encoding has incorrect value. Should be: %i But is: %s" % (273, str(rfh2_2["Encoding"])))
            self.assertEqual(rfh2_2["CodedCharSetId"], 1208, "CodedCharSetId has incorrect value. Should be: %i But is: %s" % (1208, str(rfh2_2["CodedCharSetId"])))
            self.assertEqual(rfh2_2["Format"], CMQC.MQFMT_STRING, "Format has incorrect value. Should be: %s But is: %s" % (CMQC.MQFMT_STRING, str(rfh2_2["Format"])))
            self.assertEqual(rfh2_2["Flags"], 0, "Flags has incorrect value. Should be: %i But is: %s" % (0, str(rfh2_2["Flags"])))
            self.assertEqual(rfh2_2["NameValueCCSID"], 1208, "NameValueCCSID has incorrect value. Should be: %i But is: %s" % (1208, str(rfh2_2["NameValueCCSID"])))
            self.assertEqual(rfh2_2["pscLength"], 152, "pscLength has incorrect value. Should be: %i But is: %s" % (152, str(rfh2_2["pscLength"])))
            self.assertEqual(rfh2_2["psc"], "<psc><Command>RegSub</Command><Topic>$topictree/topiccat/topic</Topic><QMgrName>DebugQM</QMgrName><QName>PUBOUT</QName><RegOpt>PersAsPub</RegOpt></psc> ", "psc has incorrect value. Should be: %s But is: %s" % ("<psc><Command>RegSub</Command><Topic>$topictree/topiccat/topic</Topic><QMgrName>DebugQM</QMgrName><QName>PUBOUT</QName><RegOpt>PersAsPub</RegOpt></psc> ", ">" + str(rfh2_2["psc"]) + "<"))
            self.assertEqual(rfh2_2["testFolderLength"], 56, "testFolderLength has incorrect value. Should be: %i But is: %s" % (56, str(rfh2_2["testFolderLength"])))
            self.assertEqual(rfh2_2["testFolder"], "<testFolder><testVar>testValue</testVar></testFolder>   ", "testFolder has incorrect value. Should be: %s But is: %s" % ("<testFolder><testVar>testValue</testVar></testFolder>   ", str(rfh2_2["testFolder"])))
            self.assertEqual(rfh2_2["mcdLength"], 28, "mcdLength has incorrect value. Should be: %i But is: %s" % (28, str(rfh2_2["mcdLength"])))
            self.assertEqual(rfh2_2["mcd"], "<mcd><Msd>xmlnsc</Msd></mcd>", "mcd has incorrect value. Should be: %s But is: %s" % ("<mcd><Msd>xmlnsc</Msd></mcd>", str(rfh2_2["mcd"])))


            self.assertEqual(msg, self.multiple_rfh2_message[rfh2_1["StrucLength"] + rfh2_2["StrucLength"]:], "Message Payloads do not match?")

        except Exception as e:
            self.fail(e)
コード例 #3
0
ファイル: test_rfh2_put_get.py プロジェクト: comtech-et/pymqi
    def test_put_get_rfh2_multiple(self):
        """Create and put a new RFH2 message containing multiple RFH2 headers with put_rfh2 and use get_rfh2 to get it from the queue.  Compare it against know correct message.
        """

        try:
            put_mqmd = pymqi.md()
            put_mqmd["Format"] = CMQC.MQFMT_RF_HEADER_2
            put_mqmd["Encoding"] = 273
            put_mqmd["CodedCharSetId"] = 1208

            put_opts = pymqi.pmo()

            put_rfh2_1 = pymqi.RFH2()
            put_rfh2_1["StrucId"] = CMQC.MQRFH_STRUC_ID
            put_rfh2_1["Version"] = CMQC.MQRFH_VERSION_2
            put_rfh2_1["StrucLength"] = 188
            put_rfh2_1["Encoding"] = 273
            put_rfh2_1["CodedCharSetId"]= 1208
            put_rfh2_1["Format"] =  CMQC.MQFMT_RF_HEADER_2
            put_rfh2_1["Flags"] = 0
            put_rfh2_1["NameValueCCSID"] = 1208
            put_rfh2_1.add_folder("<psc><Command>RegSub</Command><Topic>$topictree/topiccat/topic</Topic><QMgrName>DebugQM</QMgrName><QName>PUBOUT</QName><RegOpt>PersAsPub</RegOpt></psc>")
            put_rfh2_1.add_folder("<testFolder><testVar>testValue</testVar></testFolder>")

            put_rfh2_2 = pymqi.RFH2()
            put_rfh2_2["StrucId"] = CMQC.MQRFH_STRUC_ID
            put_rfh2_2["Version"] = CMQC.MQRFH_VERSION_2
            put_rfh2_2["StrucLength"] = 188
            put_rfh2_2["Encoding"] = 273
            put_rfh2_2["CodedCharSetId"]= 1208
            put_rfh2_2["Format"] =  CMQC.MQFMT_STRING
            put_rfh2_2["Flags"] = 0
            put_rfh2_2["NameValueCCSID"] = 1208
            put_rfh2_2.add_folder("<psc><Command>RegSub</Command><Topic>$topictree/topiccat/topic</Topic><QMgrName>DebugQM</QMgrName><QName>PUBOUT</QName><RegOpt>PersAsPub</RegOpt></psc>")
            put_rfh2_2.add_folder("<testFolder><testVar>testValue</testVar></testFolder>")
            put_rfh2_2.add_folder("<mcd><Msd>xmlnsc</Msd></mcd>")
            put_rfh2_list = [put_rfh2_1, put_rfh2_2]
            put_msg = "<testData><testVar>testValue</testVar></testData>"

            self.put_queue.put_rfh2(put_msg, put_mqmd, put_opts, put_rfh2_list)

            get_mqmd = pymqi.md()
            get_opts = pymqi.gmo()
            get_rfh2_list = []
            get_msg = self.get_queue.get_rfh2(None, get_mqmd, get_opts, get_rfh2_list)

            self.assertEqual(len(get_rfh2_list), len(put_rfh2_list), "Number of RFH2's incorrect.  Should be %i.  But is %i" % (len(get_rfh2_list), len(put_rfh2_list)))
            self.assertEqual(get_rfh2_list[0].get(), put_rfh2_list[0].get()), "Put and Get RFH2 Lists do not match."
            self.assertEqual(get_rfh2_list[1].get(), put_rfh2_list[1].get()), "Put and Get RFH2 Lists do not match."
            self.assertEqual(get_msg, put_msg, "Put and Get messages do not match.")

        except Exception as e:
            self.fail(e)
コード例 #4
0
    def test_pubsub_api_managed_non_durable_rfh2(self):
        topic_string = self.topic_string_template.format(type="API_RFH2",
                                                         destination="MANAGED",
                                                         durable="NON DURABLE")
        subname = self.subname_template.format(type="Api_rfh2",
                                               destination="Managed",
                                               durable="Non Durable")
        msg = self.msg_format(topic_string=topic_string)
        sub_desc = self.get_subscription_descriptor(
            subname, topic_string,
            pymqi.CMQC.MQSO_CREATE + pymqi.CMQC.MQSO_MANAGED)
        # register Subscription
        sub = self.create_api_subscription()
        self.sub_desc_list = [(sub, sub_desc, None)]
        sub.sub(sub_desc=sub_desc)

        # publish (put)
        put_mqmd = pymqi.md(Format=pymqi.CMQC.MQFMT_RF_HEADER_2,
                            Encoding=273,
                            CodedCharSetId=1208)

        put_opts = pymqi.pmo()

        put_rfh2 = pymqi.RFH2(StrucId=pymqi.CMQC.MQRFH_STRUC_ID,
                              Version=pymqi.CMQC.MQRFH_VERSION_2,
                              StrucLength=188,
                              Encoding=273,
                              CodedCharSetId=1208,
                              Format=pymqi.CMQC.MQFMT_STRING,
                              Flags=0,
                              NameValueCCSID=1208)
        put_rfh2.add_folder(
            b"<psc><Command>RegSub</Command><Topic>$topictree/topiccat/topic</Topic><QMgrName>DebugQM</QMgrName><QName>PUBOUT</QName><RegOpt>PersAsPub</RegOpt></psc>"
        )
        put_rfh2.add_folder(
            b"<testFolder><testVar>testValue</testVar></testFolder>")
        put_rfh2.add_folder(b"<mcd><Msd>xmlnsc</Msd></mcd>")

        self.pub_rfh2(msg, topic_string, put_mqmd, put_opts, [put_rfh2])
        get_opts = pymqi.GMO(Version=pymqi.CMQC.MQGMO_VERSION_4,
                             WaitInterval=15000,
                             Options=pymqi.CMQC.MQGMO_NO_SYNCPOINT + \
                                    pymqi.CMQC.MQGMO_FAIL_IF_QUIESCING + \
                                    pymqi.CMQC.MQGMO_WAIT)
        get_rfh2_list = []
        data = sub.get_rfh2(None, pymqi.md(Version=pymqi.CMQC.MQMD_VERSION_2),
                            get_opts, get_rfh2_list)
        sub.close(sub_close_options=0, close_sub_queue=True)
        self.assertEqual(data, msg)
コード例 #5
0
    def test_pubsub_api_managed_durable_1_to_n(self):
        """Test multiple subscriptions."""
        # number of subscriptions
        nsub = 5
        topic_string = self.topic_string_template.format(type="API",
                                                         destination="MANAGED",
                                                         durable="DURABLE")
        msg = self.msg_format(topic_string=topic_string)
        self.sub_desc_list = []
        subscriptions = []
        for n in range(nsub):
            sub_desc = self.get_subscription_descriptor(
                self.subname_template.format(type="Api",
                                             destination="Managed",
                                             durable="Durable{0}".format(n)),
                self.topic_string_template.format(type="API",
                                                  destination="MANAGED",
                                                  durable="DURABLE"),
                pymqi.CMQC.MQSO_CREATE + pymqi.CMQC.MQSO_DURABLE +
                pymqi.CMQC.MQSO_MANAGED)
            # register Subscription
            sub = self.create_api_subscription()
            self.sub_desc_list.append((sub, sub_desc, None))
            sub.sub(sub_desc=sub_desc)
            subscriptions.append(sub)

        # publish (put)
        self.pub(msg, topic_string)

        get_opts = self.create_get_opts()
        for n in range(nsub):
            data = subscriptions[n].get(None, pymqi.md(), get_opts)
            subscriptions[n].close(sub_close_options=0, close_sub_queue=True)
            self.assertEqual(data, msg)
コード例 #6
0
ファイル: test_pubsub.py プロジェクト: vikki1107/pymqi
    def test_pubsub_admin_managed(self):
        topic_string = self.topic_string_template.format(type="ADMIN",
                                                         destination="MANAGED",
                                                         durable="DURABLE")
        subname = self.subname_template.format(type="Admin",
                                               destination="Managed",
                                               durable="Durable")
        msg = self.msg_template.format(topic_string=topic_string)
        queue_name = self.queue_name_template.format(type="ADMIN",
                                                     durable="DURABLE")
        sub_desc = self.get_subscription_descriptor(subname, topic_string,
                                                    pymqi.CMQC.MQSO_RESUME)

        # register Subscription
        self.create_admin_subscription(pymqi.CMQC.MQDC_MANAGED, subname,
                                       queue_name, topic_string)
        sub = pymqi.Subscription(self.qmgr)
        self.sub_desc_list = [(sub, sub_desc, None)]
        sub.sub(sub_desc=sub_desc)
        # publish (put)
        self.pub(msg, topic_string)

        get_opts = self.create_get_opts()
        data = sub.get(None, pymqi.md(), get_opts)

        sub.close(sub_close_options=0, close_sub_queue=True)
        self.assertEqual(data, msg)
コード例 #7
0
ファイル: test_pubsub.py プロジェクト: Majoros/pymqi
    def test_pubsub_admin_provided(self):
        topic_string = self.topic_string_template.format(type="ADMIN", destination="PROVIDED", durable="DURABLE")
        subname = self.subname_template.format(type="Admin", destination="Provided", durable="Durable")
        msg = self.msg_template.format(topic_string=topic_string)
        queue_name = self.queue_name_template.format(type="ADMIN", durable="DURABLE")
        sub_desc = self.get_subscription_descriptor(subname, topic_string, pymqi.CMQC.MQSO_RESUME)
        # create queue
        self.create_queue(queue_name)
        openOpts = pymqi.CMQC.MQOO_INPUT_AS_Q_DEF
        sub_queue = pymqi.Queue(self.qmgr, queue_name, openOpts)

        # register Subscription
        self.create_admin_subscription(pymqi.CMQC.MQDC_PROVIDED, subname, queue_name, topic_string)
        sub = pymqi.Subscription(self.qmgr)
        
        sub.sub(sub_desc=sub_desc, sub_queue=sub_queue)
        self.sub_desc_list = [(sub, sub_desc, queue_name)]
        # publish (put)
        self.pub(msg, topic_string)

        get_opts = self.create_get_opts()
        data = sub.get(None, pymqi.md(), get_opts)

        sub.close(sub_close_options=0, close_sub_queue=True)
        self.assertEqual(data, msg)
コード例 #8
0
ファイル: test_pubsub.py プロジェクト: vikki1107/pymqi
    def test_pubsub_admin_provided(self):
        topic_string = self.topic_string_template.format(
            type="ADMIN", destination="PROVIDED", durable="DURABLE")
        subname = self.subname_template.format(type="Admin",
                                               destination="Provided",
                                               durable="Durable")
        msg = self.msg_template.format(topic_string=topic_string)
        queue_name = self.queue_name_template.format(type="ADMIN",
                                                     durable="DURABLE")
        sub_desc = self.get_subscription_descriptor(subname, topic_string,
                                                    pymqi.CMQC.MQSO_RESUME)
        # create queue
        self.create_queue(queue_name)
        openOpts = pymqi.CMQC.MQOO_INPUT_AS_Q_DEF
        sub_queue = pymqi.Queue(self.qmgr, queue_name, openOpts)

        # register Subscription
        self.create_admin_subscription(pymqi.CMQC.MQDC_PROVIDED, subname,
                                       queue_name, topic_string)
        sub = pymqi.Subscription(self.qmgr)

        sub.sub(sub_desc=sub_desc, sub_queue=sub_queue)
        self.sub_desc_list = [(sub, sub_desc, queue_name)]
        # publish (put)
        self.pub(msg, topic_string)

        get_opts = self.create_get_opts()
        data = sub.get(None, pymqi.md(), get_opts)

        sub.close(sub_close_options=0, close_sub_queue=True)
        self.assertEqual(data, msg)
コード例 #9
0
ファイル: test_pubsub.py プロジェクト: Majoros/pymqi
    def test_pubsub_api_managed_durable_1_to_n(self):
        """Test multiple subscriptions."""
        # number of subscriptions
        nsub = 5
        topic_string = self.topic_string_template.format(type="API", destination="MANAGED", durable="DURABLE")
        subname = self.subname_template.format(type="Api", destination="Managed", durable="Durable")
        msg = self.msg_template.format(topic_string=topic_string)
        self.sub_desc_list = []
        subscriptions = []
        for n in xrange(nsub):
            sub_desc = self.get_subscription_descriptor(
                self.subname_template.format(type="Api", destination="Managed", durable="Durable{}".format(n)),
                self.topic_string_template.format(type="API", destination="MANAGED", durable="DURABLE"),
                pymqi.CMQC.MQSO_CREATE + pymqi.CMQC.MQSO_DURABLE + pymqi.CMQC.MQSO_MANAGED)
            # register Subscription
            sub = self.create_api_subscription()
            self.sub_desc_list.append((sub, sub_desc, None))
            sub.sub(sub_desc=sub_desc)
            subscriptions.append(sub)
        
        # publish (put)
        self.pub(msg, topic_string)

        get_opts = self.create_get_opts()
        for n in xrange(nsub):
            data = subscriptions[n].get(None, pymqi.md(), get_opts)
            subscriptions[n].close(sub_close_options=0, close_sub_queue=True)
            self.assertEqual(data, msg)
コード例 #10
0
 def test_pubsub_api_provided_non_durable(self):
     topic_string = self.topic_string_template.format(
         type="API", destination="PROVIDED", durable="NON DURABLE")
     subname = self.subname_template.format(type="Api",
                                            destination="Provided",
                                            durable="None Durable")
     msg = self.msg_format(topic_string=topic_string)
     sub_desc = self.get_subscription_descriptor(subname, topic_string,
                                                 pymqi.CMQC.MQSO_CREATE)
     queue_name = self.queue_name_template.format(type="API",
                                                  durable="NON_DURABLE")
     # create queue
     self.create_queue(queue_name)
     open_opts = pymqi.CMQC.MQOO_INPUT_AS_Q_DEF
     sub_queue = pymqi.Queue(self.qmgr, queue_name, open_opts)
     # register Subscription
     sub = self.create_api_subscription()
     sub.sub(sub_desc=sub_desc, sub_queue=sub_queue)
     self.sub_desc_list = [(sub, sub_desc, queue_name)]
     # publish (put)
     self.pub(msg, topic_string)
     get_opts = self.create_get_opts()
     data = sub.get(None, pymqi.md(), get_opts)
     sub.close(sub_close_options=0, close_sub_queue=True)
     self.assertEqual(data, msg)
コード例 #11
0
ファイル: test_pubsub.py プロジェクト: vikki1107/pymqi
    def test_pubsub_encoding(self):
        """Test Encoding in managed and non durable subscription.
        """
        topic_string = self.topic_string_template.format(type="API",
                                                         destination="MANAGED",
                                                         durable="NON DURABLE")
        subname = self.subname_template.format(type="Api",
                                               destination="Managed",
                                               durable="Non Durable")
        messages = [
            "ascii",
            unicode("Euro sign: ¤", "iso-8859-15"),
            unicode("Umläut", "iso-8859-15"),
            unicodedata.lookup("INFINITY")
        ]

        md = pymqi.md()
        # setting this means the message is entirely character data
        # md.Format = pymqi.CMQC.MQFMT_STRING
        # default
        # md.CodedCharSetId = pymqi.CMQC.MQCCSI_Q_MGR
        # UTF-8
        md.CodedCharSetId = 1208
        # UCS-2
        # md.CodedCharSetId = 1200
        # ISO-8859-1
        # md.CodedCharSetId = 819
        # ASCII
        # md.CodedCharSetId = 437

        # do not add the subscription to the list,
        # because tearDown() does not have to delete the subscription (in this non durable case)
        sub_desc = self.get_subscription_descriptor(
            subname, topic_string,
            pymqi.CMQC.MQSO_CREATE + pymqi.CMQC.MQSO_MANAGED)
        # register Subscription
        sub = self.create_api_subscription()
        sub.sub(sub_desc=sub_desc)
        # publish (put)
        for msg in messages:
            self.pub(msg.encode("utf-8"), topic_string, md)

        get_opts = self.create_get_opts()
        get_opts["Options"] += pymqi.CMQC.MQGMO_CONVERT
        # md.CodedCharSetId = 819
        # md.CodedCharSetId = 437
        for msg in messages:
            # clear md for re-use
            md.MsgId = pymqi.CMQC.MQMI_NONE
            md.CorrelId = pymqi.CMQC.MQCI_NONE
            md.GroupId = pymqi.CMQC.MQGI_NONE
            # md.CodedCharSetId = 819
            data = sub.get(None, md, get_opts)
            self.assertEqual(unicode(data, "utf-8"), msg)
        sub.close(sub_close_options=0, close_sub_queue=True)
コード例 #12
0
 def test_pubsub_api_managed_non_durable(self):
     topic_string = self.topic_string_template.format(type="API", destination="MANAGED", durable="NON DURABLE")
     subname = self.subname_template.format(type="Api", destination="Managed", durable="Non Durable")
     msg = self.msg_format(topic_string=topic_string)
     sub_desc = self.get_subscription_descriptor(subname, topic_string,
                                                 pymqi.CMQC.MQSO_CREATE + pymqi.CMQC.MQSO_MANAGED)
     # register Subscription
     sub = self.create_api_subscription()
     self.sub_desc_list = [(sub, sub_desc, None)]
     sub.sub(sub_desc=sub_desc)
     # publish (put)
     self.pub(msg, topic_string)
     get_opts = self.create_get_opts()
     data = sub.get(None, pymqi.md(), get_opts)
     sub.close(sub_close_options=0, close_sub_queue=True)
     self.assertEqual(data, msg)
コード例 #13
0
ファイル: test_pubsub.py プロジェクト: Majoros/pymqi
    def test_pubsub_encoding(self):
        """Test Encoding in managed and non durable subscription.
        """
        topic_string = self.topic_string_template.format(type="API", destination="MANAGED", durable="NON DURABLE")
        subname = self.subname_template.format(type="Api", destination="Managed", durable="Non Durable")
        messages = ["ascii", unicode("Euro sign: ¤", "iso-8859-15"), unicode("Umläut", "iso-8859-15"), unicodedata.lookup("INFINITY")]

        md = pymqi.md()
        # setting this means the message is entirely character data
        # md.Format = pymqi.CMQC.MQFMT_STRING
        # default
        # md.CodedCharSetId = pymqi.CMQC.MQCCSI_Q_MGR
        # UTF-8
        md.CodedCharSetId = 1208
        # UCS-2
        # md.CodedCharSetId = 1200
        # ISO-8859-1
        # md.CodedCharSetId = 819
        # ASCII
        # md.CodedCharSetId = 437

        # do not add the subscription to the list,
        # because tearDown() does not have to delete the subscription (in this non durable case)
        sub_desc = self.get_subscription_descriptor(subname, topic_string,
                                                    pymqi.CMQC.MQSO_CREATE + pymqi.CMQC.MQSO_MANAGED)
        # register Subscription
        sub = self.create_api_subscription()
        sub.sub(sub_desc=sub_desc)
        # publish (put)
        for msg in messages:
            self.pub(msg.encode("utf-8"), topic_string, md)

        get_opts = self.create_get_opts()
        get_opts["Options"] += pymqi.CMQC.MQGMO_CONVERT
        # md.CodedCharSetId = 819
        # md.CodedCharSetId = 437
        for msg in messages:
            # clear md for re-use
            md.MsgId = pymqi.CMQC.MQMI_NONE
            md.CorrelId = pymqi.CMQC.MQCI_NONE
            md.GroupId  = pymqi.CMQC.MQGI_NONE    
            # md.CodedCharSetId = 819
            data = sub.get(None, md, get_opts)
            self.assertEqual(unicode(data, "utf-8"), msg)
        sub.close(sub_close_options=0, close_sub_queue=True)
コード例 #14
0
ファイル: test_pubsub.py プロジェクト: Majoros/pymqi
    def test_pubsub_admin_managed(self):
        topic_string = self.topic_string_template.format(type="ADMIN", destination="MANAGED", durable="DURABLE")
        subname = self.subname_template.format(type="Admin", destination="Managed", durable="Durable")
        msg = self.msg_template.format(topic_string=topic_string)
        queue_name = self.queue_name_template.format(type="ADMIN", durable="DURABLE")
        sub_desc = self.get_subscription_descriptor(subname, topic_string, pymqi.CMQC.MQSO_RESUME)

        # register Subscription
        self.create_admin_subscription(pymqi.CMQC.MQDC_MANAGED, subname, queue_name, topic_string)
        sub = pymqi.Subscription(self.qmgr)
        self.sub_desc_list = [(sub, sub_desc, None)]
        sub.sub(sub_desc=sub_desc)
        # publish (put)
        self.pub(msg, topic_string)

        get_opts = self.create_get_opts()
        data = sub.get(None, pymqi.md(), get_opts)

        sub.close(sub_close_options=0, close_sub_queue=True)
        self.assertEqual(data, msg)
コード例 #15
0
ファイル: test_pubsub.py プロジェクト: dsuch/pymqi
 def test_pubsub_api_provided_non_durable(self):
     topic_string = self.topic_string_template.format(type="API", destination="PROVIDED", durable="NON DURABLE")
     subname = self.subname_template.format(type="Api", destination="Provided", durable="None Durable")
     msg = self.msg_format(topic_string=topic_string)
     sub_desc = self.get_subscription_descriptor(subname, topic_string,
                                                 pymqi.CMQC.MQSO_CREATE)
     queue_name = self.queue_name_template.format(type="API", durable="NON_DURABLE")
     # create queue
     self.create_queue(queue_name)
     open_opts = pymqi.CMQC.MQOO_INPUT_AS_Q_DEF
     sub_queue = pymqi.Queue(self.qmgr, queue_name, open_opts)
     # register Subscription
     sub = self.create_api_subscription()
     sub.sub(sub_desc=sub_desc, sub_queue=sub_queue)
     self.sub_desc_list = [(sub, sub_desc, queue_name)]
     # publish (put)
     self.pub(msg, topic_string)
     get_opts = self.create_get_opts()
     data = sub.get(None, pymqi.md(), get_opts)
     sub.close(sub_close_options=0, close_sub_queue=True)
     self.assertEqual(data, msg)
コード例 #16
0
ファイル: capture.py プロジェクト: ucv4/messaging-analysis
	def browse_messages_in_queue(self, queue_name):
		queue = pymqi.Queue(self.connection, queue_name, CMQC.MQOO_BROWSE)

		message_descriptors = pymqi.md()
		get_message_options = pymqi.gmo()
		get_message_options.Options = CMQC.MQGMO_BROWSE_NEXT

		messages = []
		while True:
			try:
				message_body = queue.get(None, message_descriptors, get_message_options)
				messages.append(Message(message_descriptors, message_body))

				#These are required in order to move the cursor to the next entry.
				message_descriptors['MsgId'] = ''
				message_descriptors['CorrelId'] = ''
			except pymqi.MQMIError, e:
				if e.comp == CMQC.MQCC_FAILED and e.reason == CMQC.MQRC_NO_MSG_AVAILABLE:
					break
				else:
					raise
コード例 #17
0
    def browse_messages_in_queue(self, queue_name):
        queue = pymqi.Queue(self.connection, queue_name, CMQC.MQOO_BROWSE)

        message_descriptors = pymqi.md()
        get_message_options = pymqi.gmo()
        get_message_options.Options = CMQC.MQGMO_BROWSE_NEXT

        messages = []
        while True:
            try:
                message_body = queue.get(None, message_descriptors,
                                         get_message_options)
                messages.append(Message(message_descriptors, message_body))

                #These are required in order to move the cursor to the next entry.
                message_descriptors['MsgId'] = ''
                message_descriptors['CorrelId'] = ''
            except pymqi.MQMIError, e:
                if e.comp == CMQC.MQCC_FAILED and e.reason == CMQC.MQRC_NO_MSG_AVAILABLE:
                    break
                else:
                    raise
コード例 #18
0
 def run(self):
      
     #logging.debug("in run") 
     
     while True:
         try:
             
             #logging.debug("before connect %s %s %s" % (self.queue_manager_name, self.server_connection_channel, self.socket))
             file_pid = str(open("/tmp/%s_current.pid" % self.config_name.replace("://", "-"), "r").read())
             #logging.debug("%%%%%% this pid:" + str(self.getName()) + " File pid:" + str(file_pid))    
             if self.getName().strip() != file_pid.strip():
                 #logging.debug("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                 done = True
                 sys.exit(1)
             else:
                 pass
                 #logging.debug("!!! NOT Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
             
             if self._qm is None:
                 self._qm = pymqi.QueueManager(None)
                 logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                
                 self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                 logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
             else:
                 if not self.persistent_connection: 
                     self._qm = pymqi.QueueManager(None)
                     logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                    
                     self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                     logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                 else:
                     if not self._qm._is_connected():
                         self._qm = pymqi.QueueManager(None)
                         logging.debug("Connecting to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                         
                         self._qm.connectTCPClient(self.queue_manager_name, pymqi.cd(), str(self.server_connection_channel), self.socket)
                         logging.debug("Successfully Connected to " + str(self.queue_manager_name) + str(self.server_connection_channel))
                         
             queues = []
             logging.debug("Queue name list: %s" % str(self.queue_name_list))
             
             for queue_name in self.queue_name_list:
                 try:
                     queues.append((queue_name, pymqi.Queue(self._qm, queue_name, CMQC.MQOO_INPUT_SHARED)))
                     #logging.debug("queue loop.  queue name:" + str(queue_name))
                 except Exception, ex:
                     logging.error("Unable to open queue:" + str(queue_name) + " Exception: " + str(ex))
                 
             get_opts = pymqi.gmo(Options = CMQC.MQGMO_FAIL_IF_QUIESCING)
             
             #logging.debug("after get_opts") 
             msg_desc = pymqi.md()
             #logging.debug("Start get")
             for (queue_name, queue_obj) in queues:
                 #logging.debug("queue = %s " % queue_name)
                 #logging.debug("Current tid:" + str(self.getName()) + " queue:" + queue_name)
                 #logging.debug("Check pid: queue:" + queue_name)
       
                 file_pid = str(open("/tmp/%s_current.pid" % self.config_name.replace("://", "-"), "r").read())
                 #logging.debug("%%%%%% this pid:" + str(self.getName()) + " File pid:" + str(file_pid))    
                 if self.getName().strip() != file_pid.strip():
                     #open("/opt/esb/stop.txt", "a").write("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                     #logging.debug("$$$$ Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                     done = True
                     sys.exit(1)
                 else:
                     pass
                     #logging.debug("!!! NOT Stopping... this pid:" + str(self.getName()) + " File pid:" + str(file_pid))
                 
                 done = False
                 while not done:
                    
                     try:
                       
                         logging.debug("Before MQGET")
                         msg_desc['MsgId'] = ''
                         msg_desc['CorrelId'] = '' 
                         msg_data = queue_obj.get(None, msg_desc, get_opts)   
                         logging.debug("Got message. ")# MQMD:" + str(msg_desc.get()) + "MSG:" + msg_data)
                         
                         handle_output(self.splunk_host, self.queue_manager_name, queue_name, msg_data, msg_desc, False,  **self.kw)  
                         logging.debug("Handled output")
                     except pymqi.MQMIError, e:
                         if e.reason == 2033:
                             logging.debug("Done! 2033. No more messages!")
                             done = True
                         else:
                             logging.error("MQ Exception occurred: %s " % (str(e)))
                             done = True
                 
                 queue_obj.close()
                            
             if not self.persistent_connection:    
                 self._qm.disconnect()
コード例 #19
0
    def run(self):

        while True:
            try:
                # logging.debug("before connect %s %s %s" %
                # (self.queue_manager_name, self.server_conn_chl,
                #  self.socket))
                file_pid = open(
                    "/tmp/%s_current.pid" %
                    (self.config_name.replace("://", "-") + "_" +
                     str(self.thread_id)), "r").read().decode()
                logging.debug("%%%%%% this pid:" + str(self.getName()) +
                              " File pid:" + str(file_pid))

                if self.getName().strip() != file_pid.strip():
                    # logging.debug("$$$$ Stopping... this pid:" +
                    # str(self.getName()) + " File pid:" + str(file_pid))
                    done = True
                    sys.exit(1)
                else:
                    pass
                    # logging.debug("!!! NOT Stopping... this pid:" +
                    # str(self.getName()) + " File pid:" + str(file_pid))

                cd = pymqi.cd()
                #set the max message length to maximum
                cd["MaxMsgLength"] = 104857600

                if self._qm is None:
                    self._qm = pymqi.QueueManager(None)
                    logging.debug("Connecting to " +
                                  str(self.queue_manager_name) +
                                  " using channel " +
                                  str(self.server_conn_chl) + " and address " +
                                  self.socket + ".")

                    self._qm.connect_tcp_client(self.queue_manager_name, cd,
                                                self.server_conn_chl,
                                                self.socket, self.mq_user_name,
                                                self.mq_password)

                    logging.debug("Successfully Connected to " +
                                  self.queue_manager_name + " using channel " +
                                  self.server_conn_chl + " and address " +
                                  self.socket + ".")
                else:
                    if not self.persistent_connection:
                        self._qm = pymqi.QueueManager(None)
                        logging.debug("Connecting to " +
                                      str(self.queue_manager_name) +
                                      " using channel " +
                                      str(self.server_conn_chl) +
                                      " and address " + self.socket + ".")

                        self._qm.connect_tcp_client(self.queue_manager_name,
                                                    cd, self.server_conn_chl,
                                                    self.socket,
                                                    self.mq_user_name,
                                                    self.mq_password)

                        logging.debug("Successfully Connected to " +
                                      self.queue_manager_name +
                                      " using channel " +
                                      self.server_conn_chl + " and address " +
                                      self.socket + ".")
                    else:
                        if not self._qm._is_connected():
                            self._qm = pymqi.QueueManager(None)
                            logging.debug("Connecting to " +
                                          str(self.queue_manager_name) +
                                          " using channel " +
                                          str(self.server_conn_chl) +
                                          " and address " + self.socket + ".")

                            self._qm.connect_tcp_client(
                                self.queue_manager_name, cd,
                                self.server_conn_chl, self.socket,
                                self.mq_user_name, self.mq_password)
                            logging.debug("Successfully Connected to " +
                                          self.queue_manager_name +
                                          " using channel " +
                                          self.server_conn_chl +
                                          " and address " + self.socket + ".")

                queues = []
                logging.debug("Queue name list: %s" %
                              str(self.queue_name_list))

                for queue_name in self.queue_name_list:
                    try:
                        queues.append((queue_name,
                                       pymqi.Queue(self._qm, queue_name,
                                                   CMQC.MQOO_INPUT_SHARED)))
                        # logging.debug("queue loop.  queue name:" +
                        #               str(queue_name))
                    except Exception as ex:
                        logging.error("Unable to open queue:" +
                                      str(queue_name) + " Exception: " +
                                      str(ex))

                get_opts = pymqi.gmo(Options=CMQC.MQGMO_FAIL_IF_QUIESCING)

                # logging.debug("after get_opts")
                msg_desc = pymqi.md()
                # logging.debug("Start get")
                for (queue_name, queue_obj) in queues:
                    # logging.debug("queue = %s " % queue_name)
                    # logging.debug("Current tid:" +
                    #                str(self.getName()) +
                    #                " queue:" + queue_name)
                    # logging.debug("Check pid: queue:" + queue_name)

                    file_pid = str(
                        open(
                            "/tmp/%s_current.pid" %
                            (self.config_name.replace("://", "-") + "_" +
                             str(self.thread_id)), "r").read())
                    # logging.debug("%%%%%% this pid:" + str(self.getName()) +
                    #              " File pid:" + str(file_pid))
                    if self.getName().strip() != file_pid.strip():
                        # logging.debug("$$$$ Stopping... this pid:" +
                        #               str(self.getName()) +
                        #               " File pid:" + str(file_pid))
                        done = True
                        sys.exit(1)
                    else:
                        pass
                        # logging.debug("!!! NOT Stopping... this pid:" +
                        #               str(self.getName()) + " File pid:" +
                        #               str(file_pid))

                    done = False
                    while not done:

                        try:

                            logging.debug("Before MQGET")
                            msg_desc['MsgId'] = CMQC.MQMI_NONE
                            msg_desc['CorrelId'] = CMQC.MQCI_NONE
                            msg_data = queue_obj.get(None, msg_desc, get_opts)
                            logging.debug("Got message. ")
                            # MQMD:" + str(msg_desc.get()) + "MSG:" + msg_data)

                            handle_output(self.splunk_host,
                                          self.queue_manager_name, queue_name,
                                          msg_data, msg_desc, False, **self.kw)
                            logging.debug("Handled output")
                        except pymqi.MQMIError as e:
                            if e.reason == 2033:
                                logging.debug("Done! 2033. No more messages!")
                                done = True
                            else:
                                logging.error("MQ Exception occurred: %s " %
                                              (str(e)))
                                done = True

                    queue_obj.close()

                if not self.persistent_connection:
                    self._qm.disconnect()
            except pymqi.MQMIError as e:
                if e.reason == 2033:
                    pass
                else:
                    logging.error("MQ Exception occurred: %s " % (str(e)))
                    if self._qm is not None:
                        if not self.persistent_connection \
                           and self._qm._is_connected():
                            self._qm.disconnect()

            except:  # catch *all* exceptions
                e = sys.exc_info()[1]
                logging.error("Stopping. Exception in QueuePoller: %s" %
                              str(e))
                sys.exit(1)

            time.sleep(float(self.mqinput_interval))
コード例 #20
0
print timestamp

try:
    if write == 1:
        #put message

        queue_manager = param.WQ_Manager
        channel = param.WQ_Channel
        host = param.Write_Host
        port = param.Write_Port
        queue_name = param.Write_Queue
        conn_info = "%s(%s)" % (host, port)
        #print conn_info

        #header options
        put_mqmd = pymqi.md()
        put_mqmd["Format"] = CMQC.MQFMT_RF_HEADER_2
        put_mqmd["Encoding"] = 273
        put_mqmd["CodedCharSetId"] = 1208

        put_opts = pymqi.pmo()

        put_rfh2 = pymqi.RFH2()
        put_rfh2["StrucId"] = CMQC.MQRFH_STRUC_ID
        put_rfh2["Version"] = CMQC.MQRFH_VERSION_2
        put_rfh2["StrucLength"] = 188
        put_rfh2["Encoding"] = 273
        put_rfh2["CodedCharSetId"] = 1208
        put_rfh2["Format"] = CMQC.MQFMT_STRING
        put_rfh2["Flags"] = 0
        put_rfh2["NameValueCCSID"] = 819
コード例 #21
0
print timestamp

try:
    if write == 1:
        #put message

        queue_manager = param.WQ_Manager
        channel = param.WQ_Channel
        host = param.Write_Host
        port = param.Write_Port
        queue_name = param.Write_Queue
        conn_info = "%s(%s)" % (host, port)
        #print conn_info

        #header options
        put_mqmd = pymqi.md()
        put_mqmd["Format"] = CMQC.MQFMT_RF_HEADER_2
        put_mqmd["Encoding"] = 273
        put_mqmd["CodedCharSetId"] = 1208

        put_opts = pymqi.pmo()

        put_rfh2 = pymqi.RFH2()
        put_rfh2["StrucId"] = CMQC.MQRFH_STRUC_ID
        put_rfh2["Version"] = CMQC.MQRFH_VERSION_2
        put_rfh2["StrucLength"] = 188
        put_rfh2["Encoding"] = 273
        put_rfh2["CodedCharSetId"]= 1208
        put_rfh2["Format"] =  CMQC.MQFMT_STRING
        put_rfh2["Flags"] = 0
        put_rfh2["NameValueCCSID"] = 819