JBoss.org Community Documentation
This example shows you how to implement an MDB with EJB 3.0 using annotations.
Take a look at org.jboss.tutorial.mdb.bean.ExampleMDB
. The @MessageDriven annotation
defines the bean as an MDB. The activationConfig
attribute contains much of the MDB configuration via
@ActivationConfigProperty
. Also notice that the MDB source contains properties for
destinationType
and destination
The following is the list of standard Activation Config Properties available from the JCA 1.5 specification. Also listed are the respective types and default values where defined.
Name | Type | Remarks | Mandatory? | Default value |
---|---|---|---|---|
destination | java.lang.String | The jndi name of the Queue or Topic | Yes | |
destinationType | java.lang.String | The type of destination valid values are javax.jms.Queue or javax.jms.Topic | No | |
messageSelector | java.lang.String | The message selector of the subscription | No | |
acknowledgeMode | int | The type of acknowledgement when not using transacted jms - valid values AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE | No | AUTO_ACKNOWLEDGE |
clientID | java.lang.String | The client id of the connection | No | |
subscriptionDurability | String | Whether topic subscriptions are durable. Valid values are Durable or NonDurable | No | NonDurable |
subscriptionName | String | The subsription name of the topic subscription | No |
The following is the list of Activation Config Properties available as JBoss extensions.
Name | Type | Remarks | Mandatory? | Default value |
---|---|---|---|---|
isTopic | boolean | Sets the destinationType | No | false |
providerAdapterJNDI | java.lang.String | The jndi name of the jms provider | No | java:/DefaultJMSProvider |
user | java.lang.String | The user id used to connect to the jms server | No | |
pass | java.lang.String | The password of the user | No | |
maxMessages | int | Read this number of messages before delivering messages to the mdb. Each message is delivered individually on the same thread in an attempt to avoid context excessive context switching | No | 1 |
minSession | int | The minimum number of jms sessions that are available to concurrently deliver messages to this mdb | No | 1 |
maxSession | int | The maximum number of jms sessions that are available to concurrently deliver messages to this mdb | No | 15 |
reconnectInterval | long | The length of time in seconds between attempts to (re-)connect to the jms provider | No | 10 seconds |
keepAlive | long | The length of time in milliseconds that sessions over the minimum are kept alive | No | 60 seconds |
sessionTransacted | boolean | Whether the sessions are transacted | No | true |
useDLQ | boolean | Whether to use a DLQ handler | No | true |
dLQJNDIName | java.lang.String | The JNDI name of the DLQ | No | queue/DLQ |
dLQHandler | java.lang.String | The org.jboss.resource.adapter.jms.inflow.DLQHandler implementation class name | No | org.jboss.resource.adapter.jms.inflow.dlq.GenericDLQHandler |
dLQUser | java.lang.String | The user id used to make the dlq connection to the jms server | No | |
dLQPassword | java.lang.String | The password of the dLQUser | No | |
dLQClientID | java.lang.String | The client id of the dlq connection | No | |
dLQMaxResent | int | The maximum number of times a message is redelivered before it is sent to the DLQ | No | 5 |
redeliverUnspecified | boolean | Whether to attempt to redeliver a message in an unspecified transaction context | No | true |
transactionTimeout | int | Time in seconds for the transaction timeout | No | Default is the timeout set for the resource manager |
DeliveryActive | boolean | Whether the MDB should make the subscription at initial deployment or wait for start() or stopDelivery() on the corresponding MBean. You can set this to false if you want to prevent messages from being delivered to the MDB (which is still starting) during server startup | No | true |
The queue-example-service.xml
file defines the queues for this tutorial.
You can configure MDBs to have default properties using the @org.jboss.ejb3.annotation.DefaultActivationSpecs
annotations. Take a look at custom-ejb3-interceptors-aop.xml
. Here we define a custom container
configuration domain, "Custom Message Driven Bean"
, that adds a @DefaultActivationSpecs
annotation and destinationType
and destination
properties to each MDB using this domain.
Now take a look at org.jboss.tutorial.mdb.bean.DefaultedExampleMDB
. The MDB is configured to use the
"Custom Message Driven Bean"
container configuration domain via the @AspectDomain
annotation.
Note there are no properties defined in the @MessageDriven
annotation (they are all from the defaults).
To build and run the example, make sure you have installed JBoss 5.x. See the Section 1.1, “JBoss Application Server 5.x” for details.
From the command prompt, move to the "mdb" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”
Make sure your JBossAS-5.x is running
$ ant $ ant run run: [java] Message sent successfully to remote queue queue/tutorial/example [java] Message sent successfully to remote queue queue/tutorial/defaultedexample
$ mvn clean install -PRunSingleTutorial
On the server console, you will notice the following logs:
15:37:57,148 INFO [STDOUT] ---------------- 15:37:57,148 INFO [STDOUT] Received defaulted message 15:37:57,148 INFO [STDOUT] ---------------- 15:37:57,210 INFO [STDOUT] ---------------- 15:37:57,210 INFO [STDOUT] Received message 15:37:57,210 INFO [STDOUT] ----------------