Skip to content

Instantly share code, notes, and snippets.

@coding-yogi
Created May 2, 2019 06:52
Show Gist options
  • Save coding-yogi/b6cf1b4f009929c56a11c15722fe3af1 to your computer and use it in GitHub Desktop.
Save coding-yogi/b6cf1b4f009929c56a11c15722fe3af1 to your computer and use it in GitHub Desktop.
final String queueManagerName = "manager";
final String queueName = "DEV.QUEUE.1";
final String channelName = "DEV.APP.SVRCONN";
//final String replyQueue = "";
final String host = "10.23.142.85";
final int port = 1414;
//MQ Properties
Hashtable<String, Object> props = new Hashtable<>();
props.put(MQConstants.HOST_NAME_PROPERTY, host);
props.put(MQConstants.PORT_PROPERTY, port);
props.put(MQConstants.CHANNEL_PROPERTY, channelName);
MQQueueManager queueManager = new MQQueueManager(queueManagerName, props); //QUEUE Manager
int openOptions = MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INPUT_AS_Q_DEF;
MQQueue queue = queueManager.accessQueue(queueName, openOptions); //INCOMING QUEUE
//Put a message in the queue
String messagePayload = "This is a test message";
MQMessage outgoingMessage = new MQMessage();
outgoingMessage.writeString(messagePayload);
queue.put(outgoingMessage);
//read the message
MQGetMessageOptions getOptions = new MQGetMessageOptions();
getOptions.options = MQConstants.MQGMO_CONVERT;
MQMessage incomingMessage = new MQMessage();
queue.get(incomingMessage, getOptions);
String expectedMessagePayload = incomingMessage.readStringOfByteLength(incomingMessage.getMessageLength());
Assert.assertEquals(messagePayload, expectedMessagePayload + "test");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment