[英]How to add JNDI destinations (Topics and Queues) with ActiveMQ?
I don't want to use jdni.properties
file, so to add new properties to my JNDI settings, I wrote following:我不想使用
jdni.properties
文件,因此要将新属性添加到我的 JNDI 设置中,我写了以下内容:
Hashtable<String, Object> jndi_env = new Hashtable<String, Object>();
jndi_env.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
jndi_env.put("connectionFactory.ConnectionFactory","vm://0");
jndi_env.put("topic.example","example");
My Problem is, when I call this class:我的问题是,当我调用这个 class 时:
initialContext = new InitialContext(jndi_env);
Since I pass a name parameter in the last line a URL context factory is looked up.由于我在最后一行传递了一个名称参数,因此查找了 URL 上下文工厂。
This makes my code looking for a tcp://localhost:61616
connection which I actually don't want.这使我的代码寻找我实际上不想要的
tcp://localhost:61616
连接。
I see that there are我看到有
QueueConnectionFactory: org.apache.activemq.ActiveMQConnectionFactory
example: org.apache.activemq.command.ActiveMQTopic
XAConnectionFactory: org.apache.activemq.ActiveMQXAConnectionFactory
which I don't want, or at least not the type they are.我不想要,或者至少不是他们的类型。
If I check without passing an argument using my jndi.properties
file where I don't get the issue of establishing a tcp connection, then I find just:如果我使用我的
jndi.properties
文件检查而不传递参数,而我没有遇到建立 tcp 连接的问题,那么我发现只是:
ConnectionFactory: org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory
queue: org.apache.activemq.artemis.jndi.ReadOnlyContext
queue/exampleQueue: org.apache.activemq.artemis.jms.client.ActiveMQQueue
dynamicTopics: org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory$2
dynamicQueues: org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory$1
So how can I change the object types of my added jndi_env.put("topic.example","example");
那么如何更改我添加的
jndi_env.put("topic.example","example");
的 object 类型so it will be like this (but of course for Topics)所以它会是这样的(但当然是主题)
queue: org.apache.activemq.artemis.jndi.ReadOnlyContext
queue/exampleQueue: org.apache.activemq.artemis.jms.client.ActiveMQQueue
When you create your InitialContext
you're passing in the wrong factory.创建
InitialContext
时,您传入了错误的工厂。 Currently you're passing in org.apache.activemq.jndi.ActiveMQInitialContextFactory
.目前您正在传递
org.apache.activemq.jndi.ActiveMQInitialContextFactory
。 This is the factory for ActiveMQ 5.x, not Artemis.这是 ActiveMQ 5.x 的工厂,而不是 Artemis。 You need to pass in
org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
instead, eg:您需要传入
org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
代替,例如:
Hashtable<String, Object> jndi_env = new Hashtable<String, Object>();
jndi_env.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
jndi_env.put("connectionFactory.ConnectionFactory","vm://0");
jndi_env.put("topic.example","example");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.