def buildMQDetails(): for key in [ EnvStore.QMGR, EnvStore.QUEUE_NAME, EnvStore.CHANNEL, EnvStore.HOST, EnvStore.PORT, EnvStore.KEY_REPOSITORY, EnvStore.CIPHER ]: MQDetails[key] = EnvStore.getEnvValue(key)
def putMessage(): logger.info('Attempting put to Queue') try: # queue.put(json.dumps(msgObject).encode()) # queue.put(json.dumps(msgObject)) # Prepare a Message Descriptor for the request message. logger.info('Dynamic Queue Name is ') logger.info(dynamic['name']) md = pymqi.MD() md.ReplyToQ = dynamic['name'] md.MsgType = pymqi.CMQC.MQMT_REQUEST md.Format = pymqi.CMQC.MQFMT_STRING # Send the message. #queue.put(str(json.dumps(msgObject)), md) queue.put(EnvStore.stringForVersion(json.dumps(msgObject)), md) # queue.put(str(json.dumps(msgObject)), md) # queue.put("Hello") logger.info("Put message successful") #logger.info(md.CorrelID) return md.MsgId, md.CorrelId # return md.CorrelId except pymqi.MQMIError as e: logger.error("Error in put to queue") logger.error(e)
def buildMQDetails(): for key in [ 'QMGR', 'QUEUE_NAME', 'CHANNEL', 'HOST', 'PORT', 'MODEL_QUEUE_NAME', 'DYNAMIC_QUEUE_PREFIX', 'KEY_REPOSITORY', 'CIPHER' ]: MQDetails[key] = EnvStore.getEnvValue(key)
def publishMessage(): logger.info('Attempting publish to Topic') try: # queue.put(json.dumps(msgObject).encode()) # queue.put(json.dumps(msgObject)) # topic.pub(str(json.dumps(msgObject))) topic.pub(EnvStore.stringForVersion(json.dumps(msgObject))) logger.info("Publish message successful") except pymqi.MQMIError as e: logger.error("Error in publish to topic") logger.error(e)
def putMessage(): logger.info('Attempting put to Queue') try: # queue.put(json.dumps(msgObject).encode()) # queue.put(json.dumps(msgObject)) # queue.put(str(json.dumps(msgObject))) #queue.put(bytes(json.dumps(msgObject), 'utf-8')) queue.put(EnvStore.stringForVersion(json.dumps(msgObject))) logger.info("Put message successful") except pymqi.MQMIError as e: logger.error("Error in put to queue") logger.error(e)
def respondToRequest(md, msgObject): # Create a response message descriptor with the CorrelId # set to the value of MsgId of the original request message. response_md = pymqi.MD() response_md.CorrelId = md.CorrelId response_md.MsgId = md.MsgId msgReply = { 'Greeting': "Reply from Python! " + str(datetime.datetime.now()), 'value': random.randint(1, 101) } replyQueue = getQueue(md.ReplyToQ, False) if (msgObject['value']): msgReply['value'] = performCalc(msgObject['value']) #replyQueue.put(str(json.dumps(msgReply)),response_md ) replyQueue.put(EnvStore.stringForVersion(json.dumps(msgReply)), response_md)
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
logger.info("Publish message successful") except pymqi.MQMIError as e: logger.error("Error in publish to topic") logger.error(e) def buildMQDetails(): for key in [EnvStore.QMGR, EnvStore.CHANNEL, EnvStore.HOST, EnvStore.PORT, EnvStore.KEY_REPOSITORY, EnvStore.CIPHER, EnvStore.TOPIC_NAME]: MQDetails[key] = EnvStore.getEnvValue(key) # Application Logic starts here logger.info("Application is Starting") envStore = EnvStore() envStore.setEnv() MQDetails = {} credentials = { EnvStore.USER: EnvStore.getEnvValue(EnvStore.APP_USER), EnvStore.PASSWORD: EnvStore.getEnvValue(EnvStore.APP_PASSWORD) } buildMQDetails() logger.info('Credentials are set') #logger.info(credentials) #conn_info = "%s(%s)" % (MQDetails[EnvStore.HOST], MQDetails[EnvStore.PORT]) conn_info = EnvStore.getConnection(EnvStore.HOST, EnvStore.PORT)
def buildMQDetails(): for key in [ 'QMGR', 'TOPIC_NAME', 'CHANNEL', 'HOST', 'PORT', 'KEY_REPOSITORY', 'CIPHER' ]: MQDetails[key] = EnvStore.getEnvValue(key)
logger.info('Have received a keyboard interrupt') keep_running = False def buildMQDetails(): for key in [ 'QMGR', 'TOPIC_NAME', 'CHANNEL', 'HOST', 'PORT', 'KEY_REPOSITORY', 'CIPHER' ]: MQDetails[key] = EnvStore.getEnvValue(key) # Application Logic starts here logger.info("Application is Starting") envStore = EnvStore() envStore.setEnv() MQDetails = {} credentials = { 'USER': EnvStore.getEnvValue('APP_USER'), 'PASSWORD': EnvStore.getEnvValue('APP_PASSWORD') } buildMQDetails() logger.info('Credentials are set') logger.info(credentials) #conn_info = "%s(%s)" % (MQDetails['HOST'], MQDetails['PORT']) conn_info = EnvStore.getConnection('HOST', 'PORT')
def setCredentials(index): credentials[EnvStore.USER] = EnvStore.getEnvValue(EnvStore.APP_USER, index) credentials[EnvStore.PASSWORD] = EnvStore.getEnvValue( EnvStore.APP_PASSWORD, index)
EnvStore.HOST, EnvStore.PORT, EnvStore.KEY_REPOSITORY, EnvStore.CIPHER ]: MQDetails[key] = EnvStore.getEnvValue(key, index) def setCredentials(index): credentials[EnvStore.USER] = EnvStore.getEnvValue(EnvStore.APP_USER, index) credentials[EnvStore.PASSWORD] = EnvStore.getEnvValue( EnvStore.APP_PASSWORD, index) # Application Logic starts here logger.info("Application is Starting") envStore = EnvStore() envStore.setEnv() MQDetails = {} credentials = {} logger.info('Credentials are set') #logger.info(credentials) #conn_info = "%s(%s)" % (MQDetails[EnvStore.HOST], MQDetails[EnvStore.PORT]) #conn_info = EnvStore.getConnection(EnvStore.HOST, EnvStore.PORT) qmgr = None queue = None numEndPoints = envStore.getEndpointCount()