ajouter une référence de file d'attente JNDI dans ejb-jar.xml? envoi d'un message JMS dans un EJB / MDB

StackOverflow https://stackoverflow.com/questions/1612960

Question

J'ai une application EAR contenant une MDB et un fichier WAR.

Dans cette application EAR, j'envoyais un message dans une autre file d'attente à partir d'une autre application EAR. Dites jms / anotherQueue

Si l'envoi du message se produit dans un contexte Web, cela fonctionne. J'ai une telle configuration dans web.xml

<message-destination-ref>
 <message-destination-ref-name>jms/anotherQueue</message-destination-ref-name>
 <message-destination-type>javax.jms.Queue</message-destination-type>
 <message-destination-usage>Produces</message-destination-usage>
 <message-destination-link>jms/anotherQueue</message-destination-link>
</message-destination-ref> 

Mais si l'envoi du message se produit dans le contexte EJB (MDB here), j'obtiendrai un échec de la recherche du nom JNDI.

javax.naming.NameNotFoundException: anotherQueue

mon ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
 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>

  <message-driven>
   <ejb-name>jms/myMDB</ejb-name>
   <ejb-class>com.my.MDBImplement</ejb-class>
   <messaging-type>javax.jms.MessageListener</messaging-type>
   <transaction-type>Container</transaction-type>
   <activation-config>
    <activation-config-property>
     <activation-config-property-name>destination</activation-config-property-name>
     <activation-config-property-value>jms/myQueue</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
     <activation-config-property-name>destinationType</activation-config-property-name>
     <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
    </activation-config-property>
   </activation-config>
   <resource-ref>
    <res-ref-name>jms/myCF</res-ref-name>
    <res-type>javax.jms.QueueConnectionFactory</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
   </resource-ref>
  </message-driven>
 </enterprise-beans>

 <assembly-descriptor>
  <container-transaction>
   <method>
    <ejb-name>jms/myMDB</ejb-name>
    <method-name>onMessage</method-name>
    <method-params>
     <method-param>javax.jms.Message</method-param>
    </method-params>
   </method>
   <trans-attribute>NotSupported</trans-attribute>
  </container-transaction>
 </assembly-descriptor>


</ejb-jar>

le openejb.jar est

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ejb:openejb-jar
 xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
 xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0"
 xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2"
 xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
 xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence"
 xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
 xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
 <dep:environment>
  <dep:moduleId>
   <dep:groupId>myGroup</dep:groupId>
   <dep:artifactId>imyMDB</dep:artifactId>
   <dep:version>1.0</dep:version>
   <dep:type>ejb</dep:type>
  </dep:moduleId>
  <dep:dependencies>
   <dep:dependency>
    <dep:groupId>org.apache.geronimo.configs</dep:groupId>
    <dep:artifactId>activemq-broker</dep:artifactId>
    <dep:type>car</dep:type>
   </dep:dependency>
  </dep:dependencies>
 </dep:environment>
 <ejb:enterprise-beans>
  <ejb:message-driven>
   <ejb:ejb-name>jms/myMDB</ejb:ejb-name>
   <ejb:resource-adapter>
    <ejb:resource-link>myJmsResource</ejb:resource-link>
   </ejb:resource-adapter>
  </ejb:message-driven>
 </ejb:enterprise-beans>
</ejb:openejb-jar>

Je définis myJmsResource dans geronimo-application.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<app:application
 xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
 xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0"
 xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2"
 xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
 xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence"
 xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
 xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
 <dep:environment>
  <dep:moduleId>
   <dep:groupId>myGroup</dep:groupId>
   <dep:artifactId>myEAR</dep:artifactId>
   <dep:version>1.0</dep:version>
   <dep:type>ear</dep:type>
  </dep:moduleId>
 </dep:environment>
 <app:module>
  <app:connector>geronimo-activemq-ra-2.1.4.rar</app:connector>
  <conn:connector>
   <dep:environment>
    <dep:moduleId>
     <dep:groupId>myGroup</dep:groupId>
     <dep:artifactId>myJmsResource</dep:artifactId>
     <dep:version>1.0</dep:version>
     <dep:type>rar</dep:type>
    </dep:moduleId>
    <dep:dependencies>
     <dep:dependency>
    <dep:groupId>org.apache.geronimo.configs</dep:groupId>
      <dep:artifactId>activemq-broker</dep:artifactId>
      <dep:type>car</dep:type>
     </dep:dependency>
    </dep:dependencies>
   </dep:environment>
   <conn:resourceadapter>
    <conn:resourceadapter-instance>

     <conn:resourceadapter-name>myJmsResource</conn:resourceadapter-name>
     <nam:workmanager>
      <nam:gbean-link>DefaultWorkManager</nam:gbean-link>
     </nam:workmanager>
    </conn:resourceadapter-instance>
    <conn:outbound-resourceadapter>
     <conn:connection-definition>
      <conn:connectionfactory-interface>javax.jms.ConnectionFactory</conn:connectionfactory-interface>
      <conn:connectiondefinition-instance>
       <conn:name>jms/myCF</conn:name>
       <conn:implemented-interface>javax.jms.QueueConnectionFactory</conn:implemented-interface>
       <conn:implemented-interface>javax.jms.TopicConnectionFactory</conn:implemented-interface>
       <conn:connectionmanager>
        <conn:xa-transaction>
         <conn:transaction-caching />
        </conn:xa-transaction>
        <conn:single-pool>
         <conn:match-all />
        </conn:single-pool>
       </conn:connectionmanager>
      </conn:connectiondefinition-instance>
     </conn:connection-definition>
    </conn:outbound-resourceadapter>
   </conn:resourceadapter>
   <conn:adminobject>
    <conn:adminobject-interface>javax.jms.Queue</conn:adminobject-interface>
    <conn:adminobject-class>org.apache.activemq.command.ActiveMQQueue</conn:adminobject-class>
   <conn:adminobject-instance>     
     <conn:message-destination-name>jms/myQueue</conn:message-destination-name>
     <conn:config-property-setting name="PhysicalName">jms/myQueue</conn:config-property-setting>
    </conn:adminobject-instance>
    <!-- ******************************************************************** -->
    <!-- define referred message destination ??? -->
    <conn:adminobject-instance>
     <conn:message-destination-name>jms/anotherQueue</conn:message-destination-name>
     <conn:config-property-setting name="PhysicalName">jms/anotherQueue</conn:config-property-setting>
    </conn:adminobject-instance>
   </conn:adminobject>
   <conn:adminobject>
    <conn:adminobject-interface>javax.jms.Topic</conn:adminobject-interface>
    <conn:adminobject-class>org.apache.activemq.command.ActiveMQTopic</conn:adminobject-class>
   </conn:adminobject>
  </conn:connector>
 </app:module>

</app:application>

Il semble que myMDB ne puisse pas comprendre ce que jms / anotherQueue est !!! Comment puis-je résoudre ce problème?

Était-ce utile?

La solution

OK, j'ai trouvé une solution rapide ....

dans ejb-jar.xml

<enterprise-beans>

    <message-driven>
        <ejb-name>jms/myMDB</ejb-name>
                .....      
        <!--  referred queue -->
        <resource-env-ref>
            <resource-env-ref-name>jms/anotherQueue</resource-env-ref-name>
            <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
        </resource-env-ref>

    </message-driven>
</enterprise-beans>

Je dois admettre que je ne comprends toujours pas comment rédiger un plan de déploiement correct. Je ne fais que masquer, copier, coller ..... et confondre ces plans de déploiement.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top