You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by jpietras <jp...@gmail.com> on 2019/03/22 19:41:43 UTC

JNDI lookup - NameNotFoundException

I am in the process of migrating a codebase from Wildfly 10 / Artemis 1.1 to
Wildfly 14 / Artemic 2.6.3.

I was hoping someone could assist me on what I'm not understanding about not
being able to lookup a queue I am adding in my code.

 InitialContext jndi = new InitialContext();
 ConnectionFactory cf = (ConnectionFactory)
jndi.lookup("ConnectionFactory");
 connection = cf.createConnection();
 session = (QueueSession) connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
 Queue managementQueue =
ActiveMQJMSClient.createQueue("activemq.management");
 QueueRequestor requestor = new QueueRequestor(session, managementQueue);
 connection.start();
        
  Message m = session.createMessage();
        
  JMSManagementHelper.putOperationInvocation(m, ResourceNames.BROKER,
"createQueue", "abc","queue/abc");

This appears to successfully add the abc queue. 

If i run:
 JMSManagementHelper.putAttribute(m, ResourceNames.BROKER, "queueNames")
 JMSManagementHelper.getResult(requestor.request(m))

I can see my queue (queue/abc) in the list of queue names.

Is it possible for me to lookup my queue through the initial context?

I am trying to do variations of jndi.lookup("queue/abc") to no avail.

Any help would be greatly appreciated.

Thanks



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Re: JNDI lookup - NameNotFoundException

Posted by Justin Bertram <jb...@apache.org>.
In Artemis 1.x there was an artificial distinction between JMS destinations
and core addresses and queues (e.g. using prefixes like "jms.queue." and
"jms.topic."). Support for new protocols was added during the 1.x life-span
and this distinction was becoming more and more problematic as it
needlessly complicated protocol interoperability. A big chunk of work was
done for Artemis 2.x to remove this artificial distinction. Part of that
work removed the JMS-specific management operations as it wasn't tenable to
have management ops for all supported protocols/APIs. So, when you send
that management message what you're actually doing is invoking:


org.apache.activemq.artemis.api.core.management.ActiveMQServerControl#createQueue(java.lang.String,
java.lang.String) [1]

This results in a creating a core address named "abc" with a core queue
named "queue/abc" mapped to it. Since the routing type isn't specified it
will use the default defined in your <address-settings> (i.e. via
<default-address-routing-type> & <default-queue-routing-type>. If no
default is defined then MULTICAST is used. There is nothing in the method
parameters related to JNDI because JNDI is a really a JMS-specific thing
and this method is only working with core resources. This is probably not
what you expect or what you want if you're trying to use a JMS queue (which
should be using ANYCAST routing).

The ActiveMQ Artemis JNDI implementation is client-side only and it's
configured via environment properties. Wildfly's JNDI implemention is
completely different because it is a client-server implementation. In other
words requests from the JNDI client go over the network to the Wildfly
server where the lookup is performed and the result is returned to the
client. Since ActiveMQ Artemis core management operations don't support
JNDI configuration parameters you'll need to use the Wildfly management
operations which are geared specifically for JMS (since ActiveMQ Artemis
specifically serves as the JMS implementation in Wildfly). Please refer to
Wildfly documentation on how to do this.


Justin

[1]
https://activemq.apache.org/artemis/docs/javadocs/javadoc-2.6.0/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.html#createQueue-java.lang.String-java.lang.String-

On Fri, Mar 22, 2019 at 4:58 PM jpietras <jp...@gmail.com> wrote:

> I am in the process of migrating a codebase from Wildfly 10 / Artemis 1.1
> to
> Wildfly 14 / Artemic 2.6.3.
>
> I was hoping someone could assist me on what I'm not understanding about
> not
> being able to lookup a queue I am adding in my code.
>
>  InitialContext jndi = new InitialContext();
>  ConnectionFactory cf = (ConnectionFactory)
> jndi.lookup("ConnectionFactory");
>  connection = cf.createConnection();
>  session = (QueueSession) connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
>  Queue managementQueue =
> ActiveMQJMSClient.createQueue("activemq.management");
>  QueueRequestor requestor = new QueueRequestor(session, managementQueue);
>  connection.start();
>
>   Message m = session.createMessage();
>
>   JMSManagementHelper.putOperationInvocation(m, ResourceNames.BROKER,
> "createQueue", "abc","queue/abc");
>
> This appears to successfully add the abc queue.
>
> If i run:
>  JMSManagementHelper.putAttribute(m, ResourceNames.BROKER, "queueNames")
>  JMSManagementHelper.getResult(requestor.request(m))
>
> I can see my queue (queue/abc) in the list of queue names.
>
> Is it possible for me to lookup my queue through the initial context?
>
> I am trying to do variations of jndi.lookup("queue/abc") to no avail.
>
> Any help would be greatly appreciated.
>
> Thanks
>
>
>
> --
> Sent from:
> http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
>