@MessageDriven bean没有收到消息 [英] @MessageDriven bean not receiving messages

查看:187
本文介绍了@MessageDriven bean没有收到消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我根据另一个问题的建议,对我的课程进行了一些修改,将我的课程变成一个 @Singleton ,而不是 @Stateless ,但是我不再像以前那样在我的 @MessageDriven Bean中收到消息。建议?请注意,该主题在 jbossmq-destinations-service.xml中正确定义

I made some changes per suggestions from another question to turn my class into a @Singleton rather than @Stateless, however I'm no longer receiving messages in my @MessageDriven Bean as I was before. Suggestions? Note that the topic is correctly defined in jbossmq-destinations-service.xml

@javax.ejb.Singleton(mappedName="MySingletonClass")
public class MySingletonClass implements SomeInterface
{
   private Timer timer = null;

   @javax.annotation.Resource
   TimerService timerService;


   /**
    * Creates the timer.
    */
   @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
   public void resetTimer()
   {
      if (timer != null)
      {
         timer.cancel();
      }
      timer = timerService.createTimer(30000, "Note");
   }

   @Override
   public void readResponseMsg(Document responseXml)
   {
      resetTimer();
      //Do stuff
   }

   @Override
   @Timeout
   public void timeout() throws RemoteException
   {
       //do stuff
   }
}

和MDB:

@javax.ejb.MessageDriven(mappedName = "jms/MyTopic", activationConfig = {
      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
      @ActivationConfigProperty(propertyName = "destination", propertyValue = "MyTopic"),
      @ActivationConfigProperty(propertyName = "messagingType", propertyValue = "javax.jms.MessageListener"),
      @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
@ResourceAdapter("activemq.rar")
public class MyMDB implements MessageListener
{
   private static final Logger ourLogger = Logger.getLogger(MyMDB.class);

   @javax.ejb.EJB(mappedName="MySingletonClass") private MySingletonClassInterface reader;

   /**
    * @param message
    */
   public void onMessage(Message message)
   {
      TextMessage textMessage = (TextMessage) message;
      try
      {
         System.out.println("Received Message Text: " + textMessage.getText());
         reader.readResponseMsg(loadXMLFromString(textMessage.getText()));
      }
      catch (JMSException | SAXException | ParserConfigurationException | IOException e)
      {
         ourLogger.error("Exception handling Schedule Results Message", e);
      }
   }
}

这是界面: / p>

This is the interface:

@javax.ejb.Local
public interface SomeInterface
{
   public void readResponseMsg(Document responseXml);


   public void timeout() throws RemoteException;
}

更新我一直在玩弄一些东西现在看到一些例外,至少表明发生了一些事情。我已经更新了上面的代码与我的更改。这是我的例外:

UPDATE I've been fiddling with some things and am now seeing some exceptions that at least indicate something is happening. I've updated the code above with my changes. This is my exception:

Caused by: javax.naming.NameNotFoundException: MySingletonClass not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:771) [:5.0.5.Final]
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:779) [:5.0.5.Final]
    at org.jnp.server.NamingServer.getObject(NamingServer.java:785) [:5.0.5.Final]
    at org.jnp.server.NamingServer.lookup(NamingServer.java:396) [:5.0.5.Final]
    at org.jnp.server.NamingServer.lookup(NamingServer.java:399) [:5.0.5.Final]
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728) [:5.0.5.Final]
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688) [:5.0.5.Final]
    at javax.naming.InitialContext.lookup(InitialContext.java:411) [:1.7.0_25]
    at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1350) [:5.0.5.Final]
    ... 61 more

此外, JBoss 6启动日志,我也看到这样:

Also, further up in the JBoss 6 startup log, I am also seeing this:

 [BeanInstantiatorDeployerBase] Installed org.jboss.ejb3.instantiator.impl.Ejb31SpecBeanInstantiator@fbda95 into MC at org.jboss.ejb.bean.instantiator/mmpl/server/MySingletonClass

然后稍微进一步的日志:

then a little further down the log:

DEPLOYMENTS MISSING DEPENDENCIES:
  Deployment "jboss-switchboard:appName=mmpl,module=server,name=MyMDB" is missing the following dependencies:
   Dependency "jboss.j2ee:ear=mmpl.ear,jar=server.jar,name=MySingletonClass,service=EJB3" (should be in state "Installed", but is actually in state "** NOT FOUND Depends on 'jboss.j2ee:ear=mmpl.ear,jar=server.jar,name=MySingletonClass,service=EJB3',whenRequired=MapControllerStateModel$ControllerStateWrapper@7ba014{Installed},dependentState=MapControllerStateModel$ControllerStateWrapper@7ba014{Installed} **")
  Deployment "jboss.j2ee:ear=mmpl.ear,jar=server.jar,name=MySingletonClass,service=EJB3_endpoint" is missing the following dependencies:
    Dependency "jboss.j2ee:ear=mmpl.ear,jar=server.jar,name=MySingletonClass,service=EJB3" (should be in state "Installed", but is actually in state "** NOT FOUND Depends on 'jboss.j2ee:ear=mmpl.ear,jar=server.jar,name=MySingletonClass,service=EJB3' **")

DEPLOYMENTS IN ERROR:
  Deployment "jboss.j2ee:ear=mmpl.ear,jar=server.jar,name=MySingletonClass,service=EJB3" is in error due to the following reason(s): ** NOT FOUND Depends on 'jboss.j2ee:ear=mmpl.ear,jar=server.jar,name=MySingletonClass,service=EJB3',whenRequired=MapControllerStateModel$ControllerStateWrapper@7ba014{Installed},dependentState=MapControllerStateModel$ControllerStateWrapper@7ba014{Installed} **, ** NOT FOUND Depends on 'jboss.j2ee:ear=mmpl.ear,jar=server.jar,name=MySingletonClass,service=EJB3' **


推荐答案

我最终放弃了ejb单身汉的想法,并使用了因为,它完美地工作:

I ended up abandoning the ejb singleton idea and using the following, which works perfectly:

public class MySingletonClass implements SomeInterface
{
   private ScheduledFuture<?> handle;
   private static ScheduledExecutorService executor;
   private static SomeInterface instance;

   public void readResponseMsg(Document responseXml)
   {
       resetTimer();
       //do stuff
   }

   /**
    * Creates the timer.
    */
   private void resetTimer()
   {
      if (handle != null)
      {
         handle.cancel(false);
      }
      handle = executor.schedule(this, 30l, TimeUnit.SECONDS);
   }


   /**
    * Initialize the static variables. Should only be called once per server
    * restart
    */
   private static void init()
   {
      try
      {
         executor = Executors.newSingleThreadScheduledExecutor();
         inited = true;
      }
      catch (Exception e)
      {
         ourLogger.error("Exception initializing ScheduleResultReader", e);
      }
   }

   public static SomeInterface getInstance()
   {
      if (instance == null)
      {
         instance = new MySingletonClass();
      }

      return instance;
   }

}

这篇关于@MessageDriven bean没有收到消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆