我正在尝试编写一个简单的 Java 程序来将 MQ 消息注入队列。我对使用 Java 写入 MQ 队列非常缺乏经验,并且有几个问题。
- 我可以从我的 Windows 机器连接到 unix 机器上的 unix 队列吗?
- 当我尝试运行应用程序时,我得到一个 .... java.lang.UnsatisfiedLinkError: no mqjbnd05 in java.library.path
从我在谷歌中可以找到的声音来看,我缺少某种资源。我在想我可能会收到这个错误,因为我不允许从 Windows 连接到队列?
任何关于如何实现我正在做的事情或帮助的好例子都将不胜感激。
public class MQInject {
private MQQueueManager _queueManager = null;
private Hashtable params = null;
public int port = 1414;
public static final String hostname = "UQMYPOSIS1";
public static final String channel = "MQTX1012.MQTX1013";
public static final String qManager = "MQTX1013";
public static final String outputQName = "IIS.TLOG.5";
public MQInject(){
super();
}
public void init(){
//Set MQ connection credentials to MQ Envorinment.
MQEnvironment.hostname = hostname;
MQEnvironment.channel = channel;
MQEnvironment.port = port;
//MQEnvironment.userID = "";
//QEnvironment.password = password;
//set transport properties.
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
try {
//initialize MQ manager.
_queueManager = new MQQueueManager(qManager);
} catch (MQException e) {
e.printStackTrace();
}
}
public static void main(String[] args)
{
MQInject write = new MQInject();
try
{
write.selectQMgr();
write.write();
}
catch (IllegalArgumentException e)
{
System.out.println("Usage: java MQWrite <-h host> <-p port> <-c channel> <-m QueueManagerName> <-q QueueName>");
System.exit(1);
}
catch (MQException e)
{
System.out.println(e);
System.exit(1);
}
}
private void selectQMgr() throws MQException
{
_queueManager = new MQQueueManager(qManager);
}
private void write() throws MQException{
String line;
int lineNum=0;
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");
System.out.println("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 = "ROGER.QUEUE";
sendmsg.replyToQueueManagerName = qManager;
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults, same
// as MQPMO_DEFAULT constant
while ((line = input.readLine()) != null){
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(++lineNum + ": " + line);
}
queue.close();
_queueManager.disconnect();
}catch (com.ibm.mq.MQException mqex){
System.out.println(mqex);
}
catch (java.io.IOException ioex){
System.out.println("An MQ IO error occurred : " + ioex);
}
}
}