OpenEJB:使用自定义 ConnectionFactory 配置 MDB

发布于 2024-09-28 10:54:11 字数 335 浏览 1 评论 0原文

如 OpenEJB 文档中所述,我们可以配置 JMS 连接工厂和队列,它们将在 JNDI 中显示为:

openejb:Resource/MyJmsConnectionFactory, 
openejb:Resource/MyQueue
  1. 给定这些 JNDI 条目,我如何告诉 MDB 使用它们?

  2. 是否可以更改 JNDI 名称,例如 ConnectionFactory 显示为 java:/ConnectionFactoryConnectionFactory

As described in OpenEJB docs, we can configure JMS connection factory and queues, and they will appear in JNDI as:

openejb:Resource/MyJmsConnectionFactory, 
openejb:Resource/MyQueue
  1. Given those JNDI entries, how can I tell to MDB to use them?

  2. Is it possible to change JNDI name, for example ConnectionFactory to appear as java:/ConnectionFactory
    or ConnectionFactory

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

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

发布评论

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

评论(1

彩虹直至黑白 2024-10-05 10:54:11

事情的运作方式可能与你想象的不同。指定 MDB 与 javax.jms.Queue 绑定,并且该队列的名称是 EJB 规范的一部分并通过 ActivationConfig 完成,如下所示:

@MessageDriven(activationConfig = {
        @ActivationConfigProperty(
           propertyName = "destinationType", 
           propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(
           propertyName = "destination", 
           propertyValue = "FooQueue")})
public static class JmsBean implements MessageListener {

    public void onMessage(Message message) {
    }
}

MDB 容器本身实际上根本不支持 JMS。它只是理解应该将 bean 连接到特定的资源适配器。

<openejb>
    <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        ServerUrl tcp://someHostName:61616
    </Resource>

    <Container id="MyJmsMdbContainer" ctype="MESSAGE">
        ResourceAdapter MyJmsResourceAdapter
    </Container>
</openejb>

上面显示了一个连接到通过 ActiveMQ 使用 JMS 的资源适配器的 MDB 容器。

下面是一个示例,显示 MDB 容器连接到 Quartz 资源适配器

不可能按照规范告诉 MDB 容器 JMS 特定的事情,这种关系比这更通用。这篇博客文章提供了一些见解:事情如何运作。

Things work differently than you may be imagining. Specifying that an MDB is tied to a javax.jms.Queue and the name of that queue is part of the EJB specification and done via the ActivationConfig, like so:

@MessageDriven(activationConfig = {
        @ActivationConfigProperty(
           propertyName = "destinationType", 
           propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(
           propertyName = "destination", 
           propertyValue = "FooQueue")})
public static class JmsBean implements MessageListener {

    public void onMessage(Message message) {
    }
}

The MDB container itself is not actually JMS-aware at all. It simply understands that it should hook the bean up to a specific Resource Adapter.

<openejb>
    <Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
        ServerUrl tcp://someHostName:61616
    </Resource>

    <Container id="MyJmsMdbContainer" ctype="MESSAGE">
        ResourceAdapter MyJmsResourceAdapter
    </Container>
</openejb>

The above shows an MDB Container hooked up to a Resource Adapter that uses JMS via ActiveMQ.

Here is an example that shows an MDB Container hooked up to a Quartz Resource Adapter

It isn't possible to tell the MDB Container about JMS specific things as per specification, the relationship is much more generic than that. This blog post gives some insight as to how things work.

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