Exemplo n.º 1
0
    def setUpClass(cls):
        """Initialize test environment."""
        cls.prefix = os.environ.get('PYMQI_TEST_OBJECT_PREFIX', 'PYMQI.')

        # max length of queue names is 48 characters
        cls.queue_name = '{prefix}MSG.QUEUE'.format(
            prefix=config.MQ.QUEUE.PREFIX)
        cls.queue_manager = config.MQ.QM.NAME
        cls.channel = config.MQ.QM.CHANNEL
        cls.host = config.MQ.QM.HOST
        cls.port = config.MQ.QM.PORT
        cls.user = config.MQ.QM.USER
        cls.password = config.MQ.QM.PASSWORD

        cls.conn_info = '{0}({1})'.format(cls.host, cls.port)

        cls.qmgr = pymqi.QueueManager(None)
        try:
            cls.qmgr.connectTCPClient(cls.queue_manager, pymqi.CD(),
                                      cls.channel, cls.conn_info, cls.user,
                                      cls.password)
        except pymqi.MQMIError as ex:
            if ex.comp == pymqi.CMQC.MQCC_FAILED:
                raise ex

        cls.version = cls.inquire_qmgr_version().decode()
    def setUp(self):

        self.msg_prop_name = b"test_name"

        self.msg_prop_value_str = "test_valuetest_valuetest_valuetest_valuetest_value"
        self.msg_prop_value_bytes = b"test_valuetest_valuetest_valuetest_valuetest_value"
        self.msg_prop_value_bool = True
        self.msg_prop_value_int8 = -127
        self.msg_prop_value_int16 = -32768
        self.msg_prop_value_int32 = -2147483647
        self.msg_prop_value_int64 = -9223372036854775808
        self.msg_prop_value_float32 = 1.1754943508222875e-38
        self.msg_prop_value_float64 = 2.2250738585072014e-308

        # max length of queue names is 48 characters
        self.queue_name = "{prefix}MSG.PROP.QUEUE".format(
            prefix=config.MQ.QUEUE.PREFIX)
        self.queue_manager = config.MQ.QM.NAME
        self.channel = config.MQ.QM.CHANNEL
        self.host = config.MQ.QM.HOST
        self.port = config.MQ.QM.PORT
        self.user = config.MQ.QM.USER
        self.password = config.MQ.QM.PASSWORD

        self.conn_info = "{0}({1})".format(self.host, self.port)

        self.qmgr = pymqi.QueueManager(None)
        self.qmgr.connectTCPClient(self.queue_manager, pymqi.CD(),
                                   self.channel, self.conn_info, self.user,
                                   self.password)

        self.create_queue(self.queue_name)
Exemplo n.º 3
0
 def __init__(self, queue_manager, channel, host, port):
     self.queue_manager = queue_manager
     self.cd = pymqi.CD()
     self.cd.ChannelName = channel
     self.cd.ConnectionName = "%s(%s)" % (host, port)
     self.cd.ChannelType = CMQC.MQCHT_CLNTCONN
     self.cd.TransportType = CMQC.MQXPT_TCP
Exemplo n.º 4
0
def connect():
    global qmgr
    conn_info = '%s(%s)' % (args.host, args.port)
    if (not args.use_client_auth and not args.use_ssl):
        qmgr = pymqi.connect(args.queue_manager, args.channel, conn_info)
    elif (args.use_client_auth and not args.use_ssl):
        qmgr = pymqi.connect(args.queue_manager, args.channel, conn_info,
                             args.username, args.password)
    elif (args.use_ssl):
        cd = pymqi.CD()
        cd.ChannelName = bytes(args.channel, encoding='utf8')
        cd.ConnectionName = bytes(conn_info, encoding='utf8')
        cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
        cd.TransportType = pymqi.CMQC.MQXPT_TCP
        cd.SSLCipherSpec = bytes(args.cipherspec, encoding='utf8')
        sco = pymqi.SCO()
        sco.KeyRepository = bytes(args.server_cert, encoding='utf8')
        qmgr = pymqi.QueueManager(None)
        if (not args.use_client_auth):
            qmgr.connect_with_options(args.queue_manager, cd=cd, sco=sco)
        else:
            qmgr.connect_with_options(args.queue_manager,
                                      cd=cd,
                                      sco=sco,
                                      user=bytes(args.username,
                                                 encoding='utf8'),
                                      password=bytes(args.password,
                                                     encoding='utf8'))
    print("connection succesful")
Exemplo n.º 5
0
def do_task():
    try:
        qmgr.connect_tcp_client("VMFSMESMQTEST1", pymqi.CD(), "CLI.PD.MES.MEB.1", "10.232.129.54(1416)", "mqm", "mqm")
    except pymqi.MQMIError as e:
        if e.comp == pymqi.CMQC.MQCC_WARNING and e.reason == pymqi.CMQC.MQRC_ALREADY_CONNECTED:
            pass
        else:
            print("mq error: %s" % e)
            return

    client = tornado.httpclient.HTTPClient()

    cfg = read_cfg()
    if cfg is None:
        cfg = {}

    get_plan(client)

    put_fin(client, cfg)
    get_printcode(client)

    put_print(client, cfg)
    # put_bzd(client, cfg)

    write_cfg(cfg)
    client.close()
Exemplo n.º 6
0
    def setUp(self):
        self.topic_string_template = "/UNITTEST/{prefix}/PUBSUB/{{type}}/{{destination}}/{{durable}}".format(
            prefix=config.MQ.QUEUE.PREFIX)
        self.subname_template = "{prefix}'s {{type}} {{destination}} {{durable}} Subscription".format(
            prefix=config.MQ.QUEUE.PREFIX)
        self.msg_template = "Hello World in the topic string \"{{topic_string}}\"".format(
        )
        # max length of queue names is 48 characters
        self.queue_name_template = "{prefix}_Q_TEST_PUBSUB_{{type}}_PROVIDED_{{durable}}".format(
            prefix=config.MQ.QUEUE.PREFIX)
        self.queue_manager = config.MQ.QM.NAME
        self.channel = config.MQ.QM.CHANNEL
        self.host = config.MQ.QM.HOST
        self.port = config.MQ.QM.PORT
        self.user = config.MQ.QM.USER
        self.password = config.MQ.QM.PASSWORD

        self.conn_info = "{}({})".format(self.host, self.port)

        self.qmgr = pymqi.QueueManager(None)
        self.qmgr.connectTCPClient(self.queue_manager, pymqi.CD(),
                                   self.channel, self.conn_info, self.user,
                                   self.password)

        # list of tuples (subscription, subscription descriptions) for tearDown() to delete after the test
        self.sub_desc_list = []
Exemplo n.º 7
0
    def test_connection_with_tls(self):
        """Test connection to QueueManager with TLS."""
        qmgr = pymqi.QueueManager(None)
        conn_info = pymqi.ensure_bytes('{0}({1})'.format(self.host, self.port))

        cd = pymqi.CD(
            Version=pymqi.CMQXC.MQCD_VERSION_7,  # pylint: disable=C0103
            ChannelName=self.tls_channel_name,
            ConnectionName=conn_info,
            SSLCipherSpec=self.cypher_spec)

        sco = pymqi.SCO(Version=pymqi.CMQC.MQSCO_VERSION_5,
                        KeyRepository=os.path.join(
                            self.key_repo_location_client,
                            self.certificate_label_client),
                        CertificateLabel=self.certificate_label_client)

        opts = pymqi.CMQC.MQCNO_HANDLE_SHARE_NO_BLOCK

        qmgr.connectWithOptions(self.queue_manager,
                                cd,
                                sco,
                                opts=opts,
                                user=self.user,
                                password=self.password)
        is_connected = qmgr.is_connected
        if is_connected:
            qmgr.disconnect()

        self.assertTrue(is_connected)
Exemplo n.º 8
0
def connect():
    logger.info('Establising Connection with MQ Server')
    try:
        cd = pymqi.CD()
        cd.ChannelName = MQDetails['CHANNEL']
        cd.ConnectionName = conn_info
        cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
        cd.TransportType = pymqi.CMQC.MQXPT_TCP

        # Create an empty SCO object, and optionally set TLS settings
        # if a cipher is set in the envrionment variables.
        sco = pymqi.SCO()
        if MQDetails['CIPHER']:
            cd.SSLCipherSpec = MQDetails['CIPHER']
            sco.KeyRepository = MQDetails['KEY_REPOSITORY']

        #options = pymqi.CMQC.MQPMO_NO_SYNCPOINT | pymqi.CMQC.MQPMO_NEW_MSG_ID | pymqi.CMQC.MQPMO_NEW_CORREL_ID
        options = pymqi.CMQC.MQPMO_NEW_CORREL_ID

        qmgr = pymqi.QueueManager(None)
        qmgr.connect_with_options(MQDetails['QMGR'],
                                  user=credentials['USER'],
                                  password=credentials['PASSWORD'],
                                  opts=options,
                                  cd=cd,
                                  sco=sco)
        return qmgr
    except pymqi.MQMIError as e:
        logger.error("Error connecting")
        logger.error(e)
        return None
Exemplo n.º 9
0
    def setUpClass(cls):
        """Initialize test environment."""
        cls.prefix = os.environ.get('PYMQI_TEST_OBJECT_PREFIX', 'PYMQI.')

        # max length of queue names is 48 characters
        cls.queue_name = '{prefix}MSG.QUEUE'.format(prefix=config.MQ.QUEUE.PREFIX)
        cls.queue_manager = config.MQ.QM.NAME
        cls.channel = config.MQ.QM.CHANNEL
        cls.host = config.MQ.QM.HOST
        cls.port = config.MQ.QM.PORT
        cls.user = config.MQ.QM.USER
        cls.password = config.MQ.QM.PASSWORD

        cls.conn_info = '{0}({1})'.format(cls.host, cls.port)

        if pymqi.__mqbuild__ == 'server':
            cls.qmgr = pymqi.QueueManager(cls.queue_manager)
        else:
            cls.qmgr = pymqi.QueueManager(None)
            cls.qmgr.connectTCPClient(cls.queue_manager, pymqi.CD(), cls.channel,
                                      cls.conn_info, cls.user, cls.password)

        cls.pcf = pymqi.PCFExecute(cls.qmgr, response_wait_interval=15000)

        cls.version = cls.inquire_qmgr_version().decode()
Exemplo n.º 10
0
def _get_channel_definition(config):
    # type: (IBMMQConfig) -> pymqi.CD
    cd = pymqi.CD()
    cd.ChannelName = pymqi.ensure_bytes(config.channel)
    cd.ConnectionName = pymqi.ensure_bytes(config.connection_name)
    cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
    cd.TransportType = pymqi.CMQC.MQXPT_TCP
    cd.Version = config.mqcd_version
    return cd
Exemplo n.º 11
0
def connectmq_put(recv_mq, str1):
    host = recv_mq["ip"] + "(" + recv_mq["port"] + ")"

    qmgr = pymqi.QueueManager(None)
    qmgr.connect_tcp_client(recv_mq["recv_queue_manager"], pymqi.CD(), recv_mq["recv_channel"], host,
                            recv_mq["username"], recv_mq["password"])

    try:
        qmgr.connect_tcp_client(recv_mq["recv_queue_manager"], pymqi.CD(), recv_mq["recv_channel"], host,
                                recv_mq["username"], recv_mq["password"])


    except pymqi.MQMIError as e:
        if e.comp == pymqi.CMQC.MQCC_WARNING and e.reason == pymqi.CMQC.MQRC_ALREADY_CONNECTED:
            pass

    queue = pymqi.Queue(qmgr, recv_mq["recv_queue"])
    queue.put(str1)
    queue.close()
    qmgr.disconnect()
Exemplo n.º 12
0
def get_connection():
    queue_manager = config['queue_manager']

    connector_descriptor = pymqi.CD()
    connector_descriptor.ChannelName = config['server_connection']
    connector_descriptor.ConnectionName = config['host_port']
    connector_descriptor.ChannelType = CMQC.MQCHT_CLNTCONN
    connector_descriptor.TransportType = CMQC.MQXPT_TCP

    qmgr = pymqi.QueueManager(None)
    qmgr.connect_with_options(queue_manager, connector_descriptor)
    return qmgr
Exemplo n.º 13
0
    def get_connection(self):
        queue_manager = self.config['queue_manager']

        connector_descriptor = pymqi.CD()
        connector_descriptor.ChannelName = self.server_channel
        connector_descriptor.ConnectionName = self.host_port
        connector_descriptor.ChannelType = CMQC.MQCHT_CLNTCONN
        connector_descriptor.TransportType = CMQC.MQXPT_TCP
        connector_descriptor.WaitInterval = 30 * 60

        qmgr = pymqi.QueueManager(None)
        qmgr.connect_with_options(queue_manager, connector_descriptor)
        return qmgr
Exemplo n.º 14
0
    def __init__(self):
        threading.Thread.__init__(self)
        self.daemon = True

        cd = pymqi.CD()
        cd.ChannelName = channel
        cd.ConnectionName = listener
        cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
        cd.TransportType = pymqi.CMQC.MQXPT_TCP
        self.qm = pymqi.QueueManager(None)
        self.qm.connect_with_options(qm_name, opts=pymqi.CMQC.MQCNO_HANDLE_SHARE_NO_BLOCK,
                                   cd=cd)

        self.req_queue = pymqi.Queue(self.qm, request_queue_name)
        self.replyto_queue = pymqi.Queue(self.qm, replyto_queue_name)
Exemplo n.º 15
0
    def __init__(self):
        self.queue_manager = config.queue_manager
        self.channel = config.channel
        self.port = config.port
        self.host = config.host
        self.conn_info = config.conn_info
        self.queue_request_name = config.queue_request_name
        self.queue_response_name = config.queue_response_name

        cd = pymqi.CD()
        cd.ChannelName = self.channel
        cd.ConnectionName = self.conn_info
        cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
        cd.TransportType = pymqi.CMQC.MQXPT_TCP

        self.qmgr = pymqi.QueueManager(None)
        self.qmgr.connect_with_options(self.queue_manager, opts=pymqi.CMQC.MQCNO_HANDLE_SHARE_NO_BLOCK, cd=cd)
Exemplo n.º 16
0
def init_message_queue(cfg):
    ''' Initialize IBM message queue'''
    mq_conn_info = "%s(%s)" % (cfg['mq_host'], cfg['mq_port'])

    cd = pymqi.CD()
    cd.ChannelName = cfg['mq_channel']
    cd.ConnectionName = mq_conn_info
    cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
    cd.TransportType = pymqi.CMQC.MQXPT_TCP

    qmgr = pymqi.QueueManager(None)
    logger.debug("Initiating connection")
    qmgr.connect_with_options(cfg['mq_queue_manager'],
                              opts=pymqi.CMQC.MQCNO_HANDLE_SHARE_BLOCK,
                              cd=cd)
    logger.info("Connected to MQ at [{}]".format(cfg['mq_host']))

    return qmgr
Exemplo n.º 17
0
def get_ssl_connection(config):
    """
    Get the connection with SSL
    """
    cd = pymqi.CD()
    cd.ChannelName = config.channel
    cd.ConnectionName = config.host_and_port
    cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
    cd.TransportType = pymqi.CMQC.MQXPT_TCP
    cd.SSLCipherSpec = config.ssl_cipher_spec

    sco = pymqi.SCO()
    sco.KeyRepository = config.ssl_key_repository_location

    queue_manager = pymqi.QueueManager(None)
    queue_manager.connect_with_options(config.queue_manager, cd, sco)

    return queue_manager
Exemplo n.º 18
0
def connect():
    logger.info('Establising Connection with MQ Server')
    try:
        cd = None
        if not EnvStore.ccdtCheck():
            logger.info(
                'CCDT URL export is not set, will be using json envrionment client connections settings'
            )

            cd = pymqi.CD(Version=pymqi.CMQXC.MQCD_VERSION_11)
            cd.ChannelName = MQDetails[EnvStore.CHANNEL]
            cd.ConnectionName = conn_info
            cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
            cd.TransportType = pymqi.CMQC.MQXPT_TCP

            logger.info('Checking Cypher details')
            # If a cipher is set then set the TLS settings
            if MQDetails[EnvStore.CIPHER]:
                logger.info('Making use of Cypher details')
                cd.SSLCipherSpec = MQDetails[EnvStore.CIPHER]

        # Key repository is not specified in CCDT so look in envrionment settings
        # Create an empty SCO object
        sco = pymqi.SCO()
        if MQDetails[EnvStore.KEY_REPOSITORY]:
            logger.info('Setting Key repository')
            sco.KeyRepository = MQDetails[EnvStore.KEY_REPOSITORY]

        #options = pymqi.CMQC.MQPMO_NO_SYNCPOINT | pymqi.CMQC.MQPMO_NEW_MSG_ID | pymqi.CMQC.MQPMO_NEW_CORREL_ID
        options = pymqi.CMQC.MQPMO_NEW_CORREL_ID

        qmgr = pymqi.QueueManager(None)
        qmgr.connect_with_options(MQDetails[EnvStore.QMGR],
                                  user=credentials[EnvStore.USER],
                                  password=credentials[EnvStore.PASSWORD],
                                  opts=options,
                                  cd=cd,
                                  sco=sco)
        return qmgr

    except pymqi.MQMIError as e:
        logger.error("Error connecting")
        logger.error(e)
        return None
Exemplo n.º 19
0
    def setUp(self):
        # max length of queue names is 48 characters
        self.queue_name = "{prefix}PCF.QUEUE".format(
            prefix=config.MQ.QUEUE.PREFIX)
        self.queue_manager = config.MQ.QM.NAME
        self.channel = config.MQ.QM.CHANNEL
        self.host = config.MQ.QM.HOST
        self.port = config.MQ.QM.PORT
        self.user = config.MQ.QM.USER
        self.password = config.MQ.QM.PASSWORD

        self.conn_info = "{0}({1})".format(self.host, self.port)

        self.qmgr = pymqi.QueueManager(None)
        self.qmgr.connectTCPClient(self.queue_manager, pymqi.CD(),
                                   self.channel, self.conn_info, self.user,
                                   self.password)

        self.create_queue(self.queue_name)
Exemplo n.º 20
0
    def setUp(self):

        self.msg_prop_name = utils.py3str2bytes("test_name")
        self.msg_prop_value = utils.py3str2bytes("test_valuetest_valuetest_valuetest_valuetest_value")

        # max length of queue names is 48 characters
        self.queue_name = "{prefix}.MSG.PROP.QUEUE".format(prefix=config.MQ.QUEUE.PREFIX)
        self.queue_manager = config.MQ.QM.NAME
        self.channel = config.MQ.QM.CHANNEL
        self.host = config.MQ.QM.HOST
        self.port = config.MQ.QM.PORT
        self.user = config.MQ.QM.USER
        self.password = config.MQ.QM.PASSWORD

        self.conn_info = "{0}({1})".format(self.host, self.port)

        self.qmgr = pymqi.QueueManager(None)
        self.qmgr.connectTCPClient(self.queue_manager, pymqi.CD(), self.channel, self.conn_info, self.user, self.password)

        self.create_queue(self.queue_name)
Exemplo n.º 21
0
def connect():
    recv_mq = {
        "ip": "10.232.129.54",
        "port": "1416",
        "username": "******",
        "password": "******",

        "recv_queue_manager": "VMFSMESMQTEST1",
        "recv_channel": "CLI.PD.MES.MEB.1"
    }
    host = recv_mq["ip"] + "(" + recv_mq["port"] + ")"
    global qmgr
    qmgr = pymqi.QueueManager(None)
    # qmgr.connect_tcp_client(recv_mq["recv_queue_manager"], pymqi.CD(), recv_mq["recv_channel"], host,
    #                         recv_mq["username"], recv_mq["password"])
    try:
        qmgr.connect_tcp_client(recv_mq["recv_queue_manager"], pymqi.CD(), recv_mq["recv_channel"], host,recv_mq["username"], recv_mq["password"])
    except pymqi.MQMIError as e:
        print("Connect to MQ Error:",e)
        if e.comp == pymqi.CMQC.MQCC_WARNING and e.reason == pymqi.CMQC.MQRC_ALREADY_CONNECTED:
            pass
Exemplo n.º 22
0
def topic_value(tname):
    #run = Event()
    msg = ''
    subname = ''
    fileobj = open('mq_topic.log','a+b')
    queue_manager = pmclientrc.QA_QUEUE_MANAGER
    queue_name = pmclientrc.QA_QUEUE_NAME
    channel = pmclientrc.QA_CHANNEL
    host = pmclientrc.QA_HOST
    port = pmclientrc.QA_PORT
    conn_info = "%s(%s)" % (host, port)
    qmgr = pymqi.QueueManager()
    qmgr.connect_tcp_client(queue_manager, pymqi.CD(), channel, conn_info)
    if tname == 'RT.EXISTING_SECURITY.QA':
        subname = 'existing'
    elif tname == 'RT.NEW_SECURITY.QA':
        subname = 'new_security'
    elif tname == 'RT.COLLAT':
        subname = 'collat'
    elif tname == 'RT.TICKET.QA.TOPIC':
        subname = 'ticket_topic'
    elif tname == 'RT.ORDER':
        subname = 'order'
    topicname = tname
    topic_string = re.sub(r'\.','/',topicname)
    sub  = pymqi.Subscription(qmgr)
    sd   = pymqi.SD(Options=CMQC.MQSO_CREATE  |
                            CMQC.MQSO_RESUME  |
                            CMQC.MQSO_MANAGED |
                            CMQC.MQSO_DURABLE)
    sd.set_vs('SubName', subname)
    sd.set_vs('ObjectString', topic_string)
    sub.sub(sd)
    msg = getMessage(sub, syncpoint=True)
		
    fileobj.write(subname + '|' +  msg+"\n")
    sub.close(sub_close_options=CMQC.MQCO_KEEP_SUB,
    close_sub_queue=True)
    qmgr.disconnect()
Exemplo n.º 23
0
    def setUp(self):
        """Setup tests environmet.
        Configuration for setup provided by config.py
        Creates connection `self.qmgr` to Queue Manager `self.queue_manager`
        and creates queue `self.queue_name`
        """
        # max length of queue names is 48 characters
        self.queue_name = "{prefix}MSG.QUEUE".format(
            prefix=config.MQ.QUEUE.PREFIX)
        self.queue_manager = config.MQ.QM.NAME
        self.channel = config.MQ.QM.CHANNEL
        self.host = config.MQ.QM.HOST
        self.port = config.MQ.QM.PORT
        self.user = config.MQ.QM.USER
        self.password = config.MQ.QM.PASSWORD

        self.conn_info = "{0}({1})".format(self.host, self.port)

        self.qmgr = pymqi.QueueManager(None)
        self.qmgr.connectTCPClient(self.queue_manager, pymqi.CD(),
                                   self.channel, self.conn_info, self.user,
                                   self.password)
Exemplo n.º 24
0
    def initialize_config(self):
        tags = [f'mq_server:{self.config.mq_server}', f'mq_port:{self.config.mq_port}', *self.config.tags]
        self._tags = tuple(tags)

        cd = pymqi.CD()
        cd.ChannelName = self.config.channel.encode('utf-8')
        cd.ConnectionName = f'{self.config.mq_server}({self.config.mq_port})'.encode('utf-8')
        cd.ChannelType = pymqi.CMQC.MQCHT_CLNTCONN
        cd.TransportType = pymqi.CMQC.MQXPT_TCP
        cd.Version = getattr(pymqi.CMQC, f'MQCD_VERSION_{self.config.mqcd_version}')

        self._connection_options = {'cd': cd, 'user': self.config.mq_user, 'password': self.config.mq_password}

        if self.config.tls_auth:
            cd.SSLCipherSpec = self.config.tls_cipher_spec.encode('utf-8')

            sco = pymqi.SCO()
            sco.KeyRepository = self.config.tls_key_repository_location.encode('utf-8')
            if self.config.tls_certificate_label:
                sco.CertificateLabel = self.config.tls_certificate_label.encode('utf-8')

            self._connection_options['sco'] = sco
Exemplo n.º 25
0
# More examples are at https://dsuch.github.io/pymqi/examples.html
# or in code/examples in the source distribution.

import pymqi

queue_manager = 'QM1'
channel = 'DEV.APP.SVRCONN'
host = '127.0.0.1'
port = '1414'
queue_name = 'TEST.1'
message = 'Hello from Python!'
conn_info = '%s(%s)' % (host, port)
user = '******'
password = '******'

qmgr = pymqi.QueueManager(None)
qmgr.connect_tcp_client(queue_manager, pymqi.CD(), channel, conn_info)

try:
    qmgr.connect_tcp_client(queue_manager, pymqi.CD(), channel, conn_info)
except pymqi.MQMIError as e:
    if e.comp == pymqi.CMQC.MQCC_WARNING and e.reason == pymqi.CMQC.MQRC_ALREADY_CONNECTED:
        pass

queue = pymqi.Queue(qmgr, queue_name)
queue.put(message)
queue.close()

qmgr.disconnect()
# See discussion and more examples at http://packages.python.org/pymqi/examples.html
# or in doc/sphinx/examples.rst in the source distribution.

import CMQC, pymqi

queue_manager = "QM01"
channel = "SVRCONN.1"
host = "192.168.1.135"
port = "1434"
queue_name = "TEST.1"
message = "Hello from Python!"
conn_info = "%s(%s)" % (host, port)

cd = pymqi.CD()

cd.ChannelName = channel
cd.ConnectionName = conn_info
cd.ChannelType = CMQC.MQCHT_CLNTCONN
cd.TransportType = CMQC.MQXPT_TCP

connect_options = CMQC.MQCNO_HANDLE_SHARE_BLOCK

qmgr = pymqi.QueueManager(None)

for x in range(10):
    qmgr.connect_with_options(queue_manager, cd=cd, opts=connect_options)
    qmgr.connect_with_options(queue_manager, cd=cd, opts=connect_options)

queue = pymqi.Queue(qmgr, queue_name)
queue.put(message)
queue.close()
Exemplo n.º 27
0
def prepare_queue_manager():
    import pymqi

    conn_info = '{0}({1})'.format(common.HOST, common.PORT)
    qm_name = common.QUEUE_MANAGER.lower()

    qmgr = pymqi.QueueManager(None)
    qmgr.connectTCPClient(common.QUEUE_MANAGER, pymqi.CD(), common.CHANNEL,
                          conn_info, common.USERNAME, common.PASSWORD)
    pcf = pymqi.PCFExecute(qmgr, response_wait_interval=5000)

    attrs = [
        pymqi.CFST(
            Parameter=pymqi.CMQC.MQCA_SSL_KEY_REPOSITORY,
            String=pymqi.ensure_bytes('/etc/mqm/pki/keys/{}'.format(qm_name)),
        ),
        pymqi.CFST(Parameter=pymqi.CMQC.MQCA_CERT_LABEL,
                   String=pymqi.ensure_bytes(qm_name)),
    ]
    pcf.MQCMD_CHANGE_Q_MGR(attrs)

    tls_channel_name = pymqi.ensure_bytes(common.CHANNEL_SSL)
    cypher_spec = pymqi.ensure_bytes(common.SSL_CYPHER_SPEC)
    client_dn = pymqi.ensure_bytes('CN={}'.format(common.SSL_CLIENT_LABEL))
    certificate_label_qmgr = pymqi.ensure_bytes(qm_name)

    attrs = [
        pymqi.CFST(Parameter=pymqi.CMQCFC.MQCACH_CHANNEL_NAME,
                   String=pymqi.ensure_bytes(tls_channel_name)),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACH_CHANNEL_TYPE,
                   Value=pymqi.CMQC.MQCHT_SVRCONN),
        pymqi.CFST(Parameter=pymqi.CMQCFC.MQCACH_SSL_CIPHER_SPEC,
                   String=cypher_spec),
        pymqi.CFST(Parameter=pymqi.CMQCFC.MQCACH_SSL_PEER_NAME,
                   String=client_dn),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACH_SSL_CLIENT_AUTH,
                   Value=pymqi.CMQXC.MQSCA_OPTIONAL),
        pymqi.CFST(Parameter=pymqi.CMQC.MQCA_CERT_LABEL,
                   String=certificate_label_qmgr),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACF_REPLACE,
                   Value=pymqi.CMQCFC.MQRP_YES),
    ]
    pcf.MQCMD_CREATE_CHANNEL(attrs)

    attrs = [
        pymqi.CFST(Parameter=pymqi.CMQCFC.MQCACH_CHANNEL_NAME,
                   String=pymqi.ensure_bytes(tls_channel_name)),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACF_CHLAUTH_TYPE,
                   Value=pymqi.CMQCFC.MQCAUT_USERMAP),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACF_ACTION,
                   Value=pymqi.CMQCFC.MQACT_REPLACE),
        pymqi.CFST(Parameter=pymqi.CMQCFC.MQCACH_CLIENT_USER_ID,
                   String=pymqi.ensure_bytes(common.USERNAME)),
        pymqi.CFIN(Parameter=pymqi.CMQC.MQIA_CHECK_CLIENT_BINDING,
                   Value=pymqi.CMQCFC.MQCHK_REQUIRED_ADMIN),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACH_USER_SOURCE,
                   Value=pymqi.CMQC.MQUSRC_MAP),
        pymqi.CFST(Parameter=pymqi.CMQCFC.MQCACH_MCA_USER_ID, String=b'mqm'),
    ]
    pcf.MQCMD_SET_CHLAUTH_REC(attrs)

    attrs = [
        pymqi.CFST(Parameter=pymqi.CMQCFC.MQCACH_CHANNEL_NAME,
                   String=pymqi.ensure_bytes(tls_channel_name)),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACF_CHLAUTH_TYPE,
                   Value=pymqi.CMQCFC.MQCAUT_BLOCKUSER),
        pymqi.CFST(Parameter=pymqi.CMQCFC.MQCACH_MCA_USER_ID_LIST,
                   String=b'nobody'),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACH_WARNING,
                   Value=pymqi.CMQC.MQWARN_NO),
        pymqi.CFIN(Parameter=pymqi.CMQCFC.MQIACF_ACTION,
                   Value=pymqi.CMQCFC.MQACT_REPLACE),
    ]
    pcf.MQCMD_SET_CHLAUTH_REC(attrs)

    pcf.disconnect()
    qmgr.disconnect()