29
Fri, Nov
0 New Articles

Practical RPG: RPG and IBM WebSphere MQ

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

WebSphere MQ is IBM's flagship product for providing reliable inter-platform messaging, and accessing MQ from RPG is easy once you understand the techniques.

 

I have a hard time with the rebranding of IBM's MQSeries to WebSphere MQ; it's always seemed to me to be one of the more random renamings. MQSeries had great brand recognition as it was. But regardless of the name, MQ has always provided a powerful queuing architecture, and I guess a rose by any name holds true here. The purpose of this article is not to bemoan the naming but to introduce the architecture to RPG programmers.

 

Why MQ?

Given my last three articles on data queues, you might wonder why I'm even writing about WebSphere MQ. The primary reason is that MQ Series is the next step in architecture after data queues. Without going into a point-by-point comparison, MQ provides a number of industrial-strength capabilities that aren't available in data queues. You could add them yourself, but with WebSphere MQ all of the coding is done for you. This doesn't come for free; WebSphere MQ is an added expense and not a cheap one, depending on the platform. But the beauty is that once you learn it on one platform, you can use it on any platform.

 

RPG vs. Java

Since WebSphere MQ is a multi-platform product, your best access is probably through Java. However, if your primary area of concern is writing programs on the IBM i that interface with WebSphere MQ and you aren't already Java proficient, then this article will give you a little help in how to access the product. I will take the opportunity to once again briefly evangelize for Java proficiency; it opens up so many other worlds for an RPG programmer that it's simply a no-brainer that Java be your next language. But we can discuss that another day.

 

MQ Basics

So let's get down to basics. In MQ, you have three basic components: the queue manager, the queue, and the message. Here's the relationship:

 

100312PlutaImage1                       

Figure 1: This is the relationship of the primary objects in a WebSphere MQ setup.

 

The queue manager provides the coordination and servicing of the queues. This includes delivery, trigger and instrumentation events, creation and deletion, holding and releasing, and all of the other management functions. Also, the queue manager is the primary unit of "location"; a queue manager is associated with a physical machine. Any messages destined for a queue for another queue manager must be routed through a remote queue. A remote queue on one queue manager is tied to a local queue on another queue manager. Figure 1 shows some of these relationships. Note that technically the remote queue manager can even be on the same machine as the local queue manager; in this manner, the applications can be segregated while still running on the same machine; this allows portions of the application to be distributed throughout the network as necessary with no changes to the application code.

 

Note that this is only one of a variety of configurations available. It would take a whole series of articles to address various issues such as channels, clusters, namelists, publish and subscribe, predefined and dynamic queues, transaction control, dead letter queues, and so on.

 

Accessing the Queues

The simplest type of communication is the asynchronous put, also known as "fire and forget." For an asynchronous put, there are five basic steps:

  1. 1.Connect to a queue manager.
  2. 2.Open a queue.
  3. 3.Put (send) a message.
  4. 4.Close the queue.
  5. 5.Disconnect from the queue manager.

 

All of this is done via simple calls to the LIBMQM service program in library QMQM. The calls are relatively simple and very consistent. We only need a few variables:

 

d mq_HCONN       s             10i 0

d mq_OPTS         s             10i 0

d mq_HOBJ         s             10i 0

d mq_OCODE       s             10i 0

d mq_CCODE       s            10i 0

d mq_REASON       s             10i 0

                                    

d mq_QMNAME       s             48  

d mq_QNAME       s             48  

 

 

Here's the call to connect to a queue manager:

 

MQCONN( mq_QMNAME: mq_HCONN: mq_OCODE: mq_REASON);

 

The variable mq_QMNAME contains the name of the queue manager. WebSphere MQ allows up to 48 characters for the name of the queue manager and, as we'll see in a moment, another 48 characters for the name of the queue. You can see that mq_HCONN is a simple integer used to identify the connection. This value is called a "handle," hence the H in HCONN. The value is meaningless to the calling application and is only provided to pass back into other APIs to identify the queue manager. Later in fact you'll use that handle to open a queue in the queue manager:

 

MQOPEN( mq_HCONN: MQOD: mq_OPTS: mq_HOBJ: mq_OCODE: mq_REASON);

 

To open a queue, we call MQOPEN, passing in the connection handle, the queue descriptor (MQOD), and some options (mq_OPTS), and getting back a handle to the queue object (mq_HOBJ). You'll notice that the last two parameters for both calls are two more integers, the completion code (mq_OCODE) and the reason code (mq_REASON). Typically, both the completion code and the reason code should be zero for the action to be considered to have completed successfully. This is the standard reporting procedure for all of the WebSphere MQ APIs and one you should be familiar with.

 

The completion code is OK, warning, or failure. For anything other than OK, the reason code will clarify the actual error that occurred. You can go here for a list of the reason codes and explanations of each. The rest of the code consists of very similar calls to WebSphere MQ APIs:

 

MQPUT( mq_HCONN: mq_HOBJ: MQMD: MQPMO:            

       BufferLen: BufferPtr: mq_CCODE: mq_REASON);

MQCLOSE( mq_HCONN: mq_HOBJ: mq_OPTS: mq_CCODE: mq_REASON);

MQDISC( mq_HCONN: mq_OCODE: mq_REASON);

 

The MQPUT API has a few extra parameters: the handles for the connection and the queue, followed by the description and options for the message, the buffer length and pointer, and then finally the completion code and reason code. MQCLOSE has the two handles and some options, followed by the standard method. MQDISC is even simpler: the handle to the queue manager you're closing and the completion code and reason code. So as you can see, one of the most consistent actions in communicating with WebSphere MQ is to check the completion code and reason code. In my code, I have a standard routine that does that and logs any errors.

 

The get sequence is almost identical; connecting to a queue manager, opening a queue, and closing the queue and queue manager are all required for the get just as for the put. The only difference is that there are quite a few more options on the get, from the idea of a timeout value to the concept of browsing versus actually popping something off the stack. Maybe when we get a chance we can spend little more time on the APIs themselves, including the options. But for now, this is a quick glimpse into working with WebSphere MQ. Thanks for reading!

Joe Pluta

Joe Pluta is the founder and chief architect of Pluta Brothers Design, Inc. He has been extending the IBM midrange since the days of the IBM System/3. Joe uses WebSphere extensively, especially as the base for PSC/400, the only product that can move your legacy systems to the Web using simple green-screen commands. He has written several books, including Developing Web 2.0 Applications with EGL for IBM i, E-Deployment: The Fastest Path to the Web, Eclipse: Step by Step, and WDSC: Step by Step. Joe performs onsite mentoring and speaks at user groups around the country. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Joe Pluta available now on the MC Press Bookstore.

Developing Web 2.0 Applications with EGL for IBM i Developing Web 2.0 Applications with EGL for IBM i
Joe Pluta introduces you to EGL Rich UI and IBM’s Rational Developer for the IBM i platform.
List Price $39.95

Now On Sale

WDSC: Step by Step WDSC: Step by Step
Discover incredibly powerful WDSC with this easy-to-understand yet thorough introduction.
List Price $74.95

Now On Sale

Eclipse: Step by Step Eclipse: Step by Step
Quickly get up to speed and productivity using Eclipse.
List Price $59.00

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: