3.16.3 Message inflow
(1) Preconditions
The message inflow is enabled when the resource adapters and Message-driven Beans satisfy the following conditions:
- The Message-driven Beans invoked in the message inflow must conform to EJB 2.1 or later.
With EJB 2.1 or later, the Message-driven Bean can implement any message listener and not only javax.jms.MessageListener. A message listener is a listener used to deliver messages between the resource adapters and Message-driven Beans. By implementing a resource adapter-supported message listener in the Message-driven Bean, generic messages can be received.
If you try to execute message inflow in EJB 2.0 Message-driven Bean, an error occurs when the application starts, and the application fails to start. In this case, the KDJE42088-E message is output.
- To execute message inflow, you must specify the following settings as the attributes of the resource adapters and Message-driven Beans:
- Information to be set up in the Administered object (resource adapters)
- Mapping of the Message-driven Beans and resource adapters (Message-driven Beans and resource adapters)
- Information to be set up in ActivationSpec (Message-driven Beans)
- Interfaces used by the Message-driven Beans (Message-driven Beans and resource adapters)
For details on the resource adapter and J2EE application settings for executing message inflow, see 3.16.8 Settings for using the resource adapters conforming to the Connector 1.5 specifications.
Also, a Transacted Delivery is enabled when the conditions described in the following table are satisfied.
Table 3-68 Conditions when a Transacted Delivery is enabled
J2EE server settings | Message-driven Bean settings |
---|
Transaction management type <transaction-type> is Container | Transaction management type <transaction-type> is Bean |
---|
Transaction attribute <trans-attribute> is Required | Transaction attribute <trans-attribute> is NotSupported |
---|
ejbserver.distributedtx.XATransaction.enabled | true | Y | N | N |
false | R | N | N |
- Legend:
- Y: The EIS delivering the message is included in the global transaction and then the transaction is started.
- R: The EIS delivering the message is not included in the transaction and the local transaction is started.
- N: The transaction is not started.
Also, to use a Transacted Delivery, you must use resource adapters conforming to the Connector 1.5 specifications and supporting Transacted Delivery. For details on the settings, see the documentation for the resource adapter in use.
(2) Procedure for controlling the message inflow (for a Non-Transacted Delivery)
A Non-Transacted Delivery is a message delivery in which the EIS that delivers the messages does not participate in the transaction.
The following figure shows the control procedure when the message inflow is used with a Non-Transacted Delivery.
Figure 3-49 Control procedure when the message inflow is used with a Non-Transacted Delivery
![[Figure]](figure/zu035100.gif)
The following points describe the control executed when the message inflow is used with a Non-Transacted Delivery. Note that the item numbers correspond to the numbers in the figure.
- The properties are set up in ActivationSpecJavaBean of the resource adapter by the application start processing.
The content specified in the Message-driven Bean attribute <activation-config> is set up.
- The J2EE server invokes the endpointActivation method. As a result, the starting of the message endpoint is reported to the resource adapter.
- The EIS sends a message.
- The resource adapter invokes the createEndpoint message for MessageEndpointFactory.
- MessageEndpointFactory generates an endpoint proxy.
- The resource adapter invokes a message listener method, such as the onMessage method, for the endpoint proxy.
- The endpoint proxy invokes a message listener method, such as the onMessage method, for the Message-driven Bean.
- When the processing is complete, the J2EE server invokes the endpointDeactivation method. As a result, the stopping of message endpoint is reported to the resource adapter.
(3) Procedure for controlling the message inflow (for a Transacted Delivery)
A Transacted Delivery is a message delivery in which the EIS that delivers the messages participates in the transaction.
The following figure shows the control procedure when the message inflow is used with a Transacted Delivery.
Figure 3-50 Control procedure when the message inflow is used with a Transacted Delivery
![[Figure]](figure/zu035150.gif)
The following points describe the control executed when the message inflow is used with a Transacted Delivery. Note that the item numbers correspond to the numbers in the figure.
- The properties are set up in ActivationSpecJavaBean of the resource adapter by the application start processing.
The content specified in the Message-driven Bean attribute <activation-config> is set up.
- The J2EE server invokes the endpointActivation method. As a result, the starting of the message endpoint is reported to the resource adapter.
- The EIS sends a message.
- The resource adapter invokes the createEndpoint message for MessageEndpointFactory.
- MessageEndpointFactory generates an endpoint proxy.
- The resource adapter invokes a message listener method, such as the onMessage method, for the endpoint proxy.
- The invoked endpoint proxy invokes a start transaction instruction for the transaction manager.
- The transaction manager invokes the start method and starts the transaction.
- The endpoint proxy invokes a message listener method, such as the onMessage method, for the Message-driven Bean.
- The endpoint proxy instructs the conclusion of the transaction to the transaction manager.
- The transaction manager invokes the transaction conclusion methods, such as the prepare method and commit method, to conclude the transaction.
- When the processing is complete, the J2EE server invokes the endpointDeactivation method. As a result, the stopping of message endpoint is reported to the resource adapter.
(4) Deploying and undeploying the message endpoint
This section describes the processing executed for deploying and undeploying the message endpoint.
Deploying the message endpoint
This section describes the processing executed for deploying the message endpoint. The message endpoint is deployed when you start an application containing the Message-driven Beans when the resource adapter is running.
The following figure shows the processing for deploying the message endpoint.
Figure 3-51 Processing for deploying the message endpoint
![[Figure]](figure/zu035200.gif)
The following points describe the processing executed for deploying the message endpoint. The item numbers correspond to the numbers in the figure.
- Start the J2EE application containing the Message-driven Beans when the resource adapter is running.
- The J2EE server generates MessageEndpointFactory.
MessageEndpointFactory is an instance of javax.resource.spi.endpoint.MessageEndpointFactory provided by the J2EE server. javax.resource.spi.endpoint.MessageEndpointFactory is a factory class that provides an endpoint instance to the resource adapter.
- The J2EE server generates ActivationSpec.
ActivationSpec is a JavaBean that sets up the information required for starting the Message-driven Beans (endpoint).
- The J2EE server sets up the ActivationSpec property.
The information specified in the ActivationSpec property is set up as an attribute of the application that contains the Message-driven Beans.
- The J2EE server invokes the javax.resource.spi.ResourceAdapter#endpointActivation(MessageEndpointFactory, ActivationSpec) method.
At this time, the generated and set up MessageEndpointFactory and ActivationSpec instances are specified as arguments. Note that if an exception occurs during the invocation of the endpointActivation method, the KDJE43174-E message is output and the starting of the application is canceled.
- If the method specified in 5 is invoked, the resource adapter prepares to receive the messages from the message provider.
Undeploying the message endpoint
This section describes the processing executed for undeploying the message endpoint. The message endpoint is undeployed when you stop an application containing the Message-driven Beans.
The following figure shows the processing for undeploying the message endpoint.
Figure 3-52 Processing for undeploying the message endpoint
![[Figure]](figure/zu035300.gif)
The following points describe the processing executed for undeploying the message endpoint. The item numbers correspond to the numbers in the figure.
- Stop the J2EE application containing the Message-driven Beans.
- The J2EE server invokes javax.resource.spi.ResourceAdapter#endpointDeactivation(MessageEndpointFactory, ActivationSpec).
At this time, the same MessageEndpointFactory and ActivationSpec instances, which were specified for deployment, are specified as arguments. Note that if an exception occurs during the invocation of this method, the message KDJE43175-W is output. However, even if an exception occurs, the application stop processing continues.
- If the method specified in 2 is invoked, the resource adapter executes the processing to terminate the receiving of messages from the message provider.
Processing of the resource adapter for delivering the messages
This section describes the processing of the resource adapter for delivering the messages.
The resource adapter invokes the message endpoint (Message-driven Bean) by using the message endpoint proxy. This proxy is obtained by invoking the createEndpoint method of javax.resource.spi.endpoint.MessageEndpointFactory from the resource adapter.
- Note
- If you invoke the MessageEndpointFactory method after the application stops, the javax.resource.spi.UnavailableException exception is thrown. At this time, the message KDJE43177-E is output. Also, when the message endpoint method is invoked, the java.lang.IllegalStateException exception is thrown. At this time, the message KDJE43177-E is output.
- In a Transacted Delivery, if you stop a J2EE application during message delivery, the transaction might be rolled back. At this time, KDJE31011-E or KDJE31012-E error might occur. These errors might also occur when you stop the running J2EE application when the J2EE server is stopped.