令人惊讶的是,我找不到如何向 Wildfly 10 jms 队列发送消息的工作示例。似乎 Jboss 的每个版本都有不同的方法来执行此操作,因此我可以找到一些示例,但每个示例都针对不同的版本,而 Wildfly 10 则没有。
我想要做的是将消息从主 Wildfly 实例(在计算机 1 上运行)发送到托管在从属 Wildfly 实例(在计算机 2-n 上运行)上的 JMS 队列。换句话说,我可能有几个奴隶野蝇实例。
我已将以下内容添加到每个从属实例的standalone-full.xml中:
1)在global-modules元素中
<module name="org.jboss.remote-naming" slot="main"/>
2) 队列定义为
<jms-queue name="JobTaskMDB" entries="queue/JobTaskExecuterQueue java:jboss/exported/queue/JobTaskExecuterQueue"/>
3)每个从站都有访客用户
我添加到主实例的standalone-full.xml 中的唯一内容是上面的(1)
给定机器名称,例如“WILDD250148-8C9”,我如何有选择地将消息从主 Wildfly 实例发送到托管从属实例之一的指定机器的队列?
到目前为止,我什至无法通过队列的查找。 我尝试过以下代码:
String server = "WILDD250148-8C9";
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
env.put(Context.SECURITY_PRINCIPAL, "guest"); //has been added to all slaves
env.put(Context.SECURITY_CREDENTIALS, "guest");
String url =
//"queue/JobTaskExecuterQueue";
//"http-remoting://" + server + ":8080";
//"tcp://" + server + ":5445";
"jnp://" + server + ":1099";
env.put(Context.PROVIDER_URL, url);
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
remoteContext = new InitialContext(env);
String lookupName =
//"java:jboss/exported/queue/JobTaskExecuterQueue";
//"JobTaskMDB";
"queue.queue/JobTaskExecuterQueue";
Object x = remoteContext.lookup(lookupName);
例如,我总是收到“javax.naming.CommunicationException:无法连接到任何服务器”
javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [jnp://WILDD250148-8C9:1099 (No connection provider for URI scheme "jnp" is installed)]
或
javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [tcp://WILDD250148-8C9:5445 (No connection provider for URI scheme "tcp" is installed)]
当我使用 url“http-remoting://”+ server +“:8080”时,出现异常:
javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [http-remoting://WILDD250148-8C9:8080 (Operation failed with status WAITING after 5000 MILLISECONDS)] [Root exception is java.net.ConnectException: Operation failed with status WAITING after 5000 MILLISECONDS]
显然我什至不知道要使用哪个提供商 URL。
我在这里缺少什么?
最佳答案
WildFly 10 的正确 URL 提供程序是 http-remoting
。
这对我的 Wildfly 10.1 有效:
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
props.put(Context.SECURITY_PRINCIPAL, "user");
props.put(Context.SECURITY_CREDENTIALS, "password");
InitialContext ctx = new InitialContext(props);
ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
ActiveMQQueue queue = (ActiveMQQueue) ctx.lookup("queue/JobTaskExecuterQueue");
如果队列的 JNDI 名称为 java:jboss/exported/queue/JobTaskExecuterQueue
,则从客户端使用 queue/JobTaskExecuterQueue
(它相对于 >java:jboss/exported/
命名空间)
删除这一行,这是不需要的:
env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
如果你得到
Operation failed with status WAITING after 5000 MILLISECONDS
那么这意味着连接由于某些可能不同的原因(例如防火墙、慢速网络或其他原因)卡住了超过 5 秒 - 客户端代码可能是正确的。
关于java - 如何在 Wildfly 10 上查找远程 jms 队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47176412/