Actually we are using tibco queue and MessageListener to listen the message from Queue but same message processed multiple times below is my logic.
if (jndiProviderUrl.indexOf("ssl://") >= 0) {
env.put(Context.SECURITY_PRINCIPAL, jndiSecurityPrincipal);
if (queueConnectionFactorynamePassword != null)
env.put(TibjmsContext.SSL_TRUSTED_CERTIFICATES, sslTrustedStore);
if (tmpdir != null) {
if (sslPassword == null) {
System.err.println("Error: SSL Password Error");
System.exit(-1);
}
env.put(TibjmsContext.SSL_IDENTITY, tmpdir);
env.put(TibjmsContext.SSL_PASSWORD, sslPassword);
env.put("com.tibco.tibjms.ssl.password", sslPassword);
}
env.put(TibjmsContext.SSL_ENABLE_VERIFY_HOST, new Boolean(false));
env.put(TibjmsContext.SECURITY_PROTOCOL, "ssl");
env.put(TibjmsContext.SSL_CIPHER_SUITES, "DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA");
com.tibco.tibjms.TibjmsSSL.setSecureRandom(createUnsecureRandom());
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.tibco.tibjms.naming.TibjmsInitialContextFactory");
env.put(Context.PROVIDER_URL, jndiProviderUrl);
env.put(Context.PROVIDER_URL, jndiProviderUrl);
InitialContext jndiContext = new InitialContext(env);
/*
* Lookup queue connection factory which must exist in the factories
* configuration file.
*/
QueueConnectionFactory queueFactory = (QueueConnectionFactory) jndiContext.lookup(queueConnectionFactoryName);
System.err.println("OK - successfully did lookup of " + queueConnectionFactoryName + ", " + queueFactory);
/*
* Lookup queue, which must exist in the queues configuration file of JNDI and
* broker, if not successful then it is most likely that such queue does not
* exist in the configuration files
*/
javax.jms.Queue sampleQueue = null;
try {
sampleQueue = (javax.jms.Queue) jndiContext.lookup(jndiQueueName);
System.err.println("OK - successfully did lookup queue '" + jndiQueueName + "'");
} catch (NamingException ne) {
System.err.println("**NamingException occurred while lookup the queue" + jndiQueueName);
System.err.println(" Most likely such queue does not exist in your configuration.");
System.err.println(" Exception message follows:");
System.err.println(ne.getMessage());
System.exit(0);
}
/*
* Let's create a queue connection to the server and a session to verify the
* server is running so we can continue with our lookup operations.
*/
QueueConnection queueConnection = null;
QueueSession queueSession = null;
MessageConsumer msgConsumer = null;
try {
if (jndiProviderUrl.indexOf("ssl://") >= 0) {
/*
* Set the password key for the keystore returned by the JNDI
*/
char[] sslpassword = ssl_keypass.toCharArray();
com.tibco.tibjms.TibjmsSSL.setPassword(sslpassword);
queueConnection = queueFactory.createQueueConnection();
}
queueSession = queueConnection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
/*
* Starting an asynchronous queue subscriber
*/
System.err.println("Subscribing to Queue: " + jndiQueueName + "'\n");
msgNumber = 0;
catejmsjndiQueueListenerClient.Subscriber(queueConnection, queueSession, sampleQueue, msgConsumer);
public void Subscriber(Connection subsConnection, Session subsSession, Destination destination, MessageConsumer msgConsumer)
{
try {
/*
* Creates the consumer
*/
msgConsumer = subsSession.createConsumer(destination);
/*
* Set the message listener
*/
msgConsumer.setMessageListener(this);
/*
* Start the connection
*/
subsConnection.start();
}
catch(Exception e)
{
e.printStackTrace();
}
}
Listener code :
MessageListener:
public void onMessage(Message msg)
{
try
{
if (msg instanceof TextMessage) {
String orderResponse = ((TextMessage) msg).getText();
storeOrderService.convertXmlintoObject(orderResponse);
msg.acknowledge();
}
}
catch(Exception e)
{
System.err.println("Unexpected exception in the message callback!");
e.printStackTrace();
System.exit(-1);
}
}
Please provide any thing wrong i did?