NSApi.JMSKey key = null;

String msgToBeProduce =  "IBMMQ Producer" ; //User Given input is shown here

// Initializes IBMMQ producer 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_producer(ibmmq_hostname, ibmmq_port, queue_manager, channel, ibmmq_queue, ibmmq_userId, ibmmq_password, max_pool_size)
if((key = nsApi.ns_ibmmq_init_producer("127.0.0.1", 1414, "manager", "channel", "queue", "username", "password", 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, IBMMIBMMQucerConnectError2012
if(!nsApi.ns_ibmmq_get_connection(key,"IBMMQProducerConnect"))
{
System.out.println("Error in getting IBMMQ connection. Error code = " + key.getErrCode() + ", Error Msg = " + key.getErrMsg() + "\n"); 
return 0; 
}


// Put 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 put fails, then transaction is ended with <TxName>Error<JMSErrorCode>. For example, IBMMQPutMsgError2012
if(!nsApi.ns_ibmmq_put_msg(key,  msgToBeProduce, "IBMMQPutMsg"))
{
System.out.println("Error in Putting message using IBMMQ 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_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, "IBMMQProducerClose"))        {
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);
