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 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)