2016-06-13 14 views
1

次のようにjavaクラスを使用してIBM MQクライアントを実装しています。com.ibm.msg.client.wmq.WMQConstantsは解決できません

import javax.jms.JMSException; 

     import com.ibm.msg.client.jms.JmsConnectionFactory; 
     import com.ibm.msg.client.jms.JmsFactoryFactory; 
     import com.ibm.msg.client.wmq.WMQConstants; 

     import javax.jms.JMSContext; 
     import javax.jms.Topic; 
     import javax.jms.Queue; 
     import javax.jms.JMSConsumer; 
     import javax.jms.Message; 
     import javax.jms.JMSProducer; 

    /* 
    * Implements both Subscriber and Publisher 
    */ 
    class SharedNonDurableSubscriberAndPublisher implements Runnable { 
    private Thread t; 
    private String threadName; 

    SharedNonDurableSubscriberAndPublisher(String name){ 
     threadName = name; 
     System.out.println("Creating Thread:" + threadName); 
    } 

    /* 
    * Demonstrates shared non-durable subscription in JMS 2.0 
    */ 
    private void sharedNonDurableSubscriptionDemo(){ 
     JmsConnectionFactory cf = null; 
     JMSContext msgContext = null; 

     try { 
      // Create Factory for WMQ JMS provider 
      JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER); 
      // Create connection factory 
      cf = ff.createConnectionFactory(); 
      // Set MQ properties 
      cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "QM3"); 
      cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_BINDINGS); 
      // Create message context 
      msgContext = cf.createContext(); 

      // Create a topic destination 
      Topic fifaScores = msgContext.createTopic("/FIFA2014/UPDATES"); 

      // Create a consumer. Subscription name specified, required for sharing of subscription. 
      JMSConsumer msgCons = msgContext.createSharedConsumer(fifaScores, "FIFA2014SUBID"); 

      // Loop around to receive publications 
      while(true){ 

       String msgBody=null; 

       // Use JMS 2.0 receiveBody method as we are interested in message body only. 
       msgBody = msgCons.receiveBody(String.class); 

       if(msgBody != null){ 
        System.out.println(threadName + " : " + msgBody); 
       } 
      } 
     }catch(JMSException jmsEx){ 
      System.out.println(jmsEx); 
     } 
    } 

    /* 
    * Publisher publishes match updates like current attendance in the stadium, goal score and ball possession by teams. 
    */ 
    private void matchUpdatePublisher(){ 
     JmsConnectionFactory cf = null; 
     JMSContext msgContext = null; 
     int nederlandsGoals = 0; 
     int chileGoals = 0; 
     int stadiumAttendence = 23231; 
     int switchIndex = 0; 
     String msgBody = ""; 
     int nederlandsHolding = 60; 
     int chileHolding = 40; 

     try { 
      // Create Factory for WMQ JMS provider 
      JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER); 

      // Create connection factory 
      cf = ff.createConnectionFactory(); 
      // Set MQ properties 
      cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "QM3"); 
      cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_BINDINGS); 

      // Create message context 
      msgContext = cf.createContext(); 

      // Create a topic destination 
      Topic fifaScores = msgContext.createTopic("/FIFA2014/UPDATES"); 

      // Create publisher to publish updates from stadium 
      JMSProducer msgProducer = msgContext.createProducer(); 

      while(true){ 
       // Send match updates 
       switch(switchIndex){ 
        // Attendance 
        case 0: 
         msgBody ="Stadium Attendence " + stadiumAttendence; 
         stadiumAttendence += 314; 
         break; 

        // Goals 
        case 1: 
         msgBody ="SCORE: The Netherlands: " + nederlandsGoals + " - Chile:" + chileGoals; 
         break; 

        // Ball possession percentage 
        case 2: 
         msgBody ="Ball possession: The Netherlands: " + nederlandsHolding + "% - Chile: " + chileHolding + "%"; 
         if((nederlandsHolding > 60) && (nederlandsHolding < 70)){ 
          nederlandsHolding -= 2; 
          chileHolding += 2; 
         }else{ 
          nederlandsHolding += 2; 
          chileHolding -= 2; 
         } 
         break; 
       } 

       // Publish and wait for two seconds to publish next update 
       msgProducer.send (fifaScores, msgBody); 
       try{ 
        Thread.sleep(2000); 
       }catch(InterruptedException iex){ 

       } 

       // Increment and reset the index if greater than 2 
       switchIndex++; 
       if(switchIndex > 2) 
        switchIndex = 0; 
      } 
     }catch(JMSException jmsEx){ 
      System.out.println(jmsEx); 
     } 
    } 

    /* 
    * (non-Javadoc) 
    * @see java.lang.Runnable#run() 
    */ 
    public void run() { 
     // If this is a publisher thread 
     if(threadName == "PUBLISHER"){ 
      matchUpdatePublisher(); 
     }else{ 
      // Create subscription and start receiving publications 
      sharedNonDurableSubscriptionDemo(); 
     } 
    } 

    // Start thread 
    public void start(){ 
     System.out.println("Starting " + threadName); 
     if (t == null) 
     { 
      t = new Thread (this, threadName); 
      t.start(); 
     } 
     } 
    } 

私はIBM MQを初めて使用しているため、以下のインポートを解決する方法を理解できません。

import com.ibm.msg.client.jms.JmsConnectionFactory; 
import com.ibm.msg.client.jms.JmsFactoryFactory; 
import com.ibm.msg.client.wmq.WMQConstants; 

JARを介して他の依存関係を解決しました。これで助けてください。

答えて

1

「com.ibm.mq.allclient.jar」が必要です。キュー・マネージャーがインストールされている場合、またはINSTALL_DIR/java/libの下にMQC8がサポートされている場合は、ディスク上でこれを見つけることができます。

0

最近、JMSにIBM MQクラスを使用してキューにメッセージを配置し、成功しました。コンパイルする前に、ビルドパスに次のjarファイルがあることを確認してください。あなたはこれをダウンロードしても、あなたのPCにWebSphere MQをインストールしていれば、インストール・フォルダー(WebSphere MQ)/ Java/libに移動してjarファイルを見つけることができます。

com.ibm.mq.jmqi.jar

com.ibm.mqjms.jar

jms.jar

関連する問題