Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sample JMS example using Active MQ

I want to learn JMS application using Active MQ.
So downloaded apache-activemq-5.5.1 and started server
and found sample code but not working. Why following exception happens?
Note: I Added activemq library to my project and the library contains org.slf4j module

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());
           }
       }
like image 412
onurozcelik Avatar asked May 26 '26 10:05

onurozcelik


1 Answers

This error is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

since 1.6.0 As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation.

You can download SLF4J bindings from the project download page.

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

like image 54
Lukasz Avatar answered May 31 '26 15:05

Lukasz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!