消息驱动的bean不会从主题接收消息

时间:2018-05-09 16:07:57

标签: java jms ejb activemq wildfly

我使用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配置,但是那次部署失败了,因为它缺少一些组件。

1 个答案:

答案 0 :(得分:0)

所以,我花了很多时间试图让它工作,倾斜,停止尝试几天,然后遵循这些https://blog.coffeebeans.at/archives/230指令而不触及standalone-full.xml,一切正常!