我目前正在开发一个应用程序,它需要连接一个 MQ 队列,以便让队列在另一个服务中保存消息信息。完成后,服务会通过 MQ 队列返回一条结果消息并将其返回给我。
我正在发送一条包含类似于以下 XML 消息的字符串消息:
<?xml version="1.0" encoding="UTF-8"?>
<peticionDemanda>
<subtipo>DEMANDA CONTRATACIÓN</subtipo>
</peticionDemanda>
MQ 似乎没有正确解码“Ó”字符,并且“subtipo”字段被保存为“DEMANDA CONTRATACI├ôN”。
我将消息编码为“UTF-8”,并被告知用于发送消息的 CCSID 是 850 而不是 1208(属于 UTF-8 的那个)。
为了运行 MQ 管理器,我在客户端模式下使用“pymqi”Python 库。这是我用来向队列发送消息并获得响应的 MQManager 类:
class MQManager:
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)
def send_message(self, str_xml_message):
# set message descriptor
request_md = pymqi.MD()
request_md.ReplyToQ = self.queue_response_name
request_md.Format = pymqi.CMQC.MQFMT_STRING
queue_request = pymqi.Queue(self.qmgr, self.queue_request_name)
queue_request.put(str_xml_message.encode("UTF-8"), request_md)
queue_request.close()
# Set up message descriptor for get.
response_md = pymqi.MD()
response_md['CorrelId'] = request_md['MsgId']
gmo = pymqi.GMO()
gmo.Options = pymqi.CMQC.MQGMO_WAIT | pymqi.CMQC.MQGMO_FAIL_IF_QUIESCING
gmo.WaitInterval = 5000 # 5 seconds
queue_response = pymqi.Queue(self.qmgr, self.queue_response_name)
message = queue_response.get_no_rfh2(None, response_md, gmo)
queue_response.close()
return str(message)
def close(self):
self.qmgr.disconnect()
我想知道如何定义 MQ 管理器的 CCSID 值并希望解决代码页不匹配的问题。
谢谢!