Created
October 13, 2022 18:13
-
-
Save muhdkhokhar/721d973d74bea02f045f3a07aeaf9548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You have 3 free member-only stories left this month. Upgrade for unlimited access. | |
Marcus Janke | |
Marcus Janke | |
Dec 27, 2019 | |
· | |
2 min read | |
· | |
· | |
Consuming segmented IBM MQ messages in Java | |
Ever got frustrated about IBM’s MQ message segmentation feature on the consumer's end? I had this feeling a couple of years ago when consuming a queue from an external provider that segmented large messages of batch data. This should spare you some pain. | |
Photo by davide ragusa on Unsplash | |
I found it extremely annoying and cumbersome to find suitable client options to make this work. In fact, I had the feeling that everyone was looking for the answer but no one had been successful. So I had to pick up bits and pieces all over the internet and finally made this work. So here’s what you need to do: | |
Set up your environment: | |
MQEnvironment.hostname = host; | |
MQEnvironment.port = port; | |
MQEnvironment.channel = channel; | |
2. Create your QueueManager instance: | |
MQQueueManager manager = new MQQueueManager("queueManagerName"); | |
3. Access your MQQueue with the correct open options: | |
int openOptions = MQC.MQOO_INPUT_SHARED | |
| MQC.MQOO_INQUIRE | |
| MQC.MQOO_FAIL_IF_QUIESCING; | |
MQQueue queue = manager.accessQueue(queueName, openOptions); | |
MQOO_INPUT_SHARED: Allow shared access to your queue. | |
MQOO_INQUIRE: Allow inquiring queue attributes. | |
MQOO_FAIL_IF_QUIESCING: Checks quiescing state of queue on open. | |
4. Set up the MQGetMessageOptions: | |
MQGetMessageOptions gmo = new MQGetMessageOptions(); | |
gmo.options = MQC.MQGMO_ALL_SEGMENTS_AVAILABLE | |
| MQC.MQGMO_SYNCPOINT | |
| MQC.MQGMO_COMPLETE_MSG; | |
gmo.matchOptions = MQC.MQMO_NONE; | |
gmo.waitInterval = 10000; | |
MQGMO_ALL_SEGMENTS_AVAILABLE: | |
Segments in a logical message become available for retrieval only when all segments in the logical message are available. | |
MQGMO_SYNCPOINT: | |
The message is marked as being unavailable to other applications, but it is deleted from the queue only when the unit of work is committed. The message is made available again if the unit of work is backed out. | |
MQGMO_COMPLETE_MSG: | |
Only a complete logical message can be returned by the MQGET call. If the logical message is segmented, the queue manager reassembles the segments and returns the complete logical message to the application; the fact that the logical message was segmented is not apparent to the application retrieving it. | |
5. Get your MQMessage: | |
MQMessage message = new MQMessage(); | |
queue.get(message, gmo);// Do your stuff with the messagemessage.clearMessage(); | |
queue.close(); | |
manager.disconnect(); | |
The main point is to get the GetMessageOptions right. And that’s basically it. | |
I reckon that reading this might probably raise lots of questions about why the MQ client library is written in this unusual way. I did so, too. And I did not find any suitable answer. You got just to cope with this and encapsulate access as best as possible. ;) | |
Disclaimer: I am perfectly aware that this solution might be totally outdated. I just felt the urge to finally get this off my mind ;) Feel free to comment. | |
More from Marcus Janke | |
Nov 16, 2019 | |
MongoDB map keys with dots in Spring Data | |
I recently had the need to store historical events in a MongoDB document. The requirement was to do this via a Map having an Instant as a key and some data as its value. Naively setting this up in a Spring Data MongoDB document would look like this: @Data @Document public class… | |
Java | |
2 min read | |
MongoDB map keys with dots in Spring Data | |
Share your ideas with millions of readers. | |
Write on Medium | |
Aug 25, 2019 | |
Maven Plugins for Docker | |
Over the years, I tried out several Maven plugins for Docker that enable you to create Docker images within a Maven build. This should give you a quick start into the four most widely used ones at the moment, namely fabric8’s docker-maven-plugin, Spotify’s docker-maven-plugin, Spotify’s dockerfile-maven, and Google’s jib-maven-plugin. We’ll… | |
Docker | |
2 min read | |
Maven Plugins for Docker | |
Jul 4, 2019 | |
Listing all available Thymeleaf context variables | |
A while back, I was looking for a fast but convenient way to quickly see all variables that are available to a Thymeleaf template. One of the options I found, was just listing them in your rendered page itself. The solution is pretty simple. Nonetheless, being not a Thymeleaf god… | |
Thymeleaf | |
1 min read | |
Listing all available Thymeleaf context variables | |
Jul 3, 2019 | |
Docker housekeeping | |
Every once in a while, I just found it useful to do a bit of housekeeping and just get rid of all my local docker images and containers. Having tried out many things and deployed a whole bunch of images just to have a look at some cool new app or version, things might seem messy after a while. So, why not start over? That’s when you could just get rid of all your containers by doing the following: | |
Docker | |
1 min read | |
Docker housekeeping | |
Jul 2, 2019 | |
Writing select columns from one CSV file to another | |
For all you folks that just need a quick shell command to write only select columns from one CSV file to another. Here you go. Simply cut your original CSV using the defined delimiter and select the columns you want: cut -d "," -f 1,2,5 origin.csv > target.csv The above-mentioned command would transform the following origin.csv John,Doe,1950-10-13,123 Main St.,john.doe@gmail.com Jane,Doe,1950-02-22,123 Main St.,jane.doe@gmail.com | |
Bash | |
1 min read | |
Love podcasts or audiobooks? Learn on the go with our new app. | |
Try Knowable | |
Get unlimited access | |
Marcus Janke | |
Marcus Janke | |
More from Medium | |
Alexander Nguyen | |
Alexander Nguyen | |
in | |
Level Up Coding | |
$150,000 Amazon Engineer vs. $300,000 Google Engineer | |
Frank Andrade | |
Frank Andrade | |
in | |
Geek Culture | |
My Top 5 Paid Subscriptions I’ll Never Cancel as a Programmer | |
Ravi Yasas | |
Ravi Yasas | |
Spring Boot Best Practices for Developers | |
Jari Roomer | |
Jari Roomer | |
in | |
WealthWise | |
3 Habits The Wealthiest People Practice Daily That Most Others Don't | |
Help | |
Status | |
Writers | |
Blog | |
Careers | |
Privacy | |
Terms | |
About | |
Knowable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment