There seems to be some inconsistency in the use of JMS resources and the setting activationConfigwith the correct one @ActivationConfigPropertyin the annotation @MessageDriven.
First, here is my resource configuration ( glassfish-resources.xml , but translatable to other deployment descriptors). This applies to Glassfish ( asadmin add-resources glassfish-resources.xml) along with the ActiveMQ Resource Adapter :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<resource-adapter-config name="activemq-rar"
thread-pool-ids="thread-pool-1"
resource-adapter-name="activemq-rar">
<property name="ServerUrl" value="tcp://localhost:61616"/>
<property name="UserName" value="admin"/>
<property name="Password" value="admin"/>
<property name="UseInboundSession" value="false"/>
</resource-adapter-config>
<admin-object-resource enabled="true"
jndi-name="jms/queue/myApp"
object-type="user"
res-adapter="activemq-rar"
res-type="javax.jms.Queue">
<description>MyApp JMS Queue</description>
<property name="Name" value="myAppAMQ"/>
<property name="PhysicalName" value="myAppAMQ"/>
</admin-object-resource>
<connector-resource enabled="true"
jndi-name="jms/factory/myApp"
object-type="user"
pool-name="jms/factoryPool/myApp">
<description>MyApp Connection Factory</description>
<property name="Name" value="myAppFactory"/>
</connector-resource>
<connector-connection-pool associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-definition-name="javax.jms.QueueConnectionFactory"
connection-leak-reclaim="false"
connection-leak-timeout-in-seconds="0"
fail-all-connections="false"
idle-timeout-in-seconds="300"
is-connection-validation-required="false"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="true"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="jms/factoryPool/myApp"
ping="false"
pool-resize-quantity="2"
pooling="true"
resource-adapter-name="activemq-rar"
steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"/>
</resources>
Here is my bean message provider. You will notice that JNDI names are found and ActiveMQ resources are used without errors, the message is sent to the appropriate queue:
@Stateless
@LocalBean
public class ServicesHandlerBean {
@Resource(mappedName = "jms/queue/myApp")
private Queue queue;
@Resource(mappedName = "jms/factory/myApp")
private ConnectionFactory factory;
public void sendJMSMessage(MessageConfig messageData) throws JMSException {
Connection connection = null;
Session session = null;
try {
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(queue);
messageProducer.send(createJMSMessage(session, messageData));
} finally {
if (session != null) {
try {
session.close();
} catch (JMSException e) {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot close session", e);
}
}
if (connection != null) {
connection.close();
}
}
}
}
The confusion begins when defining an @MessageDriven bean. The following using the mapped name throws an exception:
@MessageDriven(mappedName = "jms/queue/myApp")
public class MessageBean implements MessageListener
: RAR8000: setName : org.apache.activemq.command.ActiveMQQueue Warning: RAR7097: setter Name org.apache.activemq.command.ActiveMQQueue Info: : : RAR8501: ra [activemq-rar], activationSpecClass [org.apache.activemq.ra.ActiveMQActivationSpec]: javax.resource.ResourceException: : null Severe: MDB00017: [InvoiceProductionMessageBean]: bean: [java.lang.Exception] : java.lang.Exception
MDB :
@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/factory/myApp"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "myAppAMQ"),
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = " JMSType = 'TypeA' "),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
}
)
public class MessageBean implements MessageListener
glassfish-ejb-jar.xml, ActiveMQ, java.lang.ClassCastException:
: RAR8501: ra [ jmsra], activationSpecClass [com.sun.messaging.jms.ra.ActivationSpec ]: java.lang.ClassCastException: org.apache.activemq.ra.ActiveMQConnectionFactory com.sun.messaging.jms.ra.DirectConnectionFactory : MDB00017: [MessageBean]: bean container: [java.lang.Exception] : java.lang.Exception
GlassFish-EJB-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-ejb-jar PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 EJB 3.1//EN" "http://glassfish.org/dtds/glassfish-ejb-jar_3_1-1.dtd">
<glassfish-ejb-jar>
<enterprise-beans>
<ejb>
<ejb-name>MessageBean</ejb-name>
<mdb-resource-adapter>
<resource-adapter-mid>activemq-rar</resource-adapter-mid>
</mdb-resource-adapter>
</ejb>
</enterprise-beans>
</glassfish-ejb-jar>
, , (JNDI), (XML + @ActivationConfigProperty). , EE7 ActivationConfigProperty . , destinationLookup , ActiveMQ destination.
ActiveMQ :
confirmMode ( JMS. : Dups-ok-confirm)
clientId ( JMS ( ))
targetType ( , )
destination ( ( ))
enableBatch ( )
maxMessagesPerBatch ( )
maxMessagesPerSessions ( . (, ).)
maxSessions ( )
messageSelector ( JMS , )
noLocal ( ; , )
( JMS)
subscriptionDurability ( () . : Durable NonDurable)
_ ( . , )
_ ( JMS)
useRAManagedTransaction( , , . , , , . , . , useRAManagedTransaction true, MessageListener , .)
initialRedeliveryDelay ( . ResourceAdapter)
maximumRedeliveries ( -1 no . ResourceAdapter)
redeliveryBackOffMultiplier ( , . ResourceAdapter)
redeliveryUseExponentialBackOff ( . ResourceAdapter useJndi no false, true, jndi)
Java EE7 spec :
confirmMode ( JMS , bean - . : Auto_acknowledge Dups_ok_acknowledge. , JMS AUTO_ACKNOWLEDGE.
messageSelector ( JMS , , JMS- bean )
targetType ( , bean . javax.jms.Queue, javax.jms.Topic.)
destinationLookup ( JMS , JMS- bean .)
connectionFactoryLookup ( JMS factory, JMS- JMS- bean .)
subscriptionDurability ( , bean, , , . Durable, NonDurable)
_ ( , , bean, , bean , .)
clientId ( JMS JMS-, JMS message-driven bean . .)
ActiveMQ , @Inject jndi? glassfish-ejb-jar.xml @ActivationConfigProperty.