2013-04-16 52 views
1

我正在尝试编写一个简单的Java程序来将MQ消息注入到队列中。我对使用Java编写MQ队列非常缺乏经验,并且有几个问题。编写一个简单的应用程序将消息注入到队列中

  1. 我可以从我的Windows机器连接到UNIX机器上的unix队列吗?
  2. 当我尝试运行我得到.... java.lang.UnsatisfiedLinkError中的应用:在的java.library.path

没有mqjbnd05从什么我可以在谷歌找到我的声音缺少某种资源。我想我得到这个错误可能BC我不允许从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); 
     } 
    } 
} 

回答

1

对于你的第一个问题,你可以在UNIX主机上运行一个队列管理器,它由运行在Windows主机上的客户机访问。

对于第二个问题,mqjbnd05库仅用于以绑定模式连接到队列管理器(即,当队列管理器和访问队列的程序位于同一主机上时)并且不是MQ客户机的一部分安装。有关更多详情,请参阅http://www-01.ibm.com/support/docview.wss?uid=swg21158430。仔细查看代码,我可以看到init()函数指定了MQC.TRANSPORT_MQSERIES_CLIENT,但我看不到init()函数正在被调用。也可能需要检查库路径中是否指定了mqjbnd05,如果是这样,请将其删除。

虽然可能与您获取的错误无关,但另一件可能值得检查的事情是通道MQTX1012.MQTX1013是服务器连接通道,而不是发送者或接收者通道。

相关问题