Chapter 19 Exercises: IBM MQ for COBOL
Section A: Conceptual Understanding (Exercises 1–8)
Exercise 1: The Four Couplings
List the four types of coupling that point-to-point integration creates (temporal, spatial, format, capacity). For each, write one sentence explaining how MQ eliminates or reduces it. Then describe a real scenario from your own environment where one of these couplings has caused an outage or delayed a project.
Exercise 2: Time Decoupling Scenarios
For each of the following scenarios, explain how temporal decoupling changes the system architecture compared to a synchronous point-to-point approach:
a) A core banking system sends end-of-day account balance updates to a reporting warehouse. The warehouse is unavailable during its nightly ETL window (11 PM–3 AM), but the core banking system generates balances at midnight.
b) A claims processing system at Pinnacle Health Insurance needs to send adjudication results to three downstream systems: payment, member notification, and regulatory reporting. Each downstream system processes at different speeds.
c) Federal Benefits Administration needs to receive enrollment updates from 50 state systems, but not all states transmit at the same time — some send batch files at midnight, others trickle in throughout the day.
Exercise 3: Queue Types Matching
Match each scenario to the correct queue type (local, remote, transmission, dead letter, model, alias):
a) A program on LPAR A needs to send messages to a queue on LPAR B without knowing the target queue manager's network address.
b) MQ needs a place to hold messages in transit between two queue managers until the channel initiator sends them.
c) A request/reply pattern needs temporary queues for replies, with each queue inheriting standard security and persistence settings.
d) A message can't be delivered because the target queue is full.
e) You're migrating from an old queue name to a new one and can't change all 15 sending programs at once.
f) A consumer program reads messages from its local queue manager.
Exercise 4: MQ Architecture Diagram
Draw (on paper or in a tool) the complete message flow for this scenario: Program A on queue manager QM01 sends a message to Program B on queue manager QM02. Include all queue objects (remote queue definition, transmission queue, local queue), channels (sender and receiver), and the channel initiator. Label every component.
Exercise 5: MQMD Field Analysis
For each MQMD field below, explain its purpose and describe a bug that could result from setting it incorrectly:
a) MQMD-PERSISTENCE b) MQMD-EXPIRY c) MQMD-REPLYTOQ d) MQMD-CORRELID e) MQMD-MSGTYPE f) MQMD-FORMAT g) MQMD-PRIORITY
Exercise 6: Pattern Selection
For each business requirement below, select the appropriate message pattern (datagram, request/reply, pub/sub) and justify your choice. Identify any cases where multiple patterns could work and explain the tradeoff.
a) When a wire transfer is approved, the compliance department, the customer notification system, and the general ledger all need to know.
b) Before approving a loan, the lending system needs a credit score from an external bureau. The bureau returns scores within 3 seconds.
c) When a customer changes their address, the core banking system needs to update its records. No response is needed from the core system.
d) Every ATM transaction must be checked against the fraud model before the ATM dispenses cash. The fraud check must return within 500ms.
e) The treasury system publishes the daily FX rate schedule. Six systems consume it.
f) A batch process generates 500,000 account statements and needs to queue them for the print/mail vendor system.
Exercise 7: Transactional Boundaries
Explain why the following code sequence is dangerous. What could go wrong? How would you fix it?
EXEC SQL
UPDATE ACCOUNTS
SET BALANCE = BALANCE - :WS-AMOUNT
WHERE ACCOUNT_NUM = :WS-ACCT
END-EXEC
EXEC CICS SYNCPOINT END-EXEC
CALL 'MQPUT' USING WS-HCONN
WS-HOBJ
MQMD
MQPMO
WS-MSG-LENGTH
WS-MSG-BUFFER
WS-COMPCODE
WS-REASON
Exercise 8: Shared Queues vs. Clusters
A bank runs two LPARs in a Parallel Sysplex. They need to ensure that if one LPAR fails, the other can immediately process all queued messages with zero message loss. Which MQ HA mechanism should they use, and why? What hardware prerequisite does this mechanism require?
Section B: Code Analysis (Exercises 9–16)
Exercise 9: Find the Bugs
The following COBOL MQ code has five bugs or bad practices. Find all five and explain the correct approach for each:
4000-PUT-MESSAGE.
MOVE MQMT-DATAGRAM TO MQMD-MSGTYPE
MOVE MQPER-NOT-PERSISTENT
TO MQMD-PERSISTENCE
MOVE MQPMO-NO-SYNCPOINT
TO MQPMO-OPTIONS
CALL 'MQPUT' USING WS-HCONN
WS-HOBJ
MQMD
MQPMO
WS-MSG-LENGTH
WS-MSG-BUFFER
WS-COMPCODE
WS-REASON
ADD 1 TO WS-PUT-COUNT.
Hint: Consider persistence, syncpoint, FAIL-IF-QUIESCING, error checking, and message ID generation.
Exercise 10: Complete the Error Handler
The following error handler skeleton needs to handle eight specific MQ reason codes. Complete the EVALUATE block with appropriate actions for each:
8000-HANDLE-MQ-ERROR.
EVALUATE WS-REASON
WHEN MQRC-NOT-AUTHORIZED
???
WHEN MQRC-Q-FULL
???
WHEN MQRC-CONNECTION-BROKEN
???
WHEN MQRC-Q-MGR-QUIESCING
???
WHEN MQRC-TRUNCATED-MSG-FAILED
???
WHEN MQRC-PUT-INHIBITED
???
WHEN MQRC-GET-INHIBITED
???
WHEN MQRC-BACKED-OUT
???
WHEN OTHER
???
END-EVALUATE.
For each case, specify: (1) whether to retry, abend, or continue; (2) what to log; (3) whether to alert operations.
Exercise 11: Request/Reply Completion
The following sender code puts a request but the reply retrieval is incomplete. Complete the MQGET section to properly retrieve the reply by correlation ID, handle timeout, and process the response:
* Request has been sent. MQMD-MSGID contains the
* message ID of the request.
MOVE MQMD-MSGID TO WS-SAVED-MSGID
* TODO: Complete the reply retrieval
* Requirements:
* - Get from WS-HOBJ-REPLY (already opened)
* - Match on correlation ID
* - Wait up to 10 seconds
* - Handle timeout (route to manual review)
* - Handle success (call 5000-PROCESS-REPLY)
* - Handle all other errors (call 8000-HANDLE-MQ-ERROR)
Exercise 12: Backout Handler
Write a complete COBOL paragraph that checks the backout count of a received message. If the count exceeds the threshold (defined in WS-BACKOUT-THRESH), route the message to the backout queue (WS-BACKOUT-QNAME), commit the routing, log the event, and increment a poison message counter. If the count is below the threshold, fall through to normal processing.
Exercise 13: DLQ Processor
Write the main processing loop for a DLQ processor program. The program should: 1. Connect to queue manager WS-QMGR-NAME 2. Open the dead letter queue 3. Loop, getting messages with a 5-second wait 4. For each message, extract the MQDLH header 5. Based on the DLQ reason code, either attempt redelivery (for MQRC-Q-FULL) or write to an exception log (for all others) 6. Commit after each message 7. Exit cleanly when no more messages or when quiescing
Write the main loop and the redelivery logic. You may reference paragraphs without writing them (e.g., PERFORM 9500-WRITE-EXCEPTION-LOG).
Exercise 14: Trigger Monitor Analysis
Given the following queue definition:
DEFINE QLOCAL(APP.INBOUND.QUEUE) +
TRIGGER +
TRIGTYPE(FIRST) +
PROCESS(APP.PROCESS) +
INITQ(SYSTEM.CICS.INITIATION.QUEUE)
BOTHRESH(5) +
BOQNAME(APP.INBOUND.BACKOUT)
DEFINE PROCESS(APP.PROCESS) +
APPLICID('APRC') +
APPLTYPE(CICS)
Answer the following: a) When does CICS transaction APRC get triggered? b) If three messages arrive in quick succession, how many times is APRC triggered? c) What happens when APRC abends after getting the first message? d) After how many abends will the message be moved to the backout queue? e) What would change if TRIGTYPE were EVERY instead of FIRST?
Exercise 15: Message Format Versioning
Write COBOL WORKING-STORAGE definitions for a versioned message format. The message should include: - A fixed-length header with format ID, version number, timestamp, and body length - Version 1 body: account number, amount, transaction type - Version 2 body: adds originating channel and customer reference - A processing paragraph that reads the version and handles both versions
Exercise 16: Pub/Sub Implementation
Write the COBOL code for a subscriber program that: 1. Creates or resumes a durable subscription to topic 'BANK/RATES/INTEREST' 2. Gets published messages in a loop with a 15-second wait 3. Processes each rate update by extracting the rate type and new value 4. Handles the case where the topic has been deleted (MQRC-UNKNOWN-OBJECT-NAME) 5. Cleans up the subscription on exit
Section C: Design and Architecture (Exercises 17–22)
Exercise 17: CNB Queue Architecture
Continental National Bank's core banking system needs to communicate with the following systems via MQ: - Wire transfer processing - ACH batch processing - ATM network - Online banking - Mobile banking - Fraud detection (request/reply) - Compliance screening - General ledger - Customer notification
Design the complete queue architecture for queue manager CNBPQM01. For each message flow, specify: - Queue names (following the CNB.{system}.{type} convention) - Queue type (local, remote, alias) - Message pattern (datagram, request/reply, pub/sub) - Persistence setting - Trigger configuration (if applicable) - Backout queue and threshold
Exercise 18: Cross-LPAR Message Flow
Design the complete MQ configuration (queue managers, queues, channels) to support this flow: A CICS transaction on LPAR A puts a message that must be processed by a batch program on LPAR B. The batch program puts a response that the original CICS region (on LPAR A) picks up. Include all object definitions in MQSC format.
Exercise 19: Failure Mode Analysis
For each failure scenario below, trace the exact behavior of the MQ infrastructure. What happens to in-flight messages? What does the application see? What manual intervention (if any) is required?
a) Queue manager crashes while a persistent message is being put under syncpoint b) Channel between two queue managers goes down while 500 messages are on the transmission queue c) A consuming program abends repeatedly, hitting the backout threshold on every message d) The dead letter queue reaches MAXDEPTH e) A queue manager is quiescing but a long-running batch program has 10,000 messages still to put f) The Coupling Facility structure for shared queues has a hardware failure
Exercise 20: Pinnacle Health Claims Messaging
Pinnacle Health Insurance processes 50 million claims per month. Design an MQ messaging architecture for the claims pipeline:
- Claims arrive via EDI from 2,000 provider systems
- Each claim goes through: validation → adjudication → payment → notification
- Claims that fail validation are routed to a manual review queue
- Adjudication requires a request/reply call to the medical rules engine (2-second SLA)
- Payment messages go to the bank interface
- Notification messages go to both member and provider portals
Consider: queue sizing, message priorities, backout handling, monitoring, and HA strategy.
Exercise 21: Migration Planning
Federal Benefits Administration is migrating from a flat-file integration between the enrollment system and the benefits calculation system to MQ. Currently: - Enrollment sends a flat file via Connect:Direct at 2 AM - Benefits calculation picks it up and processes it in a 4-hour batch window - If the file is missing or corrupt, the batch job abends and operations restarts manually
Design the MQ replacement. Address: a) Queue and channel definitions b) Message format (individual records vs. batch messages) c) Error handling for the transition period when both systems must work d) Rollback plan if the MQ implementation fails
Exercise 22: Capacity Planning
A queue processes 5,000 messages per second during peak hours, with an average message size of 4 KB. All messages are persistent. The consuming application processes at 4,800 messages per second during peak.
Calculate: a) Queue depth after 1 hour of peak processing (messages accumulate at 200/sec) b) Log volume per hour (persistent messages, dual logging) c) Time to drain the accumulated queue after peak ends (assuming consumers continue at 4,800/sec and input drops to 2,000/sec) d) MAXDEPTH recommendation (with 50% headroom) e) What happens if the consumer goes down for 30 minutes during peak?
Section D: Advanced Challenges (Exercises 23–25)
Exercise 23: Two-Phase Commit Deep Dive
Write a complete COBOL CICS program that: 1. Receives a wire transfer request via MQGET from a request queue 2. Validates the request against account data in DB2 3. If valid: debits the source account in DB2, credits the destination account in DB2, puts a confirmation message to MQ, and puts an audit message to a second MQ queue 4. All four operations (2 DB2 updates, 2 MQPUTs) must be atomic 5. If any operation fails, all operations roll back 6. Handles the timeout case where the request has already expired (check MQMD-EXPIRY) 7. Includes complete error handling per the four-layer model
This should be a complete, compilable COBOL program (IDENTIFICATION through end).
Exercise 24: MQ Performance Benchmark Design
Design a performance benchmark for an MQ-based message flow. The benchmark should: 1. Measure throughput (messages per second) for various message sizes (100 bytes, 1 KB, 4 KB, 32 KB, 100 KB) 2. Measure latency (time from MQPUT to MQGET) for persistent and non-persistent messages 3. Test with 1, 5, 10, and 20 concurrent producers and consumers 4. Identify the saturation point (where throughput stops increasing) 5. Produce output suitable for a capacity planning report
Write the COBOL producer and consumer programs. Include timing logic using CICS ASKTIME or LE callable services.
Exercise 25: End-to-End Integration Scenario
SecureFirst Retail Bank is adding a new real-time payment capability. The flow is:
- Customer initiates payment on mobile app
- Mobile API gateway puts a message to MQ on z/OS
- COBOL CICS transaction validates and authorizes the payment
- If authorized, the COBOL program puts a message for the FedNow interface
- FedNow returns a confirmation (or rejection) via MQ
- The COBOL program updates the account in DB2
- A notification message is published for the mobile app
Design and implement (in COBOL pseudo-code with real MQI calls) the complete flow. Include: - Queue architecture (all queue definitions) - Channel definitions for the mobile gateway connection - The main COBOL transaction (full MQI code) - Error handling for every failure point - The notification pub/sub setup - Monitoring and alerting strategy
Submission Notes
- Exercises 1–8 are conceptual and can be answered in prose or diagrams.
- Exercises 9–16 require COBOL code. Write complete, syntactically correct paragraphs.
- Exercises 17–22 require architectural deliverables: MQSC definitions, flow diagrams, and design justifications.
- Exercises 23–25 are advanced integrations. Exercise 23 should be a complete COBOL program. Exercises 24–25 may use pseudocode for non-MQI logic but must have real MQI calls.
- All queue names should follow a consistent naming convention.
- All code must include error handling — submissions without CC/RC checking after every MQI call will be returned.