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

WildFly查找jms/RemoteConnectionFactory抛出Read past end of file异常

问题现象

在WildFly 26.1.1版本实现基础JMS操作时,编写了JNDI查找jms/RemoteConnectionFactory的代码如下:

Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
properties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
InitialContext ic=new InitialContext(properties);
ConnectionFactory f = (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory") ;

代码运行时持续抛出异常,核心报错为反序列化ActiveMQJMSConnectionFactory类型对象阶段触发java.io.EOFException: Read past end of file,完整异常栈如下:

Exception in thread "main" javax.naming.CommunicationException: WFNAM00020: Remote naming operation failed [Root exception is java.io.EOFException: Read past end of file]
    at org.wildfly.naming.client.remote.RemoteClientTransport.lookup(RemoteClientTransport.java:289)
    at org.wildfly.naming.client.remote.RemoteContext.lambda$lookupNative$0(RemoteContext.java:190)
    at org.wildfly.naming.client.NamingProvider.performExceptionAction(NamingProvider.java:222)
    at org.wildfly.naming.client.remote.RemoteContext.performWithRetry(RemoteContext.java:100)
    at org.wildfly.naming.client.remote.RemoteContext.lookupNative(RemoteContext.java:188)
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
    at org.wildfly.naming.client.store.RelativeFederatingContext.lookupNative(RelativeFederatingContext.java:58)
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:60)
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:66)
    at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:144)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at first.jms.WildflyJms.sendMessage(WildflyJms.java:17)
    at first.jms.WildflyJms.main(WildflyJms.java:9)
Caused by: java.io.EOFException: Read past end of file
    at org.jboss.marshalling.SimpleDataInput.eofOnRead(SimpleDataInput.java:151)
    at org.jboss.marshalling.SimpleDataInput.readUnsignedByteDirect(SimpleDataInput.java:294)
    at org.jboss.marshalling.SimpleDataInput.readUnsignedByte(SimpleDataInput.java:249)
    at org.jboss.marshalling.river.BlockUnmarshaller.readUnsignedByte(BlockUnmarshaller.java:258)
    at org.jboss.marshalling.river.BlockUnmarshaller.readInt(BlockUnmarshaller.java:296)
    at org.jboss.marshalling.river.BlockUnmarshaller.readUTF(BlockUnmarshaller.java:326)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.readExternal(ActiveMQConnectionFactory.java:200)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1444)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:298)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:231)
    at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
    at org.wildfly.naming.client.remote.RemoteClientTransport.lookup(RemoteClientTransport.java:271)
    ... 13 more
Caused by: an exception which occurred:
    in object of type org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory
根因分析

该异常绝大多数场景由客户端依赖与WildFly 26.1.1服务端内置组件版本不匹配导致:

  • WildFly 26.1.1内置的ActiveMQ Artemis版本为2.19.1,配套的JBoss Marshalling、WildFly Naming Client版本均与该Artemis版本做了序列化协议对齐
  • 若客户端自行引入了版本过高/过低的activemq-artemis-client、wildfly-naming-client、jboss-marshalling依赖,服务端序列化ConnectionFactory对象的二进制格式和客户端反序列化逻辑不兼容,读取对象流时会提前碰到流末尾,抛出EOFException

剩余少部分场景由配置错误触发:

  • 使用的端口未开启HTTP Remoting能力,或服务端对应监听器启动异常,返回了不完整的响应流
  • 客户端类路径存在重复依赖,多版本同个类加载冲突,导致反序列化逻辑执行异常
解决方案

按优先级从高到低排查修复:

  • 对齐客户端依赖版本
    不要手动指定Artemis客户端、Naming客户端、Marshalling组件的版本,直接引入WildFly 26.1.1官方提供的BOM统一管理所有相关依赖版本,从根源避免版本错配。如果使用Maven构建项目,导入对应BOM后再引入必要的客户端依赖即可,无需手动声明版本号。同时排查类路径,排除所有和WildFly客户端、Artemis客户端相关的重复、版本不一致的依赖,确保所有相关组件版本和服务端完全对齐。
  • 校验服务端配置与端口
    登录WildFly管理控制台,确认undertow子系统下绑定8080端口的默认http-listener已开启Remoting功能,同时检查服务端启动日志,确认JMS子系统、Remoting子系统无启动报错。可临时将PROVIDER_URL替换为remote://localhost:4447(WildFly默认原生Remoting端口)测试,若换端口后lookup正常,说明8080端口的HTTP Remoting配置存在问题。
  • 补充认证参数
    若服务端开启了ApplicationRealm域的认证,需要在JNDI参数中补充正确的用户名、密码配置,避免认证拦截导致返回不完整响应:
    properties.put(Context.SECURITY_PRINCIPAL, "JMS访问用户名");
    properties.put(Context.SECURITY_CREDENTIALS, "对应访问密码");
    
    上述用户需要通过WildFly自带的add-user.bat/add-user.sh脚本创建,并分配JMS资源的访问权限。

内容的提问来源于stack exchange,提问作者Pawel M

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 00:33:26