activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From CobraTheSleek <kalic...@yahoo.com>
Subject JBoss JNDI assistance requested.
Date Wed, 07 Nov 2007 00:27:03 GMT

I am trying to understand how to work with JBoss JNDI and Active MQ.

My activemq-ds.xml file contains a defition of a queue:
...
<mbean code="org.jboss.resource.deployment.AdminObject"
name="activemq.queue:name=org.apache.activemq.spring.queue">
      <attribute name="JNDIName">springQueue</attribute>
      <depends
optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra.rar'</depends>
      <attribute name="Type">javax.jms.Queue</attribute>
      <attribute
name="Properties">PhysicalName=queue.org.apache.activemq.spring.queue</attribute>
   </mbean>
....
My JBoss admin console shows the queue bound as:

activemq.queue
name=org.apache.activemq.spring.queue 
name=outboundQueue 

I am trying to connect to the JNDI resource using the following code:

try {
	    Properties env2 = new Properties();

	    env2.put(Context.INITIAL_CONTEXT_FACTORY,
		    "org.jnp.interfaces.NamingContextFactory");
	    env2.put(Context.PROVIDER_URL, "jnp://localhost:1099");
	    env2.put("java.naming.factory.url.pkgs",
"org.jnp.interfaces:org.jboss.naming");
            
                InitialContext jndiContext = new InitialContext(env2);
	    
	    Object ref = jndiContext.lookup("ConnectionFactory");

	    System.out.println("ref is null:" + (ref == null));

	    PortableRemoteObject p = new PortableRemoteObject();
	    
	    QueueConnectionFactory tFactory = (QueueConnectionFactory)p 
            	.narrow(ref, QueueConnectionFactory.class); 

	    ref = jndiContext.lookup("springQueue");

	    System.out.println("ref is null:" + (ref == null));

	    p = new PortableRemoteObject();

	    Queue q = (Queue) p.narrow(ref, Queue.class);
	    
	    QueueConnection queue_conn = tFactory.createQueueConnection();
	    QueueSession queue_session =
	    queue_conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
	    QueueSender queue_sender = queue_session.createSender(q);

	    // Create the message and send.
	    TextMessage message = queue_session.createTextMessage();
	    message.setText("This message is from MDB MessageBeanFirst ");
	    queue_sender.send(message);

	} catch (NameNotFoundException e) {
	    e.printStackTrace();
	}

When I try to send the message, I get the following exception. Please note
that I am able to get a referece to the connection factory and queue from
JNDI:


javax.jms.InvalidDestinationException: Destination is not an instance of
SpyDestination queue://queue.org.apache.activemq.spring.queue
	at org.jboss.mq.SpyMessageProducer.send(SpyMessageProducer.java:232)
	at org.jboss.mq.SpyMessageProducer.send(SpyMessageProducer.java:206)
	at com.activemq.test.SpringTest.testMDB(SpringTest.java:94)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

If I change my code to connect to JNDI using the ActiveMQConnectionFactory
then my code works, i.e., as shown in the thread
http://www.nabble.com/-activemq-user--ActiveMQ-%2B-JNDI-standalone-Client-t186032s2354.html#a524083

I do not understand why I cannot send a message to the JNDI bound queue? If
that is the case I fail to understand what I gain by binding the queue in
JNDI via the MBean.

The Active MQ JNDI documentation states "ActiveMQ will work with any JNDI
provider capable of storing Java objects." 

Any tips would be greatly appreciated. 

-- 
View this message in context: http://www.nabble.com/JBoss-JNDI-assistance-requested.-tf4761941s2354.html#a13619078
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message