JBoss EAPJakarta EEJava 21企業系統升級

JBoss EAP 05: MDBs, resource adapters, and IBM MQ delivery

···5 min read
Back to the JBoss EAP learning path

An HTTP caller waits for a response; an MDB is triggered by container-managed message delivery. If processing updates a database and then fails, rollback and redelivery may follow. Explaining the outcome requires delivery and transaction ownership, not just the body of onMessage.

Version note: this series is based on JBoss EAP 8.1. The Red Hat documentation site now lists a newer 8.2 Beta, which is not a GA release. For version differences, see the Red Hat EAP documentation home in the sources.

A message moves from an IBM MQ queue through wmq.jakarta.jmsra.rar into the EAP EJB container; with container-managed transactions and REQUIRED, message receipt, onMessage, and the database write sit inside one transaction box, and the message is acknowledged at commit; below, bean-managed transactions leave message receipt outside the transaction
The MDB transaction boundary. Rules come from sections 5.4.13 and 5.4.17.1 of the Jakarta Enterprise Beans 4.0 specification; the RAR file name comes from the IBM MQ 9.4 documentation. Diagram drawn by KeepOnFirst.

Draw the complete delivery path

text
IBM MQ queue manager / queue
  → IBM MQ Jakarta resource adapter (RAR)
    → EAP EJB container → MDB.onMessage
      → business service → database

Transaction participation must be verified for each resource.

An MDB belongs to the EJB container; a Spring service belongs to Spring. Both support injection, but their lifecycles do not automatically merge. Identify how a called service is created and how transaction context crosses that boundary. Replacing an MDB with @JmsListener changes ownership and deserves a separate architecture decision.

Record three distinct version fields

Client libraries expose MQ APIs; the resource adapter (RAR) integrates with the application server. IBM distributes wmq.jmsra.rar and wmq.jakarta.jmsra.rar for different API namespaces. Check the Jakarta adapter for this EAP 8.1 path. For example, a client version of 9.4.5.1 alone does not tell you the adapter version. It also does not tell you the remote queue-manager version or support status.

RAR fileAPIServers IBM lists
wmq.jmsra.rarJMS 2.0Java EE 7 or Java EE 8
wmq.jakarta.jmsra.rarJakarta Messaging 3.0Jakarta EE 9.1 (or later)
IBM MQ 9.4 documentation: which specification each RAR matches

EAP 8.1 is Jakarta EE 10, so it matches the second row. Both files come from the same places. After you install the IBM MQ Java messaging component, they are in MQ_INSTALLATION_PATH/java/lib/jca on AIX and Linux. You can also download them separately from IBM Fix Central.

During inventory, copy the deployed RAR file name into the workbook. If it is wmq.jmsra.rar, the JMS 2.0 adapter is installed, which does not match the Jakarta path. Another IBM page says the JMS and Jakarta Messaging MQ classes are interoperable but must not coexist in a single application. Lesson 03 has a package-name table.

Record adapter archive, connection factory, destination binding, physical queue, selector, concurrency, and transaction mode. Activation properties vary by adapter; examples for EAP’s integrated broker are not interchangeable with IBM MQ configuration. The kit contains a synthetic adapter declaration, not deployable MQ connectivity.

Method completion is part of a container transaction

For a container-managed MDB message listener, Jakarta Enterprise Beans permits REQUIRED or NOT_SUPPORTED transaction attributes. These are specification options. To find the effective choice, inspect annotations, descriptors, resources, and runtime. Check the same sources to see whether DB and MQ join one transaction.

The same section has another rule. If an MDB uses bean-managed transactions and calls UserTransaction itself, the message receipt that invokes it is not part of the transaction. For message receipt to be part of the transaction, use container-managed transactions with REQUIRED.

Section 5.4.17.1 covers acknowledgment: the container handles message acknowledgment automatically. With container-managed transactions, acknowledgment is part of the transaction commit.

DemarcationReceipt in the transaction?When the message is acknowledged
container-managed + REQUIREDYes (5.4.13)At transaction commit (5.4.17.1)
bean-managed (UserTransaction)No (5.4.13)Handled by the container (5.4.17.1)
Is message receipt part of the transaction? (Jakarta Enterprise Beans 4.0)

An inference from this: with the first row’s setup, a rollback means the message is not acknowledged. Whether it is delivered again, the redelivery count, and where it ends up is not decided by the specification for IBM MQ. Check the adapter and queue configuration.

Section 8.6.5.2 covers REQUIRED message listener methods and has two key sentences. “The transaction is committed when the onMessage method has completed.” “If the onMessage method does not successfully complete or the transaction is rolled back, message redelivery semantics apply.”

How it endsTransactionSource
Returns normallyCommitted8.6.5.2
Throws a system exceptionContainer-started transaction rolled back, instance discarded, EJBException wrapping the original sent to the adapter9.3.4, Table 12
Calls setRollbackOnly, then returnsRolled back, not committed, when the method completes8.6.5.3
Three ways onMessage can end (container-managed + REQUIRED)

So the workbook needs at least three cells: RAR file name, transaction demarcation, and transaction attribute. Only with all three can you predict whether a failed message comes back. If one is missing, write “unknown” as the expectation.

The specification does not describe the “after catch” case directly. An inference from the table: if you catch an exception, log it, and return normally, the method has completed. The transaction commits. The message is not redelivered for that reason. To roll back, let a system exception propagate or call setRollbackOnly. Rollback can lead to another delivery of the same business event. Do not assume a single delivery. Verify redelivery thresholds, backout/error queues, and recovery against adapter, queue, and application configuration.

Exercise: fail after the database write

SurfaceRecord
DBOriginal state, changes, final transaction outcome
MQMessage identity, business key, delivery/error outcome
LogsCase correlation, exception, transaction outcome
RetryWhether the same event creates a duplicate side effect
Write expectations before gathering evidence in an isolated environment.

The answer is not always rollback. Derive expectations from the verified transaction model: one effective XA transaction and two independent commits can fail differently. Evaluate duplicates with the business key and established contract, not only one MQ message ID. Preserve the failure point and all evidence; this tutorial has not executed an enterprise MQ integration test.

Download the EAP offline kit: inventory, exercises, workbookNext: 06: Debugging and migration evidencePractice: lesson 10 transaction and redelivery model

Sources