0

I am able to run the below Java code to send a message to SonicMQ JMS queue. It is copied from here:

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;


public class JmsClient
{
    public static void main(String[] args) throws JMSException
    {
        ConnectionFactory factory = new progress.message.jclient.ConnectionFactory("tcp://<host>:<port>", "<user>", "<password>");
        Connection connection = factory.createConnection();

        try
        {
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            try
            {
                MessageProducer producer = session.createProducer(session.createQueue("<queue>"));
                try
                {
                    producer.send(session.createTextMessage("<message body>"));
                }
                finally
                {
                    producer.close();
                }
            }
            finally
            {
                session.close();
            }
        }
        finally
        {
            connection.close();
        }
    }
}

However, I get error:

javax.jms.InvalidDestinationException: Queue not found

I think this is because I need to specify queue "Domain Name." Where to put "Domain Name" in this code?

As stated here the following JNDI parameter should be set:

sonicsw.jndi.mfcontext.domain=[Domain_Name]

How to set JNDI parameter in the code above?

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
aaa
  • 118
  • 1
  • 7

1 Answers1

0

Typically you would use JNDI to lookup both the javax.jms.ConnectionFactory and the javax.jms.Destination (i.e. javax.jms.Queue or javax.jms.Topic). This would involve instantiating a javax.naming.InitialContext with a set of properties for whatever specific implementation you're using and then using that javax.naming.InitialContext to perform a lookup.

However, you're not actually using JNDI at all. You're instantiating the JMS ConnectionFactory directly (i.e. using new progress.message.jclient.ConnectionFactory(...)) and later calling javax.jms.Session.createQueue(...) to instantiate the local javax.jms.Queue.

Keep in mind that using javax.jms.Session.createQueue(...) to instantiate the local javax.jms.Queue has no impact on the JMS server. As the JavaDoc notes:

Note that this method simply creates an object that encapsulates the name of a queue. It does not create the physical queue in the JMS provider. JMS does not provide a method to create the physical queue, since this would be specific to a given JMS provider. Creating a physical queue is provider-specific and is typically an administrative task performed by an administrator, though some providers may create them automatically when needed.

The reason you're getting an InvalidDestinationException is because the queue you're trying to use does not exist on the JMS server. You need to administratively create that destination or change the name you're passing to createQueue to match a queue that already exists.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43