Java Client to publish message in tibco queue

TIBCO Enterprise Message Service is a standards-based messaging platform (fully TCK certified to both the JMS 1.1 and 2.0 standards) that simplifies and accelerates the integration and management of data distribution in high-performance, enterprise environments.(Source: Wiki). In this post we will create a Java client which publishes message in Tiibco Queue.

1. Create a Maven project and add following dependencies in pom.xml.
<dependencies>
    <!-- https://mvnrepository.com/artifact/javax.jms/javax.jms-api -->
    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>jms</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>tibco.jms</groupId>
        <artifactId>tibco_jms</artifactId>
        <version>6.1</version>
    </dependency>
</dependencies> 

2. Create a Java class TibcoQueue which manages tibco queue details.
/**
 * @author www.devinline.com(nikhil)
 *
 */
public class TibcoQueue {
 private String tibcoInstance;
 private String tibcoQueueName;
 private String userName;
 private String passWord;

 /**
  * @param tibcoInstance
  * @param tibcoQueueName
  * @param userName
  * @param passWord
  */
 public TibcoQueue(String tibcoInstance, String tibcoQueueName, 
   String userName, String passWord) {
  this.tibcoInstance = tibcoInstance;
  this.tibcoQueueName = tibcoQueueName;
  this.userName = userName;
  this.passWord = passWord;
 }

 public String getTibcoInstance() {
  return tibcoInstance;
 }

 public void setTibcoInstance(String tibcoInstance) {
  this.tibcoInstance = tibcoInstance;
 }

 public String getTibcoQueueName() {
  return tibcoQueueName;
 }

 public void setTibcoQueueName(String tibcoQueueName) {
  this.tibcoQueueName = tibcoQueueName;
 }

 public String getUserName() {
  return userName;
 }

 public void setUserName(String userName) {
  this.userName = userName;
 }

 public String getPassWord() {
  return passWord;
 }

 public void setPassWord(String passWord) {
  this.passWord = passWord;
 }
}

3. Create a Java class which does all configuration and send message to queue.
import java.util.List;

import javax.jms.DeliveryMode;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;

import com.tibco.tibjms.TibjmsQueueConnectionFactory;

/**
 * @author www.devinline.com (nikhil)
 *
 */

public class TibcoQueueUtils {
 private QueueConnection queueConnection;
 private QueueSession queueSession;
 private Queue sendQueue;
 private MessageProducer messageProducer;

 private void configureTibcoConnection(TibcoQueue tibcoQueue) throws Exception {
  QueueConnectionFactory queueConnectionFactory = 
    new TibjmsQueueConnectionFactory(tibcoQueue.getTibcoInstance());
  queueConnection = queueConnectionFactory.createQueueConnection(tibcoQueue.getUserName(),
    tibcoQueue.getPassWord());
  queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
  sendQueue = queueSession.createQueue(tibcoQueue.getTibcoQueueName());
 }

 private void configureProducer(TibcoQueue tibcoQueue) throws Exception {
  configureTibcoConnection(tibcoQueue);
  messageProducer = queueSession.createProducer(sendQueue);
  messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
  queueConnection.start();
 }

 private void closeProducer() throws Exception {
  messageProducer.close();
  closeTibcoConnection();
 }

 private void closeTibcoConnection() throws Exception {
  queueSession.close();
  queueConnection.stop();
  queueConnection.close();
 }

 public synchronized void sendMessage(String messageText, 
   TibcoQueue tibcoQueue) throws Exception {
  configureProducer(tibcoQueue);
  TextMessage message = queueSession.createTextMessage(messageText);
  messageProducer.send(message);
  closeProducer();
 }

 public synchronized void sendMessages(List<String> messageTexts, 
   TibcoQueue tibcoQueue) throws Exception {
  messageTexts.forEach(messageText -> {
   try {
    sendMessage(messageText, tibcoQueue);
   } catch (Exception e) {
    e.printStackTrace();
   }
  });
 }
}

4. Create Java class with main method which executes sendMessage() method and initiates message sending to queue.
import com.devinline.jms.tibco.utils.TibcoQueue;
import com.devinline.jms.utils.JMSConstants;
import com.devinline.jms.tibco.utils.TibcoQueueUtils;
/**
 * @author www.devinline.com (nikhil)
 *
 */
public class TibcoQueueClientPublisher {
 public static void main(String[] args) throws Exception {
  String message = "{\"order\":{\"orderNo\":\"XYZ1234\",\"status\":\"COMPLETED\"}}";
  /**/
  TibcoQueue tibcoQueue = new TibcoQueue(
    JMSConstants.BROKER_URL, 
    JMSConstants.QUEUE_NAME,
    JMSConstants.QUEUE_USERNAME, 
    JMSConstants.QUEUE_PASSWORD);
  
  TibcoQueueUtils queueUtil = new TibcoQueueUtils();
  System.out.println("Sending message");
  queueUtil.sendMessage(message,tibcoQueue);
  System.out.println("Message sent successfully!!");
 }
}

Note: Create JMSConstants class with fields broker_url, queueName, username and password and use it in above class accordingly.

3 Comments

  1. do you have any example using SSL certificates

    ReplyDelete
  2. These bets don't involve specific numbers and are made on the outside of the number map, therefore the name. Whether you're a global advert company or a freelance graphic designer, we have the vector graphics to make your project come to life. The numbers don’t necessarily need to be subsequent to each other|to one another}. However, as a result of} design of the number 카지노사이트 grid, there are limits to what have the ability to|you presumably can} bid on. With a excessive or low wager, have the ability to|you presumably can} wager on both the lower or upper half of the Roulette wheel. The low wager covers 1 – 18, while the excessive wager covers 19 – 36.

    ReplyDelete
Previous Post Next Post