I want to connect a log4j JMSAppender
to an ActiveMQ queue over Apache Camel, so that both are endpoints along a route. Furthermore, I'd like to have all the config done in Java (not XML).
The log4j javadoc here and this SO question both show great examples of how to set up such a connection sans Camel (via JNDI), but they are not quite what I am looking for.
I know this is possible through the activemq-camel
Camel component, and in fact that component's tutorial page shows how to set up a pooled connection factory to a broker URL. Unfortunately (for me) its all in XML.
I am struggling with:
JMSAppender
publishes messages over Camel to the correct queue; this involves endpoint creation and routebuilding Somewhere I will need an init()
-type method to set up my CamelContext
:
CamelContext context = new DefaultCamelContext();
context.addComponent("log4j-jms-appender", new LogComponent()); // ????
context.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false")); // ???
context.addRoutes(new RouteBuilder() {
public void configure() {
from("log4j-jms-appender").to("activemq:queue:log-queue");
}
});
Now, there are already several problems with this code - and I may have even gone down the wrong path entirely. As you can see, I'm struggling to add the endpoint components correctly. I'm also completely unsure of what the string " vm://
" protocol is or what it stands for. All the other code examples I see involve ActiveMQ utilizing the tcp
protocol.
Putting it altogether, it would just be nice to write a log4j Logger
and Appender
like this:
Logger logger = Logger.getLogger("foo.bar");
JMSAppender jmsAppender = configureJMSAppender();
logger.addAppender(jmsAppender);
...and then have all of its log messages placed on the ActiveMQ log-queue
via Camel (and not JNDI/Java).
Thanks in advance for any and all help!
The camel-log component doesn't have a consumer...so you can't wire up a route to consume from the log and send to a queue.
One option is to configure a JMSAppender in the log4j.properties as this page describes...
http://activemq.apache.org/how-do-i-use-log4j-jms-appender-with-activemq.html
Also, vm:// stands for virtual machine transport ...it allows you to connect to an ActiveMQ broker running in your VM...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.