1
votes

I have written a piece of code to connect to TIBCO queue and fetch customer data. But I cannot find a way to test it before moving it to production. Can we create a dummy queue somehow so that I can ensure that my program is functional before packaging it for production?

Here is my code..

    package GI;

import javax.jms.JMSSecurityException;
import javax.naming.InitialContext;

import javax.jms.Queue;
import javax.jms.TextMessage;
import javax.jms.QueueSender;
import javax.jms.DeliveryMode;
import javax.jms.QueueSession;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;

public class Queue
{
    public Queue()
    {
        System.err.println("\n------------------------------------------------------------------------");
        System.err.println("tibjmsTEQueue SAMPLE");
        System.err.println("------------------------------------------------------------------------");
    }

    public String QueueProcess(String XMLRequest, String serverUrl, String userName, String password, String InQueueName)
    {
        String [] args = new String[4];

        args[0]=serverUrl;
        args[1]=userName;
        args[2]=password;
        args[3]=InQueueName;

        System.out.println("Server....................... "+serverUrl);
        System.out.println("User......................... "+userName);
        System.out.println("InQueue...................... "+InQueueName);
        System.out.println("------------------------------------------------------------------------\n");

        try
        {
            tibjmsUtilities.initSSLParams(serverUrl,args);
        }
        catch (JMSSecurityException e)
        {
            System.err.println("JMSSecurityException: "+e.getMessage()+", provider="+e.getErrorCode());
            e.printStackTrace();
            System.exit(0);
        }

        System.err.println("Starting");

        QueueConnection connectionIn = null;
        try
        {
            InitialContext context = new InitialContext();

            Queue tibcoQueue = (Queue) context.lookup("queue/queue0");

            QueueConnectionFactory factory = new com.tibco.tibjms.TibjmsQueueConnectionFactory(serverUrl);
            connectionIn = factory.createQueueConnection(userName, password);
            QueueSession sessionIn = connectionIn.createQueueSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);

            QueueSender queueSender = sessionIn.createSender(tibcoQueue);
            queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            QueueReceiver queueReceiver = sessionIn.createReceiver(tibcoQueue);

            connectionIn.start();

            System.out.println("Connected to Queue...");
            System.out.println("XMLRequest: " + XMLRequest);

            TextMessage sendXMLRequest = sessionIn.createTextMessage(XMLRequest);

            queueSender.send(sendXMLRequest);

            System.out.println("sent: " + sendXMLRequest.getText());

            TextMessage XMLResponse = (TextMessage) queueReceiver.receive();

            System.out.println("received: " + XMLResponse.getText());
            return((String) XMLResponse.getText());
        }
        catch(Exception e)
        {
            System.err.println("Exitting with Error");
            e.printStackTrace();
            System.exit(0);
        }
        finally
        {
            System.err.println("Exitting");
            try                 {connectionIn.close();}
            catch(Exception e1) {}
        }

        return("Failure");
    }

    public static void main(String args[])
    {
        Queue t = new Queue();
    }
}
1

1 Answers

0
votes

It is never suggested to mix production and non-production traffic on the same EMS messaging instance. That is a very risky practice since it introduces the possibility of inadvertently sending non-production traffic to production applications. I would suggest first checking with your EMS operations team as they can likely point you to a development EMS instance that you can use.

For unit and/or integration testing where you are not looking to stress-test the environment, many developers install an instance of EMS on their local development workstation. Again your EMS operations team may be able to provide you with a license and installation binary to install locally.