I am using this class to connect to an IBM MQ container i am running locally:
package com.tsdevelopment.spring_boot_ibmmq_producer;
import com.ibm.mq.MQException;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.CMQC;
import org.springframework.stereotype.Service;
import java.io.IOException;
@Service
public class IBMMQProducer {
public void sendMessage(RequestPayload requestPayload) throws MQException, IOException {
MQQueueManager queueManager = null;
try {
// Set up MQ environment
com.ibm.mq.MQEnvironment.hostname = "localhost";
com.ibm.mq.MQEnvironment.port = 1414;
com.ibm.mq.MQEnvironment.channel = "TSCHANNEL";
com.ibm.mq.MQEnvironment.userID = "mqm";
com.ibm.mq.MQEnvironment.password = "pass";
// Create a connection to the queue manager
queueManager = new MQQueueManager("TS_IBMMQ_MANAGER");
// Specify the queue that you want to open
int openOptions = CMQC.MQOO_OUTPUT;
MQQueue queue = queueManager.accessQueue("TS_QUEUE", openOptions);
// Create a message
com.ibm.mq.MQMessage mqMessage = new com.ibm.mq.MQMessage();
mqMessage.writeString(requestPayload.getRequestField());
// Specify the message options
com.ibm.mq.MQPutMessageOptions pmo = new com.ibm.mq.MQPutMessageOptions();
// Put the message on the queue
queue.put(mqMessage, pmo);
// Close the queue
queue.close();
} finally {
// Disconnect from the queue manager
if (queueManager != null) {
queueManager.disconnect();
}
}
}
}
I have run the following commands in the container to create the channel and the queue:
echo "DEFINE CHANNEL(TSCHANNEL) CHLTYPE(SVRCONN) TRPTYPE(TCP) REPLACE" | runmqsc TS_IBMMQ_MANAGER
echo "DEFINE QLOCAL(TS_QUEUE)" | runmqsc TS_IBMMQ_MANAGER
But when i try to connect i get the aforementioned error. Is this an MQ conf issue or something wrong with my client?
2035 is MQRC_NOT_AUTHORIZED
The MQ logs will contain more detailed information on what is being accessed and why it is not authorised, but what you will be missing is the MQSC commands to authorise the mqm
user to access TSCHANNEL
and TS_QUEUE
.
If you use the MQ advanced developer image you get all this defined for the app
user on DEV.*
objects. IE.
SET CHLAUTH('DEV.APP.SVRCONN') TYPE(ADDRESSMAP) ADDRESS('*') USERSRC(CHANNEL) CHCKCLNT({{ .ChckClnt }}) DESCR('Allows connection via APP channel') ACTION(REPLACE)
and
SET AUTHREC PROFILE('DEV.**') PRINCIPAL('app') OBJTYPE(QUEUE) AUTHADD(BROWSE,GET,INQ,PUT)
See the mqadvanced-server-dev container repo for the full dev MQSC.