[jboss-user] Resource deployment and injection...
Drayton Brown
draytonbrown at gmail.com
Fri Mar 12 10:14:41 EST 2010
Hi all
I'm trying to migrate an application that I wrote for deployment on
Glassfish to a JBoss 5.
I've managed to iron out most of the problems, however I'm still having some
issues setting up my JMS resources and injecting them into the application.
In Glassfish I annotated the relevent class with '@Resource' annotatoins as
follows:
@Stateless
@WebService
public class Spooler implements SpoolerLocal {
@Resource(name= "jms/SpoolerTopic")
private Topic spoolerTopic;
@Resource(name= "jms/SpoolerTopicFactory")
private ConnectionFactory spoolerTopicFactory;
//Code making use of injected resouces
}
and added the following to the sun-resources.xml deployment descriptor:
<connector-connection-pool associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-definition-name="javax.jms.ConnectionFactory"
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/SpoolerTopicFactoryPool"
pool-resize-quantity="2" resource-adapter-name="jmsra"
steady-pool-size="8" validate-atmost-once-period-in-seconds="0">
<description>Spooler Events Connection Factory Pool</description>
</connector-connection-pool>
<admin-object-resource enabled="true" jndi-name="jms/SpoolerTopic"
object-type="user" res-adapter="jmsra" res-type="javax.jms.Topic">
<description>This is the Spoolers' event queue</description>
<property name="Name" value="spoolerEvents"/>
</admin-object-resource>
In Glassfish this was enough to have the application server to automatically
deploy the required resources to the server, and then inject them into the
Spooler class when needed.
I've tried a number of approaches to get the same behaviour on JBoss,
unfortunately with no luck.
I've read the instructions outlined here:
http://community.jboss.org/wiki/HowtouseanapplicationclientinJBoss-5 but
they do not seem to cater for my needs. (ie. They detail how to inject an
ALREADY EXISTING queue from the global JNDI, using the 'mappedName'
approach. They also detail how to inject a resource into a application
client - this seems similar, but I'm trying to inject into an EJB3)
I've also tried following this guide:
http://activemq.apache.org/outbound-communication.html#OutboundCommunication-ejbLoggingQueue
unfortunately
this did not work either.
The closest I have got is that I have created the following deployment
descriptors:
jboss-connection-factories-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE connection-factories PUBLIC "-//JBoss//DTD JBOSS JCA Config
1.5//EN" "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
<connection-factories>
<no-tx-connection-factory>
<jndi-name>SpoolerConnectionFactory</jndi-name>
<rar-name>jms-ra.rar</rar-name>
<connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>
<config-property name="SessionDefaultType"
type="java.lang.String">javax.jms.Topic</config-property>
<config-property name="JmsProviderAdapterJNDI"
type="java.lang.String">java:/defaultJMSProvider</config-property>
</no-tx-connection-factory>
</connection-factories>
jboss-destinations-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.jms.server.destination.TopicService"
name="jboss.messaging.destination:service=Topic,name=SpoolerTopic"
xmbean-dd="xmdesc/Topic-xmbean.xml">
<depends
optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
</mbean>
</server>
These seem to deploy the resources I would like to use, however I'm still
struggling with injecting these into the application. I've tried using these
deployment descriptors with the information found on the Apache ActiveMQ web
site in conjuction, as follows:
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
version = "3.0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<enterprise-beans>
<session>
<ejb-name>Spooler</ejb-name>
<ejb-class>com.photobox.Spooler</ejb-class>
<resource-ref>
<res-ref-name>jms/SpoolerTopicFactory</res-ref-name>
<res-type>javax.jms.ConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<message-destination-ref>
<message-destination-ref-name>jms/SpoolerTopic</message-destination-ref-name>
<message-destination-type>javax.jms.Topic</message-destination-type>
<message-destination-link>SpoolerTopic</message-destination-link>
</message-destination-ref>
</session>
</enterprise-beans>
<assembly-descriptor>
<message-destination>
<message-destination-name>SpoolerTopic</message-destination-name>
</message-destination>
</assembly-descriptor>
</ejb-jar>
jboss.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD Application Client 5.0//EN" "
http://www.jboss.org/j2ee/dtd/jboss_5_0.dtd">
<!-- http://activemq.apache.org/outbound-communication.html -->
<jboss>
<enterprise-beans>
<session>
<ejb-name>Spooler</ejb-name>
<resource-ref>
<res-ref-name>jms/SpoolerTopicFactory</res-ref-name>
<resource-name>topicFactoryRef</resource-name>
</resource-ref>
</session>
</enterprise-beans>
<assembly-descriptor>
<message-destination>
<message-destination-name>SpoolerTopic</message-destination-name>
<jndi-name>SpoolerTopic</jndi-name>
</message-destination>
</assembly-descriptor>
<resource-managers>
<resource-manager>
<res-name>topicFactoryRef</res-name>
<res-jndi-name>SpoolerTopicFactory</res-jndi-name>
</resource-manager>
</resource-managers>
</jboss>
Unforuntately this does not seem to help either.
Please could someone let me know what I'm doing wrong! I've been searching
the forums and the web for a couple of days now and I have yet to find some
documentation on this sort of resource deployment and injection for JBoss.
Most of what I find is related to MDB or application clients. Both these
solutions are not appropriate for me since the EJB which requires the
resources is not message driven, although it does dispatch messages (ie. it
is not a MessageListener).
This is a work requirement for me, so a prompt response would be highly
appreciated.
Regards
Drayton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100312/63ae2a74/attachment.html
More information about the jboss-user
mailing list