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?
Typically you would use JNDI to lookup both the
javax.jms.ConnectionFactoryand thejavax.jms.Destination(i.e.javax.jms.Queueorjavax.jms.Topic). This would involve instantiating ajavax.naming.InitialContextwith a set of properties for whatever specific implementation you're using and then using thatjavax.naming.InitialContextto perform a lookup.However, you're not actually using JNDI at all. You're instantiating the JMS
ConnectionFactorydirectly (i.e. usingnew progress.message.jclient.ConnectionFactory(...)) and later callingjavax.jms.Session.createQueue(...)to instantiate the localjavax.jms.Queue.Keep in mind that using
javax.jms.Session.createQueue(...)to instantiate the localjavax.jms.Queuehas no impact on the JMS server. As the JavaDoc notes:The reason you're getting an
InvalidDestinationExceptionis 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 tocreateQueueto match a queue that already exists.