2012-02-15 5 views
3

アクティブなMQを使用してJMSアプリケーションを学習したい。
apache-activemq-5.5.1をダウンロードしてサーバ
を起動し、サンプルコードを見つけましたが動作しません。なぜ次の例外が起こるのですか?
注:私は私のプロジェクトにActiveMQのライブラリを追加し、ライブラリは、このエラーが報告されorg.slf4jモジュールActive MQを使用したサンプルJMSの例

exception

import javax.jms.*; 
import org.apache.activemq.ActiveMQConnectionFactory; 
import javax.jms.MessageListener; 

     //JMS Producer   
     public class JMSProducer { 
       public void produce() { 
        String url = "tcp://localhost:61616"; 
        ConnectionFactory factory = new ActiveMQConnectionFactory(url); 
        try { 
         Connection connection = factory.createConnection(); 
         Session session = connection.createSession(false, 
           Session.AUTO_ACKNOWLEDGE); 
          Topic topic = session.createTopic("TestTopic"); 
          MessageProducer producer = session.createProducer(topic); 
          TextMessage msg = session.createTextMessage(); 
          msg.setText("Hello JMS World"); 
          producer.send(msg); 
        } 
        catch(JMSException exp) { 
        } 
       } 
      } 

    //JMS Consumer 
    public class JMSConsumer { 
      public void consume() { 
       String url = "tcp://localhost:61616"; 
       ConnectionFactory factory = new ActiveMQConnectionFactory(url); 
       try { 
        Connection connection = factory.createConnection(); 
        Session session = connection.createSession(false, 
         Session.AUTO_ACKNOWLEDGE); 
        Topic topic = session.createTopic("TestTopic"); 
        MessageConsumer consumer = session.createConsumer(topic); 
        JMSMessageListener listener = new JMSMessageListener(); 
        consumer.setMessageListener(listener); 
        connection.start(); 
       } 
       catch(JMSException exp) { 
       } 
      } 
     } 

//JMS Message Listener 
public class JMSMessageListener implements MessageListener { 
     @Override 
      public void onMessage(javax.jms.Message msg) { 
       System.out.println(msg.toString()); 
      } 
     } 

答えて

5

が含まれている場合org.slf4j.impl.StaticLoggerBinder クラスができませんでしたメモリにロードされます。これは、 適切なSLF4Jバインディングがクラスパス上に見つからない場合に発生します。 パスのslf4j-nop.jar、slf4j-simple.jar、 、slf4j-log4j12.jar、slf4j-jdk14.jar、またはlogback-classic.jarのうちの1つ(唯一)を配置すると問題が解決されます。

1.6.0 SLF4Jバージョン1.6以降、バインディングがない場合、SLF4Jはデフォルトでノーオペレーション(NOP)ロガーの実装になります。

プロジェクトダウンロードページからSLF4Jバインディングをダウンロードできます。

http://www.slf4j.org/codes.html#StaticLoggerBinder

+0

1 - これは私を助けました。私はJMSを使用するさまざまな方法を試していましたが、ActiveMQ 5.9.1より古いバージョンのSLF4Jを使用していました。 pomのglassfishの依存関係をコメントアウトすると、すべてが機能しました。 – rishimaharaj

関連する問題