求 MQ消息分段传输的JAVA例子,该怎么处理

求 MQ消息分段传输的JAVA例子
求 MQ消息分段传输的JAVA例子

------解决方案--------------------
使用 Group 发送消息,给每个消息编号。

/**
* send a message to queue connected currently.
*/
public void send() {
if (!checkStatus(this.queue)) {
return;
}

String content = getTaMessage().getText();

MQMessage msg = new MQMessage();

// sender /receiver at same queue manager.
msg.replyToQueueManagerName = this.queueManager.name;
msg.replyToQueueName = this.queue.name;

msg.messageType = isReply() ? MQC.MQMT_REPLY : MQC.MQMT_REQUEST;//是请求还是应答。

msg.putApplicationName = "MQ Training Frame";
msg.putApplicationType = MQC.MQAT_JAVA;
  
String ccsid = getInputCcsid().getText();

if(ccsid != null && ccsid.trim().length()>0) {
msg.encoding = MQC.MQENC_NATIVE;
msg.characterSet = Integer.parseInt(ccsid);
}

msg.report = MQC.MQRO_COA | MQC.MQRO_COD; //请求接收方给出发送成功应答报告,和交付给接收者的报告。

String receiver = getInputReceiver().getText();
  
if (receiver != null && receiver.trim().length() > 0) {
msg.correlationId = receiver.trim().getBytes(); // 请求应答模式下给出原请求的编号 。
}
  
if (this.userId != null && this.userId.trim().length() > 0) {
msg.userId = this.userId.trim();
}

try {
msg.writeString(content);

MQPutMessageOptions putOptions = new MQPutMessageOptions();

putOptions.options = MQC.MQPMO_SYNCPOINT; // 需要事务支持。

if (isGroupEnabled()) {

msg.messageFlags = MQC.MQMF_MSG_IN_GROUP; //标记这个消息是某个组中的一部分。

if (isLastMessageInGroup()) {
msg.messageFlags |= MQC.MQMF_LAST_MSG_IN_GROUP; // 这个消息标记为组中的最后一个
}

if (isOrderEnabled()) {
putOptions.options |= MQC.MQPMO_LOGICAL_ORDER; //本组消息要求按序交付给接收方,接收方迭代获取该组消息时将不会按错误的次序取。
}

msg.messageSequenceNumber = getSequenceInGroup(); // 自己连续编号。

String groupId = getGroupId();

if (groupId == null || groupId.trim().length() == 0) {
groupId = UUIDGenerator.getInstance().generateTimeBasedUUID()
.toString(); // 生成随机组编号 。
}

msg.groupId = groupId.getBytes();
}

logger
.log("Message [option : Ordering :"
+ ((putOptions.options | MQC.MQPMO_LOGICAL_ORDER) == MQC.MQPMO_LOGICAL_ORDER)
+ "/"
+ isOrderEnabled()
+ "],[flag : Grouping :"
+ ((msg.messageFlags | MQC.MQMF_MSG_IN_GROUP) == MQC.MQMF_MSG_IN_GROUP)
+ "/"
+ isGroupEnabled()
+ ", is last :"
+ ((msg.messageFlags | MQC.MQMF_LAST_MSG_IN_GROUP) == MQC.MQMF_LAST_MSG_IN_GROUP)
+ "/" + isLastMessageInGroup() + "],[Group ID :"
+ translateCString(msg.groupId) + "],[Sequence :"
+ msg.messageSequenceNumber + "]");

this.queue.put(msg, putOptions);

appendHistory(msg, "Send", content);

getTaMessage().setText("");

logger.log("Sent successfully.");

setReply(false);

dirty = true;

} catch (Exception e) {
logger.log(e);
}
}