Question

I have run sample JMS application using Jboss 6.

This is hornetq-jms.xml file

<configuration xmlns="urn:hornetq"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">

   <connection-factory name="NettyConnectionFactory">
      <connectors>
         <connector-ref connector-name="netty"/>
      </connectors>
      <entries>
         <entry name="/ConnectionFactory"/>
         <entry name="/XAConnectionFactory"/>
      </entries>
   </connection-factory>

   <connection-factory name="NettyThroughputConnectionFactory">
       <connectors>
         <connector-ref connector-name="netty-throughput"/>
       </connectors>
        <entries>
            <entry name="/ThroughputConnectionFactory"/>
            <entry name="/XAThroughputConnectionFactory"/>
        </entries>
    </connection-factory>

   <connection-factory name="InVMConnectionFactory">
      <connectors>
         <connector-ref connector-name="in-vm"/>
      </connectors>
      <entries>
         <entry name="java:/ConnectionFactory"/>
         <entry name="java:/XAConnectionFactory"/>
      </entries>
   </connection-factory>

   <queue name="DLQ">
      <entry name="/queue/DLQ"/>
   </queue>

   <queue name="ExpiryQueue">
      <entry name="/queue/ExpiryQueue"/>
   </queue>
  <queue name="testQueue">
    <entry name="queue/queueA"/>
  </queue>

  <topic name="testTopic">
    <entry name="/topic/topicA"/>
   </topic>
</configuration>

After that i have run the sample program to send message to jms and got following error message

javax.naming.NameNotFoundException: jms not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:396)
    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:597)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
    at sun.rmi.transport.Transport$1.run(Transport.java:159)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

This is sample program

import java.util.Properties;
import java.util.Scanner;

import javax.jms.*;

import javax.naming.Context;

public class QueueExample implements MessageListener  
{

    public void example() throws Exception
    {
        String destinationName = "queue/queueA";

        Context ic = null;
        ConnectionFactory cf = null;
        Connection connection =  null;

        try
        {         
            ic = getInitialContext();

            cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
            Queue queue = (Queue)ic.lookup(destinationName);

            connection = cf.createConnection();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer publisher = session.createProducer(queue);
            MessageConsumer subscriber = session.createConsumer(queue);

            subscriber.setMessageListener(this);
            connection.start();

            TextMessage message = session.createTextMessage("Hello!");
            publisher.send(message);

            Scanner keyIn = new Scanner(System.in); 

            System.out.print("JMS Server listening. Type a Key + CR to exit\n");
            keyIn.next();

        }
        finally
        {         
            if(ic != null)
            {
                try
                {
                    ic.close();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    //throw e;
                }
            }

            // ALWAYS close your connection in a finally block to avoid leaks.
            // Closing connection also takes care of closing its related objects e.g. sessions.
            closeConnection(connection);
        }
    }
    public synchronized void onMessage(Message message)
    {
        TextMessage text = (TextMessage)message;
        String strMessage = null;
        try {
            strMessage = text.getText();
        } catch (JMSException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("Message received: "+strMessage);
    }

    private void closeConnection(Connection con)
    {      
        try
        {
            if (con != null)
            {
                con.close();
            }         
        }
        catch(JMSException jmse)
        {
            System.out.println("Could not close connection " + con +" exception was " + jmse);
        }
    }

    protected boolean isQueueExample()
    {
        return true;
    }

    public static void main(String[] args) throws Exception
    {
        new QueueExample().example();
    }
    public static Context getInitialContext( )
    throws javax.naming.NamingException {

        Properties p = new Properties( );
        p.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.jnp.interfaces.NamingContextFactory");
        p.put(Context.URL_PKG_PREFIXES,
        " org.jboss.naming:org.jnp.interfaces");
        p.put(Context.SECURITY_PRINCIPAL, "testuser");
        p.put(Context.SECURITY_CREDENTIALS, "test");
        p.put(Context.PROVIDER_URL,"jnp://localhost:1099");
        return new javax.naming.InitialContext(p);
        /*Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        props.put(Context.PROVIDER_URL, "remote://localhost:4447");
        props.put(Context.SECURITY_PRINCIPAL, "testuser");
        props.put(Context.SECURITY_CREDENTIALS, "password");
        InitialContext context = new InitialContext(props);*/
    }  
}

How to resolve this Error? Is there anything wrong for configuration? Please someone help me.

Was it helpful?

Solution

It seems that your program wants to look-up some object from jndi within the path "jms". You may look in JBoss JNDI-tree where your objects are bound. Maybe it is "queueA". I would try to use

String destinationName = "/queue/queueA";

and

<queue name="testQueue">
  <entry name="/queue/queueA"/>
</queue>

instead of "queue/queueA" to put the queue into the global namespace. For the start with JMS i would try a servlet as producer and a MDB as consumer. I think that would be easier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top