Is it possible to implement message segmentation using JMS as it is in using Native IBM API as shown here. One posible solution I have read is message grouping for JMS. is anyone using this an alternative solution to Segmentation, using JMS?
Yes, you can implement message segmentation using JMS as described here.
No, that's not segmentation. That's grouping. It is similar, but it's also not using JMS. As far as I can tell, segmentation is not supported in IBM's implementation of JMS.
I found some dirty solution for this problem using IBM's implementation of JMS. I did not find a solution how i can from my application, but you can do this in com.ibm.mq.jmqi.jar
of the MQ version that you use (for me it was be 9.0.0.0)
Receiving segments as complete message
For receiving complete message from MQ you need to set MQGMO_COMPLETE_MSG flag to GMO.Options.
At first you need find and decompile com.ibm.mq.jmqi.MQGMO.class
(i did it using the IntelliJ or u can use some decompiler for example http://java-decompiler.github.io/ or web decompiler http://www.javadecompilers.com).
Then for each call of setting GMO.Options you need to add MQGMO_COMPLETE_MSG header, just replace method setOptions
in MQGMO.java
with this code:
public void setOptions(int var1) {
var1 = var1 & -4097 | 65536;
if (Trace.isOn) {
Trace.data(this, "com.ibm.mq.jmqi.MQGMO", "setOptions(int)", "setter", var1);
}
this.options = var1;
}
And you need to replace value of version-field - private int version = 2;
.
Then you need to recompile this class, you can use command "path_to_jdk_folder\bin\javac" -classpath com.ibm.mq.jmqi.jar MQGMO.java
.
And last step you need to place MQGMO.class
into com.ibm.mq.jmqi.jar
, you can do this with command "path_to_jdk_folder\bin\jar" uf com.ibm.mq.jmqi.jar com/ibm/mq/jmqi/MQGMO.class
. The path com/ibm/mq/jmqi/MQGMO.class
required in your file system to correctly place the class in com.ibm.mq.jmqi.jar
.
Be careful and check that the class has really been replaced.
At now you can put your patched jar to classpath of your application and check that you can receive a completed messages from queue.
Sending large message as segments
To send large messages and tell IBM MQ to segment them you need to set MQMD flag - MQMF_SEGMENTATION_ALLOWED.
At first you need find and decompile com.ibm.mq.jmqi.MQMD.class
(how to do this - look at previous part).
Then you need to set the values in some fields instead of existing:
private int msgFlags = 1;
private int version = 2;
Field msgType = 2
are setting property MQMF_SEGMENTATION_ALLOWED to all outcoming messages.
Then you need to recompile this class as in the previous part and put it into com.ibm.mq.jmqi.jar
.
You can verify this solution by putting the large message in a queue with small message length limitation.
Be careful
Be careful that classpath of your application has no duplicates of com.ibm.mq.jmqi.MQMD.class
and com.ibm.mq.jmqi.MQGMO.class
classes.
来源:https://stackoverflow.com/questions/8134485/is-ibm-mq-message-segmentation-possible-using-jms