Sample JMS example using Active MQ
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
onurozcelik
Features Bachelor of science degree in Computer Engineering Master of science degree in Computer Engineering Working as a senior researcher at Tübitak BİLGEM
Updated on June 04, 2022Comments
-
onurozcelik almost 2 years
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 moduleimport 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()); } }
-
rishimaharaj about 10 years+1 - this helped me. Had a pom where I was trying different ways of using JMS and had glassfish which had an older version of SLF4J than what was required by ActiveMQ 5.9.1. Commenting out the glassfish dependencies in the pom resulted in everything working.