ActiveMQInitialContextFactory与NamingContextFactory [英] ActiveMQInitialContextFactory vs. NamingContextFactory

查看:121
本文介绍了ActiveMQInitialContextFactory与NamingContextFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Java企业应用程序,该应用程序使用activemq将消息发送到独立队列代理。

I'm creating a java enterprise application which uses activemq to send messages to a standalone queue broker.

我目前通过jndi查找来维护对长期资源的访问。效果很好。我想在ActiveMQ连接工厂和队列连接工厂中继续这种模式,但是在 amq中文档,它指定我的jndi.properties应该具有:

I currently maintain access to long lived resources through jndi lookup which works quite nicely. I'd like to continue this pattern with the ActiveMQ connection factories and queue connection factories, however in the amq documentation it specifies that my jndi.properties should have:

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory

而默认的jndi.properties(可用于我的简单对象和外观查找具有:

while the default jndi.properties (which works with my simple object and facade lookups has:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

我可以与另一个一起使用吗?我可以拥有两个jndi.properties文件或两个初始上下文吗?

Can I use one with the other? Can I have two jndi.properties files or two initial contexts somehow?

问题说明了如何通过jndi仅配置activemq。希望他们一起玩得开心。

This question shows how to configure ONLY activemq through jndi. I want them to play nicely together.

推荐答案

您可以创建任意数量的 InitialContext 对象。您只需将环境传递到其构造函数正确初始化它。

You can create any number of InitialContext objects you want. You just have to pass environment to its constructor to properly initialize it.

因此,您仍然可以安全地使用 jndi.properties 并使用如下代码初始化activemq的初始上下文:

So you can still safely use jndi.properties and initialize initial context for activemq with the code which may look like this:

public void setUpActiveMQResources() throws IOException, NamingException {
    InitialContext context = createInitialContext("/activemq.jndi.properties");
    // do what you want
}

public InitialContext createInitialContext(String resource) throws IOException, NamingException {
    InputStream is = getClass().getResourceAsStream(resource);
    Properties props = new Properties();
    try {
        props.load(is);
    } finally {
        is.close();
    }
    return new InitialContext(props);
}

activemq.jndi.properties 在这种情况下是类路径资源,其内容类似于此处

activemq.jndi.properties in that case is the classpath resource with content like here

这篇关于ActiveMQInitialContextFactory与NamingContextFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆