JBoss EJB3 MDB 配置

发布于 2024-08-05 06:40:33 字数 3055 浏览 7 评论 0原文

我试图理解在 JBoss 4.3 中运行的一些 EJB 3 代码。

我们在 JBoss 中配置了一个 ejb3-interceptors-aop.xml 文件,其中包含一些 MDB 配置,然后我们就得到了 MDB Java 类。

我想了解的是 MDB 何时以及如何“绑定”到 MQ?即MDB何时/如何开始监听MQ队列?

JBoss在启动时是否读取ejb3-interceptors-aop.xml文件,然后找到AspectDomain注释等于“GatewayMDB”的类并在启动时“绑定”到MQ队列?


ejb3-interceptors-aop.xml 中的 XML:

   <domain name="GatewayMDB">
      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
      </bind>
      <bind pointcut="execution(public * *->*(..))">
         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
      </bind>
      <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=30, timeout=10000)
      </annotation>
      <annotation expr="!class(@org.jboss.annotation.ejb.DefaultActivationSpecs)">
         @org.jboss.annotation.ejb.DefaultActivationSpecs ({@javax.ejb.ActivationConfigProperty(propertyName = "channel", propertyValue = "SYSTEM.DEF.SVRCONN"), @javax.ejb.ActivationConfigProperty(propertyName = "hostName", propertyValue = "10.10.10.10"), @javax.ejb.ActivationConfigProperty(propertyName = "queueManager", propertyValue = "QM"), @javax.ejb.ActivationConfigProperty(propertyName = "port", propertyValue = "1419"),@javax.ejb.ActivationConfigProperty(propertyName = "transportType", propertyValue = "CLIENT")})
      </annotation>
   </domain>

MDB 类:

@MessageDriven(name = "BridgeMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "TO.WLS.LQUEUE.BG"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "maxPoolDepth", propertyValue = "1") })
@ResourceAdapter("wmq.jmsra.rar")
@AspectDomain("GatewayMDB") 
@Interceptors(SpringBeanAutowiringInterceptor.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class BridgeMDB implements MessageListener {
    private static Logger logger = Logger.getLogger(BridgeMDB.class);


    @Autowired
    private MessageProcessor messageProcessor;
    @Autowired
    private MessageTranslator messageTranslator;

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void onMessage(Message message) {
        ...
    }

}

I am trying to understand some EJB 3 code running in JBoss 4.3.

We've got an ejb3-interceptors-aop.xml file configured in JBoss with some MDB configuration and then we've got the MDB Java class.

What I'd like to understand is when and how does the MDB get "bound" to the MQ? That is, when/how does the MDB start listening to the MQ queue?

Does JBoss at startup read the ejb3-interceptors-aop.xml file and then find the class with the AspectDomain annotation equal to "GatewayMDB" and "bind" to the MQ queue at startup?


XML in ejb3-interceptors-aop.xml:

   <domain name="GatewayMDB">
      <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
         <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
      </bind>
      <bind pointcut="execution(public * *->*(..))">
         <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
         <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
         <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
      </bind>
      <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
         @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=30, timeout=10000)
      </annotation>
      <annotation expr="!class(@org.jboss.annotation.ejb.DefaultActivationSpecs)">
         @org.jboss.annotation.ejb.DefaultActivationSpecs ({@javax.ejb.ActivationConfigProperty(propertyName = "channel", propertyValue = "SYSTEM.DEF.SVRCONN"), @javax.ejb.ActivationConfigProperty(propertyName = "hostName", propertyValue = "10.10.10.10"), @javax.ejb.ActivationConfigProperty(propertyName = "queueManager", propertyValue = "QM"), @javax.ejb.ActivationConfigProperty(propertyName = "port", propertyValue = "1419"),@javax.ejb.ActivationConfigProperty(propertyName = "transportType", propertyValue = "CLIENT")})
      </annotation>
   </domain>

MDB class:

@MessageDriven(name = "BridgeMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "TO.WLS.LQUEUE.BG"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "maxPoolDepth", propertyValue = "1") })
@ResourceAdapter("wmq.jmsra.rar")
@AspectDomain("GatewayMDB") 
@Interceptors(SpringBeanAutowiringInterceptor.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class BridgeMDB implements MessageListener {
    private static Logger logger = Logger.getLogger(BridgeMDB.class);


    @Autowired
    private MessageProcessor messageProcessor;
    @Autowired
    private MessageTranslator messageTranslator;

    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void onMessage(Message message) {
        ...
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在风中等你 2024-08-12 06:40:33

免责声明:这是一个假设,因为我不知道jboss代码。


在 java 中处理类文件的常见方法是通过类路径读取它们(在本例中是在加载时)并为每个类构造某种元数据。

然后,当应用程序引导时,容器将读取类的元数据以连接/注入/配置在类中定义的适当属性。

至于xml,大多数jboss配置都是静态的,也就是说,你必须重新启动应用程序服务器才能使更改生效。

总而言之,我想说你的观察是正确的。

Disclaimer: this is a supposition, since I don't know the jboss code.


The common way of processing class files in java is to read them through the class path (in this case it would be at load-time) and construct some sort of metadata for each class.

Then, when the application bootstraps the container will read the class's metadatada to wire/inject/configure the appropriate attributes that were defined within the class.

As for the xml, most of the jboss configuration is static AFAIK, ie, you have to restart the app server in order for changes to take effect.

So all in all, I would say that your observation is correct.

独孤求败 2024-08-12 06:40:33

为了清楚地了解此过程,最好的选择是阅读 JCA 规范。这是一个清晰易懂的规范。

IBM 提供了部署到 JBoss 的 JCA 适配器。当 JBoss 部署 MDB 时,“激活规范”会传递到 IBM JCA。然后,IBM JCA 为 MDB 实例创建一个托管连接工厂。请注意,这与 JBoss 服务器配置中配置的任何连接工厂是独立且不同的。

激活规范的一部分是 JMS 会话的数量。 IBM JCA 创建并管理这些会话。 IBM JCA 还在这些会话上创建 JMS 消息侦听器。

收到消息后,IBM JCA 创建消息驱动上下文,从 JBoss 托管实例池请求 MDB 实例,向 MDB 实例提供消息驱动上下文并调用 MDB onMessage() 方法。

For a clear understanding of this process, your best bet would be to read the JCA specification. It is a clearly and easily understandable spec.

IBM provides their JCA adapter which is deployed to JBoss. When JBoss deploys your MDB, an "activation specification" is passed to the IBM JCA. The IBM JCA then creates a managed connection factory for the MDB instances. Note that this is separate and distinct from any connection factories as configured in the JBoss server configuration.

Part of the activation spec is the number of JMS sessions. The IBM JCA creates and manages these sessions. The IBM JCA also create JMS message listeners on these sessions.

When a message is received, the IBM JCA creates a message driven context, requests an MDB instance from the JBoss managed instance pool, provides the message driven context to the MDB instance and calls the MDB onMessage() method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文