NSApi.JMSKey key = null;

String msg=null;
// Initializes IBMMQ consumer with given parameters 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_ibmmq_init_consumer(ibmmq_hostname, ibmmq_port, queue_manager, channel, ibmmq_queue, ibmmq_userId, ibmmq_password, max_pool_size)
if((key = nsApi.ns_ibmmq_init_consumer("127.0.0.1", 1414, "queue manager", "channel", "queue", "username", "", 1)) == null)
{
System.out.println("Error in initializing ibmmq producer. 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, IBMMQConsumerConnectError2012
if(!nsApi.ns_ibmmq_get_connection(key, "IBMMQConsumerConnect"))
{
System.out.println("Error in getting IBMMQ connection. Error code = " + key.getErrCode() + ", Error Msg = " + key.getErrMsg() + "\n");
return 0;
}

// Get message from 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, IBMMQGetMsgError2012

if((msg = nsApi.ns_ibmmq_get_msg(key, "IBMMQGetMsg")) == null)
{
System.out.println("Error in Getting message using IBMMQ connention. 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_ibmmq_release_connection(key))
{
System.out.println("Error in releasing IBMMQ 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_ibmmq_close_connection(key, "IBMMQConsumerClose"))
{
System.out.println("Error in closing Ibmmq 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);
