5

我需要在没有 J2EE 容器开销的情况下运行 JNDI 提供程序。我已尝试按照本文中的说明进行操作,该文章准确地描述了(第 3 页)我想要做什么。不幸的是,这些方向都失败了。我也必须将 jboss-common.jar 添加到我的类路径中。一旦我这样做了,我会得到一个堆栈跟踪:

$ java org.jnp.server.Main
0    [main] DEBUG
org.jboss.naming.Naming  - Creating
NamingServer stub, theServer=null,rmiPort=0,clientSocketFactory=null,serverSocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076[bindAddress=null]
Exception in thread "main"
java.lang.NullPointerException
     at org.jnp.server.Main.getNamingInstance(Main.java:301)
     at org.jnp.server.Main.initJnpInvoker(Main.java:354)
     at org.jnp.server.Main.start(Main.java:316)
     at org.jnp.server.Main.main(Main.java:104)

我希望能够完成这项工作,但我也愿意向其他轻量级独立 JNDI 提供者开放。所有这一切都是为了使 ActiveMQ 工作,如果有人可以建议另一个轻量级 JMS 提供程序,它可以在 vm 之外很好地工作,客户端所在的客户端不需要一个完整的应用程序服务器也可以工作。

4

3 回答 3

6

Apache ActiveMQ已经带有一个集成的轻量级 JNDI 提供程序。请参阅这些使用说明

基本上,您只需将 jndi.properties 文件添加到类路径即可。

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

# use the following property to configure the default connector
java.naming.provider.url = failover:tcp://localhost:61616

# use the following property to specify the JNDI name the connection factory
# should appear as. 
#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry

# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.MyQueue = example.MyQueue


# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.MyTopic = example.MyTopic
于 2008-10-13T09:10:33.830 回答
2

使用这样的 jndi.properties 文件:

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

# use the following property to configure the default connector
java.naming.provider.url=tcp://jmshost:61616

# use the following property to specify the JNDI name the connection factory
# should appear as. 
#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry

# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
#queue.MyQueue = example.MyQueue


# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.myTopic = MY.TOPIC

确保此文件在您的类路径中。然后您可以像这样查找主题/队列(减去适当的尝试/捕获):

context = new InitialContext(properties);

context = (Context) context.lookup("java:comp/env/jms");

topicConnectionFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");

topic = (Topic) context.lookup("myTopic");
于 2008-10-10T20:34:43.267 回答
1

JBoss JMQ 也可以仅使用 MicroKernel 和非常少的库集来运行。JBoss AS 安装程序具有“配置文件”选项,其中之一是用于独立 JMQ。它还允许您挑选和选择组件(尽管它对您的依赖关系没有太多帮助)。您是否尝试过运行安装程序?

于 2008-10-10T19:23:53.937 回答