0 Replies Latest reply on Dec 17, 2012 2:55 AM by jobame

    Message Linking not working

    jobame

      Hi there,

       

      trying to get a working message linking example. However, when deploying the following exception it thrown. Does anybody have a glue on what is going wrong? There are some books describing message linking (e.g. http://www.ejb3buch.de chapter /) but none of the authors provides a _working_ example.

       

      Exception

       

      08:53:18,144 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Real: name=vfs:///C:/Daten/workspace/.metadata/.plugins/org.jboss.id

      e.eclipse.as.core/jboss-6.1.0.Final_Runtime/deploy/workApp.ear state=PreReal mode=Manual requiredState=Real: org.jboss.deployers.spi.DeploymentException: Error dur

      ing deploy: org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.DebitPositionTriggerBean

                at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49) [:2.2.2.GA]

                at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:185) [:2.2.2.GA]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1832) [:2.2.2.GA]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1550) [:2.2.2.GA]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1571) [:2.2.2.GA]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1603) [:2.2.2.GA]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1491) [:2.2.2.GA]

                at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.SP2]

                at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.SP2]

                at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.SP2]

                at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.SP2]

                at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.SP2]

                at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.SP2]

                at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939) [jboss-dependency.jar:2.2.0.SP2]

                at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654) [jboss-dependency.jar:2.2.0.SP2]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.change(DeployersImpl.java:1983) [:2.2.2.GA]

                at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:1076) [:2.2.2.GA]

                at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:679) [:2.2.2.GA]

                at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.process(MainDeployerPlugin.java:106) [:6.1.0.Final]

                at org.jboss.profileservice.dependency.ProfileControllerContext$DelegateDeployer.process(ProfileControllerContext.java:143) [:0.2.2]

                at org.jboss.profileservice.deployment.hotdeploy.HDScanner$HDScanAction.deploy(HDScanner.java:240) [:0.2.2]

                at org.jboss.profileservice.deployment.hotdeploy.HDScanner$HDScanAction.complete(HDScanner.java:192) [:0.2.2]

                at org.jboss.profileservice.management.TwoPCActionWrapper.doComplete(TwoPCActionWrapper.java:57) [:0.2.2]

                at org.jboss.profileservice.management.actions.AbstractTwoPhaseModificationAction.complete(AbstractTwoPhaseModificationAction.java:74) [:0.2.2]

                at org.jboss.profileservice.management.actions.AbstractTwoPhaseModificationAction.prepare(AbstractTwoPhaseModificationAction.java:95) [:0.2.2]

                at org.jboss.profileservice.management.ModificationSession.prepare(ModificationSession.java:87) [:0.2.2]

                at org.jboss.profileservice.management.AbstractActionController.internalPerfom(AbstractActionController.java:234) [:0.2.2]

                at org.jboss.profileservice.management.AbstractActionController.performWrite(AbstractActionController.java:213) [:0.2.2]

                at org.jboss.profileservice.management.AbstractActionController.perform(AbstractActionController.java:150) [:0.2.2]

                at org.jboss.profileservice.management.AbstractActionController.perform(AbstractActionController.java:135) [:0.2.2]

                at org.jboss.profileservice.deployment.hotdeploy.HDScanner.scan(HDScanner.java:146) [:0.2.2]

                at org.jboss.profileservice.deployment.hotdeploy.HDScanner.run(HDScanner.java:90) [:0.2.2]

                at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [:1.6.0_37]

                at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source) [:1.6.0_37]

                at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [:1.6.0_37]

                at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source) [:1.6.0_37]

                at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source) [:1.6.0_37]

                at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [:1.6.0_37]

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [:1.6.0_37]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [:1.6.0_37]

                at java.lang.Thread.run(Unknown Source) [:1.6.0_37]

      Caused by: java.lang.IllegalStateException: Message destination LinkBillingQueue in AbstractVFSDeploymentContext@1095645065{vfs:///C:/Daten/workspace/.metadata/.plugins/o

      rg.jboss.ide.eclipse.as.core/jboss-6.1.0.Final_Runtime/deploy/workApp.ear/workAppEJB.jar/} does not define a mapped name

                at org.jboss.ejb3.resolvers.DefaultMessageDestinationReferenceResolver.findMessageDestination(DefaultMessageDestinationReferenceResolver.java:50) [:1.7.21]

                at org.jboss.ejb3.resolvers.DefaultMessageDestinationReferenceResolver.findWithinModule(DefaultMessageDestinationReferenceResolver.java:76) [:1.7.21]

                at org.jboss.ejb3.resolvers.DefaultMessageDestinationReferenceResolver.resolveMessageDestinationJndiName(DefaultMessageDestinationReferenceResolver.java:140) [:1.7.21]

                at org.jboss.as.ejb3.switchboard.resource.provider.MessageDestinationReferenceResourceProvider.provide(MessageDestinationReferenceResourceProvider.java:95) [:6.1.0.Final

      ]

                at org.jboss.as.ejb3.switchboard.resource.provider.MessageDestinationReferenceResourceProvider.provide(MessageDestinationReferenceResourceProvider.java:21) [:6.1.0.Final

      ]

                at org.jboss.switchboard.mc.JndiEnvironmentProcessor.process(JndiEnvironmentProcessor.java:68) [:1.0.0-alpha-15]

                at org.jboss.switchboard.mc.deployer.AbstractSwitchBoardDeployer.process(AbstractSwitchBoardDeployer.java:119) [:1.0.0-alpha-15]

                at org.jboss.switchboard.mc.deployer.EJBEnvironmentSwitchBoardDeployer.internalDeploy(EJBEnvironmentSwitchBoardDeployer.java:87) [:1.0.0-alpha-15]

                at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55) [:2.2.2.GA]

                at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) [:2.2.2.GA]

                ... 39 more

       

       

      Sender

       

      package com.work.ejbeans.billing;

       

      import java.util.List;

      import java.util.logging.Level;

      import java.util.logging.Logger;

      import javax.annotation.PostConstruct;

      import javax.annotation.PreDestroy;

      import javax.annotation.Resource;

      import javax.ejb.EJB;

      import javax.ejb.Schedule;

      import javax.ejb.Singleton;

      import javax.jms.Connection;

      import javax.jms.JMSException;

      import javax.jms.Message;

      import javax.jms.MessageProducer;

      import javax.jms.ObjectMessage;

      import javax.jms.Queue;

      import javax.jms.QueueConnection;

      import javax.jms.QueueConnectionFactory;

      import javax.jms.QueueSender;

      import javax.jms.QueueSession;

      import javax.jms.Session;

      import com.work.persistence.sfclasses.ResultClassDebitPosCandidate;

      import com.work.persistence.sfdao.LineItemAccessDao;

       

      @Singleton(name="DebitPositionTriggerBean")

      public class DebitPositionTrigger {

       

                @Resource(mappedName = "OpaConnectionFactory")

                private QueueConnectionFactory connectionFactory;

       

                @Resource(mappedName = "jms/LogicBillingQueueDestination")

                private Queue queue;

       

                private Connection connection ;

       

                @EJB

                LineItemAccessDao lineItemAccessDao;

       

                private volatile Boolean          inProgress = Boolean.FALSE ;

       

                @PostConstruct

                protected void createQueue() {

                          try {

                                    connection = connectionFactory.createQueueConnection();

                          }

                          catch (JMSException jmsExcp) {

                          }

                }

       

                @PreDestroy

                public void destroyQueue() throws JMSException {

                          try {

                                    connection.close();

                          }

                          catch (JMSException jmsException) {

                          }

                }

       

                private void sendBillingOrderMsg(final ResultClassDebitPosCandidate orderMsg) {

       

                          Session msgSesssion = null  ;

       

                          try {

                                    msgSesssion = connection.createSession(false, Session.SESSION_TRANSACTED) ; // auto-acknoledge or session-transacted ??

                                    final MessageProducer msgSender = msgSesssion.createProducer(queue) ;

                                    final Message messageData = msgSesssion.createObjectMessage(orderMsg);

                                    msgSender.send(messageData) ;

                          }

                          catch (JMSException jmsExcp) {

                                    try {

                                              msgSesssion.close() ;

                                    }

                                    catch (JMSException innerJmsExcp) {

                                    }

                          }

                }

       

                @Schedule(second="0", minute="*/1", hour="*", persistent=false)

                public void triggerDebitPositions() {

       

                          Boolean myProgressState = Boolean.FALSE ;

       

                          synchronized (inProgress) {

                                    if (inProgress) {

                                              return ;

                                    }

                                    else {

                                              myProgressState = inProgress = Boolean.TRUE ;

                                    }

                          }

       

                          try {

                                    calculateDebitPositions() ;

                          } catch (Exception anyExp) {

                          } finally {

                                    if (myProgressState) {

                                              inProgress = Boolean.FALSE ;

                                    }

                          }

                }

       

                private void calculateDebitPositions()  {

                          final List<ResultClassDebitPosCandidate> listOfDebitPosCandidateIds = lineItemAccessDao.getDebPosCanditates();

                          for (ResultClassDebitPosCandidate currId : listOfDebitPosCandidateIds) {

                                    sendBillingOrderMsg(currId) ;

                          }

                }

      }

       

       

      Receiver

       

      package com.work.abrechnung.ejbeans.billing;

       

      import java.math.BigDecimal;

      import java.util.Calendar;

      import java.util.Date;

      import javax.ejb.DependsOn;

      import javax.ejb.EJB;

      import javax.ejb.MessageDriven;

      import javax.ejb.TransactionAttribute;

      import javax.ejb.TransactionAttributeType;

      import javax.ejb.TransactionManagement;

      import javax.ejb.TransactionManagementType;

      import javax.jms.JMSException;

      import javax.jms.Message;

      import javax.jms.MessageListener;

      import javax.jms.ObjectMessage;

      import javax.persistence.EntityManager;

      import javax.persistence.PersistenceContext;

      import javax.persistence.TypedQuery;

      import com.work.abrechnung.ejbeans.billing.scheduleutil.CalculateDebPosTaskIf;

      import com.work.abrechnung.ejbeans.billing.scheduleutil.QueueControlBilling;

      import com.work.abrechnung.helpers.CalendarTools;

      import com.work.abrechnung.persistence.billingclasses.DebitPosition;

      import com.work.abrechnung.persistence.billingclasses.DebitStateMachineBean;

      import com.work.abrechnung.persistence.common.billingfunctional.DebitPositionStateEnum;

      import com.work.abrechnung.persistence.sfclasses.LineItem;

      import com.work.abrechnung.persistence.sfclasses.LineItemPrice;

      import com.work.abrechnung.persistence.sfdao.LineItemAccessDao;

       

       

      @TransactionManagement(TransactionManagementType.CONTAINER)

      @TransactionAttribute(TransactionAttributeType.REQUIRED)

      @MessageDriven

      @DependsOn("module=JMS,name=\"BillingQueue\",type=Queue")

      public class BillingSchedulerMdb extends QueueControlBilling implements MessageListener {

       

                @PersistenceContext(unitName="billing_DS")

                private EntityManager          bsEm ;

       

       

                @PersistenceContext(unitName="sfImport_DS")

                private EntityManager          sfEm ;

       

          @EJB

          LineItemAccessDao lineItemAccessDao;

       

          public void onMessage(Message message) {

       

                    try {

                              final CalculateDebPosTaskIf  calculateDebPosParm = (CalculateDebPosTaskIf) ((ObjectMessage) message).getObject() ;

                              final TypedQuery<LineItem> quLineItem = sfEm.createQuery(LineItem.QUERYID__FIND_BY_ID, LineItem.class) ;

                              quLineItem.setParameter("id", calculateDebPosParm) ;

                              final LineItem lineItm = quLineItem.getSingleResult() ;

                              final DebitStateMachineBean debStateMachine = optCreateNewDebitStateEntry(

                                                                      calculateDebPosParm.getDebStateEntryId(),

                                                                      lineItm ) ;

                              final Object consumptionData = null ;

                              computeDebitPosition(debStateMachine, lineItm, consumptionData) ;

       

       

                              final Calendar oleNextCalDate = debStateMachine.getNextCalcDate() ;

                              final Calendar newNextCalDate = computeNextDepPosCalcDate(lineItm, oleNextCalDate)  ;

                              debStateMachine.setNextCalcDate(newNextCalDate) ;    

                              bsEm.merge(debStateMachine) ;

                    }

                    catch(JMSException  rtExcp) {

                              System.out.print(rtExcp.toString()) ;

                    }

          }

       

                private DebitStateMachineBean optCreateNewDebitStateEntry(Long debStateEntryId, LineItem lineItm) {

                          if (null == debStateEntryId) {

                                    final DebitStateMachineBean newStateEntry = new DebitStateMachineBean() ;

                                    newStateEntry.setFkey_LineItem(lineItm.getId()) ;

                                    newStateEntry.setJobNumber(4711) ; /* create a unique id number */

                                    newStateEntry.setPrevCalcDate(null) ;

                                    final Calendar nextDueDate4DebPosCalc = computeNextDepPosCalcDate(lineItm, newStateEntry.getPrevCalcDate()) ;

                                    newStateEntry.setNextCalcDate(nextDueDate4DebPosCalc) ;

                                    bsEm.persist(newStateEntry) ;

                                    return newStateEntry ;

                          }

                          else {

                                    final TypedQuery<DebitStateMachineBean> quDebState = bsEm.createQuery(DebitStateMachineBean.QUERYID__FIND_BY_ID, DebitStateMachineBean.class) ;

                                    quDebState.setParameter("id", debStateEntryId) ;

                                    return quDebState.getSingleResult() ;

                          }

                }

       

                private Calendar computeNextDepPosCalcDate(LineItem lineItm, Calendar prevCalcDate) {

                          Calendar retValue = null ;

                          if (null == prevCalcDate) {

                                    switch (lineItm.getPriceServiceDirection()) {

                                              case IN_ADVANCE:

                                              {

                                                        retValue = lineItm.getActivationDate() ;

                                                        break ;

                                              }

       

                                              case AFTERWARDS:

                                              { 

                                                        retValue = CalendarTools.endingDayOfMonth(lineItm.getStartDate()) ;

                                                        break ;

                                              }

                                    }

                                    return retValue ;

                          }

                          else {

                                    if ( CalendarTools.wasEndOfMonth(prevCalcDate) ) {

                                              final Calendar rawIncrDate = CalendarTools.incrCalendarByPeriod(prevCalcDate, lineItm.getPriceServicePeriod()) ;

                                              retValue = CalendarTools.endingDayOfMonth(rawIncrDate) ;

                                    }

                                    else {

                                              retValue = CalendarTools.endingDayOfMonth(prevCalcDate) ;

                                    }

                          }

                          return retValue;

                }

       

                private void computeDebitPosition(DebitStateMachineBean debStateMachine, LineItem          lineItem, Object                     consumptionData) {

                          final Calendar                    NOW = Calendar.getInstance() ;

                          NOW.setTime(new Date()) ;

                          final BigDecimal proportionalRate = CalendarTools.getProportionalRateOfMonth(

                                              lineItem.getStartDate(),

                                              debStateMachine.getNextCalcDate()) ;

                          final LineItemPrice          validPric = lineItemAccessDao.getLineItemPriceByLineItemIdAndDueDate(lineItem.getId(),debStateMachine.getNextCalcDate()) ; // LineItemAccessDao ;

                          final BigDecimal factoredBasedPrice = proportionalRate.multiply(validPric.getBasePrice()) ;

                          final DebitPosition          newDebPosition = new DebitPosition() ;

                          newDebPosition.setGenerationDate(NOW) ;

                          newDebPosition.setDebitPositionDueDate(debStateMachine.getNextCalcDate()) ;

                          newDebPosition.setNetAmount(factoredBasedPrice) ;

                          newDebPosition.setState(DebitPositionStateEnum.COMPUTED) ;

                          debStateMachine.addDebitPositions(newDebPosition) ;

                          bsEm.merge(newDebPosition) ;

                }

      }

       

       

      ejb-jar.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <ejb-jar 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_1.xsd"

          version="3.1">

          <enterprise-beans>

                    <!-- definition for the JMS sender  -->

              <session>

                  <ejb-name>DebitPositionTriggerBean</ejb-name>

                  <ejb-class>de.as24.abrechnung.ejbeans.billing.DebitPositionTrigger</ejb-class>

                  <message-destination-ref>

                            <message-destination-ref-name>jms/LogicBillingQueueDestination</message-destination-ref-name>

                            <message-destination-type>java.jms.Queue</message-destination-type>

                            <message-destination-usage>Produces</message-destination-usage>

                            <message-destination-link>LinkBillingQueue</message-destination-link>

                  </message-destination-ref>

              </session>

              <!-- definition for the JMS consumer  -->

              <message-driven>

                        <ejb-name>BillingSchedulerMdbBean</ejb-name>

                        <messaging-type>javax.jms.MessageListener</messaging-type>

                        <message-destination-type>javax.jms.Queue</message-destination-type>

                        <message-destination-link>LinkBillingQueue</message-destination-link>

              </message-driven>

          </enterprise-beans>

          <assembly-descriptor>

                          <message-destination>

                                    <message-destination-name>LinkBillingQueue</message-destination-name>

                          </message-destination>

                </assembly-descriptor>

      </ejb-jar>

       

       

      hornetq-jms.xml

       

      <configuration xmlns="urn:hornetq"

                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                  xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">

      [...]

         <connection-factory name="BillingConnectionFactory">

            <xa>true</xa>

            <connectors>

               <connector-ref connector-name="netty"/>

            </connectors>

            <entries>

               <entry name="/jms/XABillingConnectionFactory"/>

            </entries>

         </connection-factory>

      [...]

         <queue name="BillingQueue">

            <entry name="/queue/BillingQueue"/>

         </queue>

      </configuration>

       

      Regards,

       

      Jobame