I'll then see if I can work out the configuration details required to get Chainsaw to join in and see Logging Events.

It's definitely doable, I just don't have all the info as yet.


Ok, simplistic test case here, using the class and jndi.properties shown further below, which depends on activemq 4.1.1 core jar and log4j 1.2.14.

Steps:

1) Download ActiveMQ 4.1.1 distribution.  Run the broker:

Paul-Smiths-Computer:/JavaStuff/apache-activemq-4.1.1/bin paulsmith $ ./activemq
ACTIVEMQ_HOME: /JavaStuff/apache-activemq-4.1.1
ACTIVEMQ_BASE: /JavaStuff/apache-activemq-4.1.1
Loading message broker from: xbean:activemq.xml
INFO BrokerService - ActiveMQ 4.1.1 JMS Message Broker (localhost) is starting
IN
..
...etc

Also, in a second window, run the consumer example that comes with ActiveMQ (it comes with an examples sub-folder):

ant consumer -Dtopic=true -Dsubject=jmsappendertest

This will sit and wait for 10 messages on the 'jmsappendertest' topic to arrive.

Now run the below simplistic test case showing how using the JMSAppender can send topic messages. The consumer test above will print out the messages it receives.



package org.apache.logging;

import java.util.Date;

import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.net.JMSAppender;

public class Shell {

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


        BasicConfigurator.configure();
        Logger.getLogger("org.apache.activemq").setLevel(Level.INFO);

        Logger LOG = Logger.getLogger(Shell.class);
        LOG.info("Startup...");

        JMSAppender appender = new JMSAppender();
appender.setInitialContextFactoryName (ActiveMQInitialContextFactory.class.getName());
        appender.setProviderURL("tcp://localhost:61616");
appender.setTopicConnectionFactoryBindingName ("topicConnectionFactory");
        appender.setTopicBindingName("dynamicTopics/jmsappendertest");
        appender.activateOptions();

        Logger.getRootLogger().addAppender(appender);

        while (true) {
LOG.info("At the 3rd stroke it will be " + new Date ().toString());
            Thread.sleep(1000);
        }
    }
}

-----------------------------------------
You will also need this jndi.properties file in the class path of this example:

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory

# use the following property to configure the default connector
java.naming.provider.url = tcp://localhost:61616

connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactory


# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.jmsappendertest = jmsappendertest


Next I'll work out how to get Chainsaw to replace the conusmer test as the client.

cheers

Paul



Reply via email to