8 Replies Latest reply on May 30, 2012 5:14 AM by pi4630

    7.1.1.: DI for ConnectionFactory and Queue not possible?

    pi4630

      Hi,

       

      I work on two AS versions: 6.0.0.Final because it's the production environment. I am following 7 versions all the time to make sure I get the updates of the new direction, which I generally like.

       

      But in 7.1.1., I find that still I can't inject Connection Factory and Queue. Back in 7.1.0 CR1b, I followed the issue https://issues.jboss.org/browse/AS7-1338, right now I found this still isn't working.

       

      In other words, I can't do

       

      {code}

      @Resource(mappedName = "ConnectionFactory")

      ConnectionFactory factory;

       

      @Resource(mappedName = "queue/test")

      Queue queue;

      {code}

       

      but need to do

       

      {code}

      Context ic = new InitialContext();

      ConnectionFactory factory = (ConnectionFactory) ic.lookup("/ConnectionFactory");

      Queue queue = (Queue) ic.lookup("queue/test");

      {code}

      instead.

       

      Besides, the above issue is reported as resolved in 7.1.0.Final.

      Am I missing something?

        • 1. Re: 7.1.1.: DI for ConnectionFactory and Queue not possible?
          sfcoy
          • 2. Re: 7.1.1.: DI for ConnectionFactory and Queue not possible?
            jaikiran

            Just make you are using the standalone-full.xml or standalone-full-ha.xml profiles while starting the server. Those are the ones which have messaging subsystem enabled.

             

            ./standalone.sh -server-config=standalone-full.xml

            • 3. Re: 7.1.1.: DI for ConnectionFactory and Queue not possible?
              pi4630

              Jaikiran, I was using

              ./standalone.sh -c standalone-full.xml

               

              Not good?

              • 4. Re: 7.1.1.: DI for ConnectionFactory and Queue not possible?
                jaikiran

                Should be fine. What exactly happens with that code? Do you see any error messages? Can you post any relevant exception stacktraces? And please also post the exact code in that class (is that a EJB)?

                • 5. Re: 7.1.1.: DI for ConnectionFactory and Queue not possible?
                  pi4630

                  From server.log:

                   

                   

                  {font:courier new}

                  ERROR [org.jboss.as] (MSC service thread 1-3) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 5107ms - Started 226 of 312 services (5 services failed or missing dependencies, 80 services are passive or on-demand)

                  08:57:19,6

                  INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment HelloMessage.jar in 44ms

                  08:57:19,662 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report

                  JBAS014775:    New missing/unsatisfied dependencies:

                        service jboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.ConnectionFactory (missing) dependents: [service jboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env."it.bz.prov.logic.Talker".factory]

                        service jboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.queue.test (missing) dependents: [service jboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env."it.bz.prov.logic.Talker".queue]

                  27 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "HelloMessage.jar" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.\"it.bz.prov.logic.Talker\".queuejboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.queue.testMissing[jboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.\"it.bz.prov.logic.Talker\".queuejboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.queue.test]","jboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.\"it.bz.prov.logic.Talker\".factoryjboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.ConnectionFactoryMissing[jboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.\"it.bz.prov.logic.Talker\".factoryjboss.naming.context.java.comp.HelloMessage.HelloMessage.Talker.env.ConnectionFactory]"]}

                  {font}

                   

                  Inside my standard-full.xml, the JMS Connection Factory JNDI name is set as well as the destinations:

                   

                   

                  {code:xml}

                  <jms-connection-factories>

                                      <connection-factory name="InVmConnectionFactory">

                                          <connectors>

                                              <connector-ref connector-name="in-vm"/>

                                          </connectors>

                                          <entries>

                                              <entry name="java:/ConnectionFactory"/>

                                          </entries>

                  ...

                  <jms-destinations>

                                      <jms-queue name="testQueue">

                                          <entry name="queue/test"/>

                                          <entry name="java:jboss/exported/jms/queue/test"/>

                                      </jms-queue>

                   

                  {code}

                   

                  Finally, here's the code:

                   

                   

                  {code}

                  package it.bz.prov.logic;

                   

                  import javax.annotation.Resource;

                  import javax.ejb.Stateless;

                  import javax.jms.Connection;

                  import javax.jms.ConnectionFactory;

                  import javax.jms.JMSException;

                  import javax.jms.MessageProducer;

                  import javax.jms.Queue;

                  import javax.jms.Session;

                  import javax.jms.TextMessage;

                  import javax.naming.Context;

                  import javax.naming.InitialContext;

                   

                  import it.bz.prov.ibusiness.ITalkRemote;

                   

                  @Stateless

                  public class Talker implements ITalkRemote {

                   

                      // Can't do JNDI resource injection

                      // will be available in 7.1

                      // see https://issues.jboss.org/browse/AS7-1338

                   

                      // @Resource(mappedName = "java:/ConnectionFactory")

                      // Connection factory;

                   

                      // OLD WAY

                       @Resource(mappedName = "ConnectionFactory")

                       ConnectionFactory factory;

                   

                       @Resource(mappedName = "queue/test")

                       Queue queue;

                   

                      @Override

                      public String greet(String name) {

                          String answer = null;

                          if (name != null && !name.equalsIgnoreCase("")) {

                              answer = "Hello, " + name + "!";

                   

                              squeal(name);

                   

                          }

                   

                          return answer;

                      }

                   

                      private void squeal(String name) {

                   

                          try {

                  //            Context ic = new InitialContext();

                  //            ConnectionFactory factory = (ConnectionFactory) ic

                  //                    .lookup("/ConnectionFactory");

                  //            Queue queue = (Queue) ic.lookup("queue/test");

                              Connection conn = factory.createConnection();

                              Session session = conn.createSession(false,

                                      Session.AUTO_ACKNOWLEDGE);

                              MessageProducer sender = session.createProducer(queue);

                              TextMessage tm = session.createTextMessage();

                              // TextMessage of type squeal

                              tm.setStringProperty("Subject", "squeal");

                              tm.setText(name);

                              sender.send(tm);

                              sender.close();

                          } catch (Exception e) {

                              e.printStackTrace();

                          }

                   

                      }

                   

                  }

                  {code}

                  • 6. Re: 7.1.1.: DI for ConnectionFactory and Queue not possible?
                    jaikiran

                    @Resource(mappedName = "ConnectionFactory")
                         ConnectionFactory factory;

                         @Resource(mappedName = "queue/test")
                         Queue queue;

                    This should be

                     

                    @Resource(mappedName = "java:/ConnectionFactory")
                         ConnectionFactory factory;

                         @Resource(mappedName = "java:/queue/test")
                         Queue queue;

                    • 7. Re: 7.1.1.: DI for ConnectionFactory and Queue not possible?
                      jaikiran

                      By the way, earlier in your logs you'll see the exact JNDI names to which the queue and connection factory is bound. You just have to use that value in your mappedName attribute.

                      1 of 1 people found this helpful
                      • 8. Re: 7.1.1.: DI for ConnectionFactory and Queue not possible?
                        pi4630

                        Yes, I see it

                         

                        Just to get it right: In 6.0.0.Final, my JMS destinations is called  <entry name="/queue/testQueue"/>, while the ConnectionFactory is called 

                        <entry name="java:/ConnectionFactory"/>. There I inject with just "ConnectionFactory", and the JNDI name is resolved.

                         

                        Now I see I must use the config entry name(s) "as is" with 7 onwards.

                         

                        Thanks Jaikiran!