java 如何为 JMS 连接工厂查找指定初始上下文详细信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15017265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to specify the initial context detail for JMS connection factory lookup
提问by user2098047
I faced a situation at work where I need to specify the initial context name to an underlying architecture component so that it can help me post message to a JMS Queue.
我在工作中遇到一种情况,我需要为底层架构组件指定初始上下文名称,以便它可以帮助我将消息发布到 JMS 队列。
How do I specify the exact context factory name?
I presume this is probably the string to be used "org.jnp.interfaces.namingcontextfactory
" based on google results. I would like to understand what is the authoritative method to arrive at this string taking perhaps the jboss server configuration as the starting point?
如何指定确切的上下文工厂名称?我认为这可能是org.jnp.interfaces.namingcontextfactory
基于 google 结果要使用的字符串“ ”。我想了解以jboss服务器配置为起点,获得此字符串的权威方法是什么?
Thanks Cinish
谢谢西尼什
回答by Nicholas
The initial context is a reference to a JNDInamespace where objects like JMS Queues can be looked up. I wrote this tutorialsome time ago, which you might find helpful.
初始上下文是对JNDI命名空间的引用,可以在其中查找 JMS 队列等对象。我前段时间写了这个教程,你可能会觉得它有帮助。
For a remotejboss server, there are 3 basic this should be (using the default port):
对于远程jboss 服务器,应该有 3 个基本的(使用默认端口):
- java.naming.factory.initial: org.jnp.interfaces.NamingContextFactory
- java.naming.factory.url.pkgs: org.jboss.naming:org.jnp.interfaces
- java.naming.provider.url: <hostname>:1099
- java.naming.factory.initial: org.jnp.interfaces.NamingContextFactory
- java.naming.factory.url.pkgs: org.jboss.naming:org.jnp.interfaces
- java.naming.provider.url: <主机名>:1099
The code would look something like this:
代码看起来像这样:
import javax.naming.*;
import javax.jms.*;
import java.util.*;
.....
Properties jndiProps = new Properties();
jndiProps.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
jndiProps.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
jndiProps.put("java.naming.provider.url", "localhost:1099");
Context ctx = new InitialContext(jndiProps);
Queue jmsQueue = (Queue)ctx.lookup("jndi-name-of-queue");
If your code is running insidethe jboss server, you don't need those properties since they are implicit.
如果您的代码在 jboss 服务器内运行,您不需要这些属性,因为它们是隐式的。
import javax.naming.*;
import javax.jms.*;
.....
Context ctx = new InitialContext(); // no properties needed
Queue jmsQueue = (Queue)ctx.lookup("jndi-name-of-queue");