You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将WildFly 12连接至远程Artemis 2.5服务器?

解决WildFly 12连接远程Artemis 2.5队列的配置问题

我来帮你梳理下当前遇到的问题,并结合WildFly 12.0.0.Final和Artemis 2.5.0的版本特性给出针对性的解决方案:

一、先修正JNDI队列绑定的错误配置

你当前的external-context配置存在属性错误,导致无法正确查找到远程队列。请修改standalone-full.xml中的naming子系统配置:

<subsystem xmlns="urn:jboss:domain:naming:2.0">
    <bindings>
        <external-context name="java:global/RemoteArtemisJNDI" module="org.apache.activemq.artemis" class="javax.naming.InitialContext">
            <environment>
                <property name="java.naming.factory.initial" value="org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"/>
                <property name="java.naming.provider.url" value="tcp://localhost:61616"/>
                <!-- 修正队列JNDI配置:Artemis的队列前缀是`queue.`直接加队列名 -->
                <property name="queue.DemoQueue" value="DemoQueue"/>
            </environment>
        </external-context>
        <!-- 绑定到WildFly标准JMS队列命名空间,避免资源冲突 -->
        <lookup name="java:/jms/queue/DemoQueue" lookup="java:global/RemoteArtemisJNDI/DemoQueue"/>
    </bindings>
    <remote-naming/>
</subsystem>

同时调整生产者代码中的队列JNDI引用:

@Resource(lookup="java:/jms/queue/DemoQueue")
private Queue queue;

二、修复MDB无限接收消息的问题

你使用useJNDI=false时,MDB会直接实例化本地队列(连接WildFly内置的Artemis服务器),而非远程队列,这就是无限收消息的根源。请修改MDB配置为JNDI模式:

@ResourceAdapter("remote-artemis")
@MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/DemoQueue"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
})
public class Receiver implements MessageListener {
    @Override
    public void onMessage(Message message) {
        try {
            if (message instanceof TextMessage) {
                System.out.println("Received remote message: " + ((TextMessage) message).getText());
            }
        } catch (JMSException e) {
            throw new RuntimeException("处理消息失败", e);
        }
    }
}

三、完善远程连接工厂配置

Artemis默认开启认证,你需要在pooled-connection-factory中添加账号密码(默认是admin/admin),同时关闭HA模式(非集群场景):

<pooled-connection-factory name="remote-artemis" 
                           entries="java:/jms/RemoteArtemisCF" 
                           connectors="remote-artemis"
                           user="admin"
                           password="admin"
                           ha="false"/>

四、验证Artemis服务器的基础配置

确保Artemis的broker.xml中acceptor配置允许远程连接(默认配置即可):

<acceptors>
    <acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true</acceptor>
</acceptors>

你之前的队列配置是正确的,无需修改:

<addresses>
    <address name="DemoQueue">
        <anycast>
            <queue name="DemoQueue"/>
        </anycast>
    </address>
</addresses>

完成以上配置后,重启WildFly和Artemis服务器:

  1. 生产者发送消息时,会通过远程连接工厂将消息投递到Artemis的DemoQueue
  2. MDB会通过指定的资源适配器连接远程Artemis,接收队列中的消息,不会再出现无限接收的情况

内容的提问来源于stack exchange,提问作者Alessio Fiore

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:47:22