Java program to connect TIBCO JMS Queue:
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Properties;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.google.common.io.Files;
public class test2 {
public static void main(String[] args) throws IOException {
String userName = "<username>;
//String password = "<password>";
try {
String passwordFile = "<password file>";
String password = Files.toString(new File(passwordFile),Charset.forName("UTF-8")).trim();
// Obtain a JNDI connection
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.tibco.tibjms.naming.TibjmsInitialContextFactory");
env.put(Context.PROVIDER_URL, "tcp://<server>:<portno>");
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
InitialContext jndi = new InitialContext(env);
InitialContext initalContext;
ConnectionFactory factory = (ConnectionFactory) jndi.lookup("QueueConnectionFactory");
try {
Connection connection = factory.createConnection(userName,
password);
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue sampleTopic = (Queue) jndi.lookup("<Queue lookup name>");
} catch (JMSException je) {
je.printStackTrace();
}
} catch (NamingException e) {
e.printStackTrace();
}
}
}
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Properties;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.google.common.io.Files;
public class test2 {
public static void main(String[] args) throws IOException {
String userName = "<username>;
//String password = "<password>";
try {
String passwordFile = "<password file>";
String password = Files.toString(new File(passwordFile),Charset.forName("UTF-8")).trim();
// Obtain a JNDI connection
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.tibco.tibjms.naming.TibjmsInitialContextFactory");
env.put(Context.PROVIDER_URL, "tcp://<server>:<portno>");
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
InitialContext jndi = new InitialContext(env);
InitialContext initalContext;
ConnectionFactory factory = (ConnectionFactory) jndi.lookup("QueueConnectionFactory");
try {
Connection connection = factory.createConnection(userName,
password);
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue sampleTopic = (Queue) jndi.lookup("<Queue lookup name>");
} catch (JMSException je) {
je.printStackTrace();
}
} catch (NamingException e) {
e.printStackTrace();
}
}
}
No comments:
Post a Comment