首页 > 解决方案 > 消息驱动 bean 不接收来自主题的消息

问题描述

我正在使用 WildFly AS 并以独立完整配置运行我的 EJB 应用程序。我创建了消息驱动 bean,但由于某种原因,它不接收消息。

@MessageDriven(name = "receiver",
    activationConfig = {
            @ActivationConfigProperty(
                    propertyName = "destinationType",
                    propertyValue = "javax.jms.Topic"
            ),
            @ActivationConfigProperty(
                    propertyName = "destination",
                    propertyValue = "Ecare"
            ),
            @ActivationConfigProperty(
                    propertyName = "acknowledgeMode",
                    propertyValue = "Auto-acknowledge"
            )})
@ResourceAdapter("activemq-ra.rar")
public class JMSListener implements MessageListener {
    private Logger logger = Logger.getLogger("JMSListener logger");
    private JMSNotifier jmsNotifier = new JMSNotifier();

@Override
public void onMessage(Message message) {
    logger.info("Message received");
    jmsNotifier.notifyAllSubscribers();
}
}

我尝试从应用程序发送消息并通过 ActiveMQ 控制台手动发送。我可以看到他们来了,但 MDB 从不读取任何内容。我唯一的猜测是它可能实际上是在监听来自嵌入服务器的一些 JMS 系统的消息,而我正在将它们发送到独立的 ActiveMQ 系统,但我不知道如何检查它。

补充:基本上,我在standalone-full.xml 中找到了所有连接到JMS 的配置。

<subsystem xmlns="urn:jboss:domain:messaging-activemq:2.0">
        <server name="default">
            <security-setting name="#">
                <role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
            </security-setting>
            <address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
            <http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
            <http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
                <param name="batch-delay" value="50"/>
            </http-connector>
            <in-vm-connector name="in-vm" server-id="0">
                <param name="buffer-pooling" value="false"/>
            </in-vm-connector>
            <http-acceptor name="http-acceptor" http-listener="default"/>
            <http-acceptor name="http-acceptor-throughput" http-listener="default">
                <param name="batch-delay" value="50"/>
                <param name="direct-deliver" value="false"/>
            </http-acceptor>
            <in-vm-acceptor name="in-vm" server-id="0">
                <param name="buffer-pooling" value="false"/>
            </in-vm-acceptor>
            <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
            <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
            <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
            <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
            <pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
        </server>
    </subsystem>

并且在<subsystem xmlns="urn:jboss:domain:ejb3:5.0">

        <mdb>
            <resource-adapter-ref resource-adapter-name="${ejb.resource-adapter-name:activemq-ra.rar}"/>
            <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
        </mdb>

我试图添加以下配置

<subsystem xmlns="urn:jboss:domain:resource-adapters:2.0">
    <resource-adapters>
        <resource-adapter id="activemq">
            <archive>
                activemq-rar-5.10.0.rar
            </archive>

            <transaction-support>XATransaction</transaction-support>

            <config-property name="UseInboundSession">
                false
            </config-property>

            <config-property name="Password">
                defaultPassword
            </config-property>

            <config-property name="UserName">
                defaultUser
            </config-property>

            <config-property name="ServerUrl">
                tcp://localhost:61616
            </config-property>

            <connection-definitions>
                <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/ConnectionFactory" enabled="true" pool-name="ConnectionFactory">

                    <xa-pool>
                        <min-pool-size>1</min-pool-size>
                        <max-pool-size>20</max-pool-size>
                        <prefill>false</prefill>
                        <is-same-rm-override>false</is-same-rm-override>
                    </xa-pool>

                </connection-definition>
            </connection-definitions>

            <admin-objects>
                <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:jboss/activemq/queue/TestQueue" use-java-context="true" pool-name="TestQueue">

                    <config-property name="PhysicalName">
                        activemq/queue/TestQueue
                    </config-property>

                </admin-object>

                <admin-object class-name="org.apache.activemq.command.ActiveMQTopic" jndi-name="java:jboss/activemq/topic/TestTopic" use-java-context="true" pool-name="TestTopic">

                    <config-property name="PhysicalName">
                        activemq/topic/TestTopic
                    </config-property>

                </admin-object>
            </admin-objects>
        </resource-adapter>
    </resource-adapters>
</subsystem>

我也将此资源放在 mdb 标记中,但 deployemt 失败了,因为一些组件已经存在。之后,我尝试删除默认的 activemq 配置,但当时部署失败,因为它缺少一些组件。

标签: javajmsejbactivemqwildfly

解决方案


所以,我花了很多时间试图让它工作,倾斜,停止尝试几天,然后按照这些https://blog.coffeebeans.at/archives/230说明而不接触standalone-full.xml 和一切工作!


推荐阅读