NSApi.JMSKey key = null;
String msg=null;
// Initializes tibco producer with given consumers and connection pool of given pool_size
// It returns a key (LookUp Table Key + Connection Pool Id) which need to be passed for getting connection from the pool
// In case of error, error code of value < 0 is returned and error_msg (max 1014) is set with error message

// JMSKey ns_tibco_init_consumer(tibco_hostname, tibco_port, tibco_use_topic_or_queue, tibco_topic_or_queue, tibco_userId, tibco_password, max_pool_size)
if((key = nsApi.ns_tibco_init_consumer("tcp://127.0.0.1", 7222, "NS_TIBCO_USE_QUEUE", "Queue", "username", "password", 1)) == null)
{
System.out.println("Error in initializing tibco consumer. Issue while initialising Look Up Table or with key insertion in it.");
return 0;
}

//Get connection from the connection pool
//This method will return connection : First check from Free Pool and return, if not found then make a new connection and return it
// In case of error, error code of value < 0 is returned and error_msg (max 1014) is set with error message
// Few possible errors are:
// All connections are busy
// Error in making connection
// If actual connection is made, then transaction is started with name passed if it is not NULL or empty
// If connection fails, then transaction is ended with <TxName>Error<JMSErrorCode>. For example, TIBCOConsumerConnectError2012
if(!nsApi.ns_tibco_get_connection(key, "TIBCOConsumerConnect"))
{
System.out.println("Error in getting tibco connection. Error code = " + key.getErrCode() + ", Error Msg = " + key.getErrMsg());
return 0;
}

//get message in the JMS queue/topic using connection taken using get connection API
//In case of error, error code of value < 0 is returned and error_msg (max 1014) is set with error message
// Few possible errors are:
// Connection closed by JMS server
// Invalid connection ID passed
// Transaction is started with name passed if it is not NULL or empty
// If get fails, then transaction is ended with <TxName>Error<JMSErrorCode>. For example, TIBCOPutMsgError2012
if((msg = nsApi.ns_tibco_get_msg(key, "TIBCOGetMsg")) == null)
{
System.out.println("Error in Getting message using Tibco connection. Error code = " + key.getErrCode() + ", Error Msg = " + key.getErrMsg() + "\n");
}

//This will release the working Connection.
//It Implies moving a Connection from Running state to Ready State (Busy -> Free)
if(!nsApi.ns_tibco_release_connection(key))
{
System.out.println("Error in Releasing tibco connection. Error code = " + key.getErrCode() + ", Error Msg = " + key.getErrMsg() + "\n");
return 0;
}

/*
//This API will close the active connection (Free/Busy -> Closed)
if(!nsApi.ns_tibco_close_connection(key, "TIBCOConsumerClose"))        {
System.out.println("Error in closing tibco connection. Key = " + key.getKeyMain() + " - " + key.getIdPool() + "\n");
return 0;
}

*/

// Page think time in case of adding delay for next session
nsApi.ns_page_think_time(0.0);
