I am inserting messages in a queue using WebSphere MQ tool using java code. While entering the text it will store the message in the queue. I want to validate while inserting messages whether
1.the queue exists or not
2.Is there any channel error
3.Port number mismatch
4.host address error
I want to capture these errors and store it in a text file with time stamp and service in error log.
Help me how to do it.
Menu insertion of messages in queue
Menu based insertion of messages in queue
Message inserted in Websphere MQ
public class QueueMessage { public static Scanner sc = new Scanner(System.in);
private MQQueueManager _queueManager = null;
public int port = 1413;
public String hostname = "192.168.100.120";
public String channel = "QM_HOME.Q_LOCAL";
public String qManager = "QM_HOME";
public String inputQName = "Q_LOCAL_END";
public String outputQName = "Q_LOCAL_END";
public QueueMessage()
{
super();
}
public void init(String[] args) throws IllegalArgumentException
{
// Set up MQ environment
MQEnvironment.hostname = hostname;
System.out.println("HOST :"+hostname);
MQEnvironment.channel = channel;
MQEnvironment.port = port;
System.out.println("init");
}
public void selectQMgr() throws MQException
{
_queueManager = new MQQueueManager(qManager);
}
public void write() throws MQException {
int openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
try {
MQQueue queue = _queueManager.accessQueue(outputQName, openOptions,
null, // default q manager
null, // no dynamic q name
null); // no alternate user id
DataInputStream input = new DataInputStream(System.in);
System.out
.println("MQWrite v1.0 connected and ready for input, terminate with ^Znn");
// Define a simple MQ message, and write some text in UTF format..
MQMessage sendmsg = new MQMessage();
sendmsg.format = MQC.MQFMT_STRING;
sendmsg.feedback = MQC.MQFB_NONE;
sendmsg.messageType = MQC.MQMT_DATAGRAM;
sendmsg.replyToQueueName = "QM_LOCAL_END";
sendmsg.replyToQueueManagerName = qManager;
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the
String line = null;
System.out.print("Enter your Message: ");
line = sc.nextLine();
sendmsg.clearMessage();
sendmsg.messageId = MQC.MQMI_NONE;
sendmsg.correlationId = MQC.MQCI_NONE;
sendmsg.writeString(line);
// put the message on the queue
queue.put(sendmsg, pmo);
System.out.println("Message inserted: " + line);
queue.close();
_queueManager.disconnect();
// same
// as MQPMO_DEFAULT constant
}
catch (com.ibm.mq.MQException mqex) {
System.out.println(mqex);
} catch (java.io.IOException ioex) {
System.out.println("An MQ IO error occurred : " + ioex);
}
}
private void While(boolean b) {
// TODO Auto-generated method stub
}
}
Aucun commentaire:
Enregistrer un commentaire