简体   繁体   English

如何在Wildfly 10上查找远程JMS队列

[英]How to lookup a remote jms queue on Wildfly 10

It's amazing that i can't find a working example of how to send a message to a Wildfly 10 jms queue. 令人惊讶的是,我找不到如何向Wildfly 10 jms队列发送消息的有效示例。 It seems every version of Jboss had a different way of doing this so i can find a few examples but each one addresses a different version and none for Wildfly 10. 似乎每个版本的Jboss都有不同的执行方式,因此我可以找到一些示例,但每个示例都针对不同的版本,而Wildfly 10则没有。

what I'm trying to do is send a message from a master wildfly instance (running on machine 1) to a JMS queue hosted on a slave wildfly instance (running on machine 2-n). 我要做的是将消息从主wildfly实例(在计算机1上运行)发送到从属wildfly实例(在计算机2-n上运行)上托管的JMS队列。 In other words, i may have several slave wildfly instances. 换句话说,我可能有几个slave wildfly实例。

I've added to the standalone-full.xml of each slave instance the following: 我已将以下内容添加到每个从属实例的standalone-full.xml中:
1) In the global-modules element 1)在global-modules元素中

<module name="org.jboss.remote-naming" slot="main"/>

2) The queue is defined as 2)队列定义为

<jms-queue name="JobTaskMDB" entries="queue/JobTaskExecuterQueue java:jboss/exported/queue/JobTaskExecuterQueue"/>

3) Every slave has the guest user 3)每个奴隶都有来宾用户

The only thing I've added to the standalone-full.xml of the master instance is (1) above 我添加到主实例的standalone-full.xml中的唯一内容是上面的(1)

Given a machine name, such as "WILDD250148-8C9", how can i selectively send a message from the master Wildfly instance to the queue of the specified machine hosting one of the slave instances? 给定机器名称,例如“ WILDD250148-8C9”,我如何有选择地将消息从主Wildfly实例发送到承载从属实例之一的指定计算机的队列?

So far I can't even get passed the lookup of the queue. 到目前为止,我什至无法通过队列查询。 I've tried the following code: 我尝试了以下代码:

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);

I always get "javax.naming.CommunicationException: Failed to connect to any server", for example 我总是得到“ 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)]

or 要么

javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [tcp://WILDD250148-8C9:5445 (No connection provider for URI scheme "tcp" is installed)]

when I used the url "http-remoting://" + server + ":8080" I got the exception: 当我使用网址“ http-remoting://” +服务器+“: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]

Obviously i don't even know which provider URL to use. 显然,我什至不知道要使用哪个提供商URL。

what am i missing here? 我在这里想念什么?

The correct URL provider for WildFly 10 is http-remoting . WildFly 10的正确URL提供程序是http-remoting This works for me with Wildfly 10.1: 这适用于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");

If the JNDI name of the queue is java:jboss/exported/queue/JobTaskExecuterQueue then from the client, use queue/JobTaskExecuterQueue (it's relative to the java:jboss/exported/ namespace) 如果队列的JNDI名称为java:jboss/exported/queue/JobTaskExecuterQueue则从客户端使用queue/JobTaskExecuterQueue (它相对于java:jboss/exported/名称空间)

Remove this line, this is not needed: env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces"); 删除此行,不需要此行: env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");

If you're getting 如果你得到

Operation failed with status WAITING after 5000 MILLISECONDS 5000毫秒后操作失败,状态为WAITING

then it means that the connection got stuck for more than 5 seconds for some probably different reason, like a firewall, slow network or something - the client code is probably correct. 则表示由于某些不同的原因(例如防火墙,网络速度慢或其他原因),连接被卡住了5秒钟以上-客户端代码可能是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM