Reputation: 868
I am trying to publish a simple message to ibmmq using java.The message sending is successful.But when i check the queue on ibm console .The Message is showed as
But I am expecting as simple String.
Here is my code.when I am trying to convert I am getting below message The message of type jms_bytes can not have its body assigned to java.lang.String
import com.ibm.mq.*;
import com.ibm.mq.constants.MQConstants;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.msg.client.jms.JmsFactoryFactory;
import com.ibm.msg.client.wmq.WMQConstants;
import javax.jms.*;
import java.io.IOException;
import java.util.Hashtable;
public class PublisherTest
{
static private String CHANNEL = "anychannel";
static private int PORT = 1414;
static private String HOST = localhost;
static private String QMANAGER = "QM1";
static private String QUEUE = "queue.test";
static private String USER = USER;
static private Hashtable<String, Object> props =
new Hashtable<String, Object>();
static MQQueueManager qMgr = null;
static private void putMsgOnQueue(String message) {
// Disabling IBM cipher suite mapping due to
// using Oracle Java and not IBM Java
System.setProperty("com.ibm.mq.cfg.useIBMCipherMappings", "false");
// Enabling SSL debug to view the communication
System.setProperty("javax.net.debug", "ssl:handshake");
props.put(MQConstants.CHANNEL_PROPERTY, CHANNEL);
props.put(MQConstants.PORT_PROPERTY, PORT);
props.put(MQConstants.HOST_NAME_PROPERTY, HOST);
props.put(MQConstants.USER_ID_PROPERTY, USER);
props.put(MQConstants.PASSWORD_PROPERTY, PASSWORD);
props.put(MQConstants.SSL_CIPHER_SUITE_PROPERTY, "TLS_RSA_WITH_AES_256_CBC_SHA256");
try {
qMgr = new MQQueueManager(QMANAGER, props);
// MQOO_OUTPUT = Open the queue to put messages
// MQOO_INPUT_AS_Q_DEF = Using queue-defined defaults
int openOptions = MQConstants.MQOO_OUTPUT;
// creating destination
MQQueue queue = qMgr.accessQueue(QUEUE, openOptions);
// specify the message options...
MQPutMessageOptions pmo = new MQPutMessageOptions(); // Default
// MQPMO_ASYNC_RESPONSE = MQPUT operation is completed without the
// application waiting for the queue manager to complete the call
// Using this option can improve messaging performance,
// particularly for applications using client bindings.
pmo.options = MQConstants.MQPMO_ASYNC_RESPONSE;
// create message
MQMessage mqMessage = new MQMessage();
System.out.println("Writing message to queue: " + QUEUE);
mqMessage.writeString(message.toString());
// Put message on queue
queue.put(mqMessage, pmo);
// Close queue
queue.close();
// Get status
MQAsyncStatus asyncStatus = qMgr.getAsyncStatus();
// Print status code (0 = successful)
System.out.println(asyncStatus.reasonCode);
} catch (MQException e) {
System.out.println("The connection to MQ could not be established." + e.getMessage());
} catch (IOException e) {
System.out.println("Error while writing message." +
e.getMessage());
} finally {
try {
qMgr.disconnect();
} catch (MQException e) {
System.out.println("The connection could not be closed." +
e.getMessage());
}
}
}
public static void main(String[] args) {
putMsgOnQueue("WELCOME");
}
}
ANY Help Would be Appreciated.
Upvotes: 2
Views: 2395
Reputation: 15273
The default message format is MQFMT_NONE. This means the message body consists of bytes. Your code is not setting message format. So my thinking is that MQ Console is indicating such messages as binary.
Suggest you set the message format as string and run. This sets the message format as string.
MQMessage mqMessage = new MQMessage();
mqMessage.format = MQConstants.MQFMT_STRING;
Upvotes: 6