This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes JMSAppender and logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMSAppender and logging" Watch "JMSAppender and logging" New topic

JMSAppender and logging

Aditya Yagnik

Joined: Mar 29, 2010
Posts: 7

Dear Members,

I am trying to put a logging mechanism in place using commons logging and log4j. I have managed to configure for Console and FileAppender. However, I am having difficulty in making JMSAppender work on my local box. Please find below log4j properties file and test code.

Log4j properties:

log4j.appender.JMSAPPENDER =
log4j.appender.JMSAPPENDER.Threshold = DEBUG
log4j.appender.JMSAPPENDER.InitialContextFactoryName = org.apache.activemq.jndi.ActiveMQInitialContextFactory
log4j.appender.JMSAPPENDER.ProviderURL = tcp://localhost:61616
log4j.appender.JMSAPPENDER.TopicBindingName = logTopic
log4j.appender.JMSAPPENDER.TopicConnectionFactoryBindingName = ConnectionFactory

JAVA Class:

package test;
import javax.jms.Connection;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.spi.LoggingEvent;

public class Log4jJMSAppenderExample implements MessageListener {

private static final Log logger = LogFactory.getLog("Log4jJMSAppenderExample.class");
public Log4jJMSAppenderExample() throws Exception {

// create a logTopic topic consumer
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection conn = factory.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = sess.createConsumer(sess.createTopic("logTopic"));
consumer.setMessageListener((MessageListener) this);

// log a message"Test log");

// clean up

public static void main(String[] args) throws Exception {
new Log4jJMSAppenderExample();

public void onMessage(Message message) {
try {
// receive log event in your consumer
LoggingEvent event = (LoggingEvent)((ActiveMQObjectMessage)message).getObject();
System.out.println("Received log [" + event.getLevel() + "]: "+ event.getMessage());
} catch (Exception e) {


I am getting below errors. Please can somebody help.

log4j:ERROR Error while activating options for appender named [JMSAPPENDER].
javax.jms.JMSException: Wire format negotiation timeout: peer did not send his wire format.
at org.apache.activemq.util.JMSExceptionSupport.create(
at org.apache.activemq.ActiveMQConnection.syncSendPacket(
at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(
at org.apache.activemq.ActiveMQConnection.createSession(
at org.apache.activemq.ActiveMQConnection.createTopicSession(
at Source)
at org.apache.log4j.config.PropertySetter.activate(
at org.apache.log4j.config.PropertySetter.setProperties(
at org.apache.log4j.config.PropertySetter.setProperties(
at org.apache.log4j.PropertyConfigurator.parseAppender(
at org.apache.log4j.PropertyConfigurator.parseCategory(
at org.apache.log4j.PropertyConfigurator.configureRootCategory(
at org.apache.log4j.PropertyConfigurator.doConfigure(
at org.apache.log4j.PropertyConfigurator.doConfigure(
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(
at org.apache.log4j.LogManager.<clinit>(
at org.apache.log4j.Logger.getLogger(
at org.apache.commons.logging.impl.Log4JLogger.getLogger(
at org.apache.commons.logging.impl.Log4JLogger.<init>(
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(
at org.apache.commons.logging.LogFactory.getLog(
at test.Log4jJMSAppenderExample.<clinit>(
Caused by: Wire format negotiation timeout: peer did not send his wire format.
at org.apache.activemq.transport.WireFormatNegotiator.oneway(
at org.apache.activemq.transport.MutexTransport.oneway(
at org.apache.activemq.transport.ResponseCorrelator.asyncRequest(
at org.apache.activemq.transport.ResponseCorrelator.request(
at org.apache.activemq.ActiveMQConnection.syncSendPacket(
... 27 more
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 193

Look at the link below
Active MQ - Log4j JMS Appender

Hope that resolves your issue.

Aditya Yagnik

Joined: Mar 29, 2010
Posts: 7

Thanks Prabhakar. I have managed to create a topic. Next task is to configure chainsaw to read the log.

Naveed Assghar

Joined: Nov 15, 2011
Posts: 1
1- One possibility could be that you are connecting to a wrong host:port this link can explain this issue
2- make sure activemq-all-5.5.1.jar is not included twice on your classpath. if it is already loaded by tomcat from its lib directory then remove it from your war or vice versa.
I agree. Here's the link:
subject: JMSAppender and logging
It's not a secret anymore!