3 Replies Latest reply on Aug 29, 2011 3:54 AM by Serkan Eskici

    Need urgent help with JMS producer !

    Serkan Eskici Novice

      Hi,


      I'm trying to send a message to a queue from a POJO and I keep getting the following error:


      org.jboss.seam.InstantiationException: Could not instantiate Seam component: notQueueSender
              at org.jboss.seam.Component.newInstance(Component.java:2170)
              at org.jboss.seam.Component.getInstance(Component.java:2024)
              at org.jboss.seam.Component.getInstance(Component.java:1986)
              at org.jboss.seam.Component.getInstance(Component.java:1980)
              at org.jboss.seam.Component.getInstanceInAllNamespaces(Component.java:2375)
              at org.jboss.seam.Component.getValueToInject(Component.java:2327)
              at org.jboss.seam.Component.injectAttributes(Component.java:1739)
              at org.jboss.seam.Component.inject(Component.java:1557)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:61)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
              at nl.portbase.spoc.validation.RetryServiceHandler_$$_javassist_seam_10.retry(RetryServiceHandler_$$_javassist_seam_10.java)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62)
              at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80)
              at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44)
              at org.jboss.seam.async.ThreadPoolDispatcher$RunnableAsynchronous.run(ThreadPoolDispatcher.java:142)
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
              at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
              at java.util.concurrent.FutureTask.run(FutureTask.java:138)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207)
              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.RuntimeException: exception invoking: create
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:154)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
              at org.jboss.seam.Component.callCreateMethod(Component.java:2198)
              at org.jboss.seam.Component.newInstance(Component.java:2158)
              ... 39 more
      Caused by: javax.jms.JMSException: No currently active Session. This JMS provider cannot be used outside a MessageListener.onMessage() invocation
              at org.apache.activemq.ra.InboundSessionProxy.getSessionAndProducer(InboundSessionProxy.java:82)
              at org.apache.activemq.ra.InboundSessionProxy.createSender(InboundSessionProxy.java:225)
              at org.jboss.seam.jms.ManagedQueueSender.create(ManagedQueueSender.java:51)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              ... 42 more
      




      And this is the code block where I'm doing the JMS call:


      @AutoCreate
      @Name("retryServiceHandler")
      public class RetryServiceHandler {
      
          @Logger
          private Log log;
      
          @In(create = true)
          private QueueSession queueSession;
      
          @In
          private QueueSender notQueueSender;
      
          @In
          private QueueSender hazmatQueueSender;
      
          @In
          private EntityManager entityManager;
      
          
          @Asynchronous
          @Transactional
          public void retry(String msRefid, boolean msgRetry, @Duration long duration) {
              LCANotification not = (LCANotification) entityManager.createQuery("from LCANotification n where n.msRefId = :id")
                  .setParameter("id", msRefid)
                  .getSingleResult();
      
              try {
                  if (msgRetry)
                      notQueueSender.send(queueSession.createTextMessage(marshall(not)));
                  else
                      hazmatQueueSender.send(queueSession.createTextMessage(marshall(not)));
              }
              catch (Exception e) {
                  log.error("Calling the 'RETRY service' failed: {0}", getErrorMessage(e));
                  not.addState(NOT_SENT);
                  changeStateToInvalid(not);
                  Events.instance().raiseAsynchronousEvent(EVENT_SEND_NOTIFICATION_ALERT, EVENT_TYPE_9, not);
              }
          }
      



      And this method is triggered from a SLSB like this:


      @TransactionAttribute
      public void retry() {
          RetryServiceHandler handler = (RetryServiceHandler) Component.getInstance(RetryServiceHandler.class);
          handler.retry(msRefid, true, waitTimeInSecs * 1000);
      }
      



      The strange thing is that I can send messages into the queue from a MDB, that is: I read a message from a MDB then I send it back to another queue. And this just works. But when I try to send a message outside a MDB, then it doesn't work. And according to the Seam manual it should be possible to send messages just from a POJO.


      I've 2 deployments: 1 EAR file and 1 WAR, and it both cases sending messages doesn't work.


      Further info, I'm using:



      • Seam 2.2.1.final

      • JBoss 5.1.GA

      • ActiveMQ 5.4

      • PostGres 8.4



      Can someone please provide any help or a hint about this issue ?


      Thx !





        • 1. Re: Need urgent help with JMS producer !
          Leo van den berg Master

          Hi Serkan,


          I see you're using ActiveMQ as your JMS-provider. I assume that you've configured everything as in the docs, because it has some problems. Because your MDB works you have as a minimum the ActiveMQ RAR in the deploy dir.


          My advice is NOT to use a POJO, but a session bean. I've tried several times to make it work from a POJO but it fails on all fronts. The session bean's Resource annotation which you use in a session bean works without a problem.


          Leo


          P.S If you're working on HAZMAT for transportation, please contact me on LinkedIn, I am doing a HAZMAT project at the moment.

          • 2. Re: Need urgent help with JMS producer !
            Serkan Eskici Novice

            Hi Leo,


            Thanks for your reply.


            Yes, I've configured everything fine. Btw which was not as trivial as I would think. Especially getting XA transactions working properly was a nightmare :) -After all, I think I'm gonna post the whole correct configuration here (when I've time).


            Switching to EJB's at this moment is not an option. That would require me to the change the deployment from WAR to EAR and that would have a huge impact on everything build so far. I guess I figured what the problem is: it has to do with JNDI and managed resources. It seems that these can only be used inside EJB's since they're managed by the container.


            And that logically forces me to make JMS calls without using (injected) JNDI resources but by connecting directly to the queue, by doing something like this:


            ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
            Connection connection = connectionFactory.createConnection();
            connection.start();
            
            //create a session
            //create a destination
            //create a producer
            //send messages, etc.
            



            And btw, @Resource can only be used on a MDB, right ? -And not on Session beans, I guess....


            Cheers,
            Serkan



            PS: I'll contact you on LinkedIn.

            • 3. Re: Need urgent help with JMS producer !
              Serkan Eskici Novice

              Correction:
              @Resource


              Should be:
              @ResourceAdapter(activemq-ra.rar)