int jpid;                              //JMS Pool Id
int jcid;                              //JMS Connection Id
char header[1024];                     //message to be recieved
int header_len = 1024;                 //message length
char error_msg[1024 + 1];              // Error string. Must be 1024 size
int ret;                               // Error code
int msg_len = 1024;
char msg[1024 + 1];        // Initialize Tibco consumer with given parameters and connection pool of pool_size
// It returns JMS 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
// (int ns_tibco_init_consumer(tibco_hostname, tibco_port, tibco_topic_or_queue, topic/queue_name, tibco_userId, tibco_password, max_pool_size))
if((jpid = ns_tibco_init_consumer("tcp://127.0.0.1", 7222, 1, "topic", "username", "password", 1,error_msg)) < 0)
{
fprintf(stderr, "Error in initializing Tibco consumer. Error code = %d, Error Msg = %s", jpid, error_msg);
return;
}

// Get connection from the connection pool.
// This method will return connection is free or make 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((jcid = ns_tibco_get_connection(jpid, "TIBCOConsumerConnect", error_msg)) < 0)
{
fprintf(stderr, "Error in getting Tibco connention. Error code = %d, Error Msg = %s", jcid, error_msg);
return;
}

// Get message from 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 put fails, then transaction is ended with <TxName>Error<JMSErrorCode>. For example, TIBCOGetMsgError2012

if((ret = ns_tibco_get_msg(jcid, msg, msg_len, header, header_len, "TIBCOGetMsg", error_msg)) < 0)
{
fprintf(stderr, "Error in getting message using Tibco connention. Error code = %d, Error Msg = %s", ret, error_msg);
}

//This api will release the  connection from connection pool and it should be called every time so that another user can reuse it.
if((ret = ns_tibco_release_connection(jcid, error_msg)) < 0)
{
fprintf(stderr, "Error in releasing Tibco connection.Error code = %d, Error Msg = %s", ret, error_msg);
return;
}

/*
//This api will close connection with Tibco server and it should not be called every time as it will impact performance. It should be called at the end of test.
if((ret = ns_tibco_close_connection(jcid, "TIBCOConsumerClose" , error_msg)) < 0)
{
fprintf(stderr, "Error in closing Tibco  connection %d", ret);
return;
}

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