gpt4 book ai didi

java - 验证队列消息

转载 作者:行者123 更新时间:2023-12-01 09:47:35 32 4
gpt4 key购买 nike

我正在使用 Java 代码使用 WebSphere MQ 工具将消息插入队列中。输入文本时,它将把消息存储在队列中。我想在插入消息时验证是否

1.队列是否存在

2. channel 是否有错误

3.端口号不匹配

4.主机地址错误

我想捕获这些错误并将其存储在一个文本文件中,并在错误日志中包含时间戳和服务。

帮我看看该怎么做。

队列中消息的菜单插入

Menu based insertion of messages in queue

Message inserted in Websphere MQ

公共(public)类QueueMessage{ 公共(public)静态扫描器 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 ^Z\n\n");
// 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

}

}

最佳答案

using java code

标准 Java 编码 - 您只需捕获 MQException。

try
{
_qMgr = new MQQueueManager(qMgrName, myHashTable);
}
catch (MQException e)
{
System.err.println("Completion Code=" + e.completionCode + " Reason Code=" + e.reasonCode);
}

有关 MQ 的所有内容都记录在 MQ Knowledge Center 中。所有 MQ/Java 类均已记录 - 即 MQQueueManager class

要记住的第一条规则是对象名称(队列、 channel 等)区分大小写。规则 #2 是 MQ 不是数据库。规则 #3,确保您的应用程序记录所有“异常”。

1.the queue exists or not

原因代码 2085 (MQRC_UNKNOWN_OBJECT_NAME)

2.Is there any channel error

2009 年的原因代码 (MQRC_CONNECTION_BROKEN)

3.Port number mismatch

原因代码 2059 (MQRC_Q_MGR_NOT_AVAILABLE)

4.host address error

原因代码 2538 (MQRC_HOST_NOT_AVAILABLE)

关于java - 验证队列消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37860613/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com