Glassfish 3.1 ActiveMQ 和 genericra 消费消息

发布于 2024-12-11 17:58:37 字数 1006 浏览 0 评论 0原文

使用的技术。

  • ActiveMQ 5.5.1
  • Glassfish 3.1
  • genericra 2.1

我在哪里;

  • 我安装了 ActiveMQ,并
  • 在 Glassfish 中配置并运行 genericra。我已经配置了连接器资源 (amqRes)、连接器连接池 (amqPool) 和管理对象资源 (amqQueue)。部署 genericra 并配置资源适配器配置。
  • 我可以从 Glassfish 中运行的应用程序将消息发布到 activeMQ 队列上。当我发帖时,我可以在 activeMQ 管理控制台的队列中看到一个新条目。

我们正在使用其他 JMS 队列(在 glassfish 中)并且它们运行良好。

我遇到的麻烦是从 activeMQ 队列中获取消息。我编写了一个实现 javax.jms.MessageListener 的测试 @MessageDriven bean。它有一个简单的方法(onMessage),只输出消息。我不知道如何注册 MDB 以便它从 activeMQ 队列中获取消息。我见过很多将条目放入 ejb-jar.xml、glassfish-ejb-jar.xml 或 sun-ejb-jar.xml 的示例 - 这些示例都不适合我。当我查看 activeMQ 控制台时,我看不到我创建的队列的任何消费者。

我读过很多博客,但似乎缺少最后一块拼图。

import javax.ejb.MessageDriven;
import javax.jms.Message;

@MessageDriven(mappedName = "amqQueue")
public class ActiveMQTestListener implements javax.jms.MessageListener {
    public void onMessage(Message message) {
        System.out.println(message.toString());
    }
}

Technologies used.

  • ActiveMQ 5.5.1
  • Glassfish 3.1
  • genericra 2.1

Where I am at;

  • I have ActiveMQ installed and running
  • genericra is configured and working in Glassfish. I have configured a connector resource (amqRes), Connector connection pool (amqPool) and admin object resource (amqQueue). Deployed genericra and configured the resource adapter configs.
  • I am able to post a message onto the activeMQ queue from an app running in Glassfish. When I post I can see a new entry on the queue in activeMQ admin console.

We are using other JMS queues (within glassfish) and they work well.

The trouble I'm having is getting a message off the queue from activeMQ. I have written a test @MessageDriven bean that implements javax.jms.MessageListener. It has one simple method (onMessage) that just outputs the message. I'm not sure how to register the MDB so that it picks up messages from the activeMQ queue. I have seen quite a few examples of putting entries in ejb-jar.xml, glassfish-ejb-jar.xml or sun-ejb-jar.xml - none of which have worked for me. When I look in the activeMQ console I can't see any consumers for the queue I've created.

I have read a number of blogs but seem to be missing this last piece of the jigsaw.

import javax.ejb.MessageDriven;
import javax.jms.Message;

@MessageDriven(mappedName = "amqQueue")
public class ActiveMQTestListener implements javax.jms.MessageListener {
    public void onMessage(Message message) {
        System.out.println(message.toString());
    }
}

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

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

发布评论

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

评论(1

空心↖ 2024-12-18 17:58:37

好的,经过多次尝试后,我成功了。事实证明,您不需要创建连接器资源、连接池或管理对象资源即可从活动 mq 接收消息。

总之,我在 glassfish http 中部署了连接器 genericra.rar (我将名称更改为 genericRA) ://java.net/downloads/genericjmsra/v2.1a/binaries/。我使用 http://activemq.apache.org/sjsas 中的设置配置了资源适配器配置-with-genericjmsra.html(复制在下面 - 稍微修改以适应示例)。我在 glassfish 中手动输入了详细信息。

asadmin create-resource-adapter-config
  --property
  SupportsXA=true
  :RMPolicy=OnePerPhysicalConnection
  :ProviderIntegrationMode=javabean
  :ConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :QueueConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :TopicConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :XAConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :XAQueueConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :XATopicConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :UnifiedDestinationClassName=org.apache.activemq.command.ActiveMQDestination
  :QueueClassName=org.apache.activemq.command.ActiveMQQueue
  :TopicClassName=org.apache.activemq.command.ActiveMQTopic
  :ConnectionFactoryProperties=brokerURL\\=tcp\\://127.0.0.1\\:61616
  :LogLevel=FINE
  genericRA

如果您想从 glassfish 发送 ale,我们发现管理对象资源没有出现在 jndi 列表 (./asadmin list-jndi-entries) 中。我们发现管理对象资源被禁用。我们必须编辑domain.xml 并设置enabled = true。

我的测试消息驱动bean;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(activationConfig =  {
    @ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destinationProperties",propertyValue = "PhysicalName=amqQueue")
})
public class ActiveMQTestListener implements MessageListener {
    public void onMessage(Message message) {
        System.out.println(message.toString());
    }
}

我的 glassfish-ejb-jar.xml;

<glassfish-ejb-jar>
    <enterprise-beans>
        <ejb>
            <ejb-name>ActiveMQTestListener</ejb-name>
            <mdb-resource-adapter>
                <resource-adapter-mid>genericRA</resource-adapter-mid>
            </mdb-resource-adapter>
        </ejb>
    </enterprise-beans>
</glassfish-ejb-jar>

我启动了 activeMQ、glassfish(在调试模式下,以便我可以看到消息)并打开控制台(http://localhost:8161/admin)。我创建了一个名为 amqQueue 的新队列。我创建了一条新消息(在 activeMQ 控制台中发送),将目标设置为 amqQueue 并在消息正文中输入了一些文本。点击发送,代码中触发了断点。

OK, so after much playing around I got it working. It turns out you don't need to create a connector resource, connection pool or admin object resource in order to receive a message from active mq.

In summary I deployed the connector genericra.rar (I changed the name to genericRA) in glassfish http://java.net/downloads/genericjmsra/v2.1a/binaries/. I configured the resource adapters configs using the settings from http://activemq.apache.org/sjsas-with-genericjmsra.html (copied below - slighyly modified to fit the example). I entered the details manualy in glassfish.

asadmin create-resource-adapter-config
  --property
  SupportsXA=true
  :RMPolicy=OnePerPhysicalConnection
  :ProviderIntegrationMode=javabean
  :ConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :QueueConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :TopicConnectionFactoryClassName=org.apache.activemq.ActiveMQConnectionFactory
  :XAConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :XAQueueConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :XATopicConnectionFactoryClassName=org.apache.activemq.ActiveMQXAConnectionFactory
  :UnifiedDestinationClassName=org.apache.activemq.command.ActiveMQDestination
  :QueueClassName=org.apache.activemq.command.ActiveMQQueue
  :TopicClassName=org.apache.activemq.command.ActiveMQTopic
  :ConnectionFactoryProperties=brokerURL\\=tcp\\://127.0.0.1\\:61616
  :LogLevel=FINE
  genericRA

If you want to be ale to send from glassfish we found that the admin object resource wasn't appearing in the jndi list (./asadmin list-jndi-entries). We discovered that the admin object resource was disabled. We had to edit the the domain.xml and set enabled = true.

My test message driven bean;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(activationConfig =  {
    @ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destinationProperties",propertyValue = "PhysicalName=amqQueue")
})
public class ActiveMQTestListener implements MessageListener {
    public void onMessage(Message message) {
        System.out.println(message.toString());
    }
}

My glassfish-ejb-jar.xml;

<glassfish-ejb-jar>
    <enterprise-beans>
        <ejb>
            <ejb-name>ActiveMQTestListener</ejb-name>
            <mdb-resource-adapter>
                <resource-adapter-mid>genericRA</resource-adapter-mid>
            </mdb-resource-adapter>
        </ejb>
    </enterprise-beans>
</glassfish-ejb-jar>

I started activeMQ, glassfish (in debug mode so that I could see the message) and brought up the console (http://localhost:8161/admin). I created a new queue called amqQueue. I created a new message (send in the activeMQ console), set the destination to amqQueue and entered some text in the message body. Clicked send and the break point was triggered in the code.

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