通过JNDI使用ActiveMQ

编程入门 行业动态 更新时间:2024-10-14 04:30:42
本文介绍了通过JNDI使用ActiveMQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用JNDI创建与ActiveMQ的简单连接。


我有

I'm trying to create simply connect with ActiveMQ using JNDI. I have

  • 名为'example.A'的队列。

  • Queue named 'example.A'.

    根据触及JNDI的ActiveMQ文档,如果我想通过JNDI使用ConectionFactories和Queues(Topics),我必须在我的类路径上放置jndi.properties文件。据我所知,默认情况下,activeMQ类路径是%activemq%/ conf目录。我没有改变它。 所以我的队列有这个属性:

    According ActiveMQ documentation touching JNDI, if I want to use ConectionFactories and Queues (Topics) via JNDI, I have to place jndi.properties file on my classpath. As I have understood, activeMQ classpath is %activemq%/conf directory by default. I have not changed it. So I have this property for my queue:

    queue.MyQueue = example.A

    queue.MyQueue = example.A

    我为ActiveMQ创建了java客户端类,它使用如下的JNDI:

    I have created java client class for ActiveMQ which uses JNDI as below:

    Properties jndiParameters = new Properties() ; jndiParameters.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); jndiParameters.put(Context.PROVIDER_URL, "tcp://localhost:61616"); Context context = new InitialContext(jndiParameters); ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("ConnectionFactory"); Queue queue = (Queue) context.lookup("MyQueue");

  • 但它无法找到我的队列,它会抛出异常:javax.naming.NameNotFoundException:MyQueue

    but it cannot find my queue, it throws exception: javax.naming.NameNotFoundException: MyQueue

    我的错误在哪里?

    推荐答案

    问题是您是显式创建属性并将它们传递给InitialContext构造函数。这意味着将不会读取类路径上的jndi.properties。

    The problem is that you are explicitly creating the properties and passing them into the InitialContext constructor. This means the jndi.properties on the class path won't be read.

    您的代码应该类似于:

    Context context = new InitialContext(); ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("ConnectionFactory"); Queue queue = (Queue) context.lookup("MyQueue");

    更多推荐

    通过JNDI使用ActiveMQ

    本文发布于:2023-10-26 18:28:15,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1530989.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:JNDI   ActiveMQ

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!