繁体   English   中英

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

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

令人惊讶的是,我找不到如何向Wildfly 10 jms队列发送消息的有效示例。 似乎每个版本的Jboss都有不同的执行方式,因此我可以找到一些示例,但每个示例都针对不同的版本,而Wildfly 10则没有。

我要做的是将消息从主wildfly实例(在计算机1上运行)发送到从属wildfly实例(在计算机2-n上运行)上托管的JMS队列。 换句话说,我可能有几个slave wildfly实例。

我已将以下内容添加到每个从属实例的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)]

当我使用网址“ 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]

显然,我什至不知道要使用哪个提供商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");

如果你得到

5000毫秒后操作失败,状态为WAITING

则表示由于某些不同的原因(例如防火墙,网络速度慢或其他原因),连接被卡住了5秒钟以上-客户端代码可能是正确的。

暂无
暂无

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

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