[logback-user] Configuring JMSQueueAppender to send messages to a Websphere MQ server
Espen Rydningen
espenrydningen at gmail.com
Mon Oct 11 14:36:53 CEST 2010
After a heap of other projects I finally got time to solve this problem, and
it was just as you stated Christian, the MQ guy gave me raw MQ details.
After nagging him to set this properly up in the application server, the
configuration was just this:
<appender name="QUEUE"
class="com.foo.bar.common.log.CustomJMSQueueAppender">
<QueueConnectionFactoryBindingName>jms/FooBarQF</QueueConnectionFactoryBindingName>
<QueueBindingName>jms/FooBarQ</QueueBindingName>
</appender>
-Espen
On Wed, Aug 25, 2010 at 4:56 PM, Christian Migowski <chrismfwrd at gmail.com>wrote:
> Hi Espen,
>
> this has nothing to do with logback. Your problem is that your MQ guy
> just gave you the "raw MQ credentials" (i.e. you'd have to create the
> ConnectionFactory and Queue object by yourself), but what logback
> needs is a JNDI-bound ConnectionFactory and Queue.
> If you have an application server at hand, the most easy way to solve
> this is to deploy the "IBM Websphere MQ resource adapter" in it and
> use the JNDI-bound objects from there. Here is a HOWTO for Jboss:
>
>
> http://www.ibm.com/developerworks/websphere/library/techarticles/0710_ritchie/0710_ritchie.html
>
> hth,
> regards,
> christian!
>
> On Wed, Aug 25, 2010 at 4:28 PM, Espen Rydningen
> <espenrydningen at gmail.com> wrote:
> > Hi
> >
> > Has anyone successfully configured the JMSQueueAppender to send
> > messages to a Websphere MQ server? I'm really struggling with this.
> > Hope someone can assist. Here is my configuration file:
> >
> > logback-test.xml
> >
> > <?xml version="1.0" encoding="UTF-8" ?>
> > <configuration>
> >
> > <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
> > <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
> > <pattern>
> > %d{HH:mm:ss} [%thread] %-5level %logger{0} - %msg%n
> > </pattern>
> > </encoder>
> > </appender>
> >
> > <appender name="QUEUE"
> class="com.foo.bar.common.log.CustomJMSQueueAppender">
> >
> <InitialContextFactoryName>org.apache.activemq.jndi.ActiveMQInitialContextFactory</InitialContextFactoryName>
> > <ProviderURL>tcp://10.10.10.10:1414</ProviderURL>
> >
> <QueueConnectionFactoryBindingName>ConnectionFactory</QueueConnectionFactoryBindingName>
> > <QueueBindingName>app_test_log</QueueBindingName>
> >
> > <!-- Only messages with marker JMS gets through to queue-->
> > <filter class="com.foo.bar.common.log.MarkerFilter">
> > <marker>JMS</marker>
> > <onMismatch>DENY</onMismatch>
> > <onMatch>ACCEPT</onMatch>
> > </filter>
> > </appender>
> >
> > <root level="TRACE" >
> > <appender-ref ref="STDOUT" />
> > <appender-ref ref="QUEUE" />
> > </root>
> > </configuration>
> >
> > My MQ guy who sat up the queue gave me these values:
> >
> > qmanager is ESAPFOK9
> > machine is 10.10.10.10
> > Channel is app.logging
> > queue is app_test_log
> >
> > These are the essential parts of my Maven2 pom file:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > (...)
> >
> > <dependency>
> > <groupId>ch.qos.logback</groupId>
> > <artifactId>logback-classic</artifactId>
> > <version>0.9.21</version>
> > </dependency>
> >
> > <dependency>
> > <groupId>junit</groupId>
> > <artifactId>junit</artifactId>
> > <version>4.8.1</version>
> > <scope>test</scope>
> > </dependency>
> >
> > <dependency>
> > <groupId>org.apache.activemq</groupId>
> > <artifactId>activemq-core</artifactId>
> > <version>5.0.0</version>
> > <scope>test</scope>
> > <exclusions>
> > <exclusion>
> > <groupId>commons-logging</groupId>
> > <artifactId>commons-logging</artifactId>
> > </exclusion>
> > <exclusion>
> > <groupId>commons-logging</groupId>
> >
> <artifactId>commons-logging-api</artifactId>
> > </exclusion>
> > <exclusion>
> > <groupId>org.apache.activemq</groupId>
> > <artifactId>activeio-core</artifactId>
> > </exclusion>
> > </exclusions>
> > </dependency>
> >
> > </dependencies>
> >
> > </project>
> >
> > I made a really simple Junit test:
> >
> > public class CustomJMSQueueAppenderTest {
> > private final static Logger logger =
> > LoggerFactory.getLogger(CustomJMSQueueAppenderTest.class);
> > private static Marker JMS_LOG = MarkerFactory.getMarker("JMS_LOG");
> >
> > @Test
> > public void sendLogMessageToMqAndFile(){
> > logger.info("New test run: {}", new Date());
> > logger.info("This message will only be sent to console");
> > logger.info(JMS_LOG, "This message is to be sent both to
> > console and to JMS");
> > }
> > }
> >
> > But alas, this was the result:
> >
> > Running com.foo.bar.common.log.CustomJMSQueueAppenderTest
> > 15:50:41,860 |-INFO in ch.qos.logback.classic.LoggerContext[default] -
> > Found resource [logback-test.xml] at
> >
> [file:/usr/IBM/build/frontend-trunk/delegator/foobar/target/test-classes/logback-test.xml]
> > 15:50:42,329 |-INFO in
> > ch.qos.logback.classic.joran.action.ConfigurationAction - debug
> > attribute not set
> > 15:50:42,411 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
> > - About to instantiate appender of type
> > [ch.qos.logback.core.ConsoleAppender]
> > 15:50:42,431 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
> > - Naming appender as [STDOUT]
> > 15:50:42,593 |-INFO in
> > ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing
> > component [encoder] on top of the object stack.
> > 15:50:42,872 |-INFO in
> > ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing
> > component [filter] on top of the object stack.
> > 15:50:42,961 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
> > - About to instantiate appender of type
> > [com.foo.bar.common.log.CustomJMSQueueAppender]
> > 15:50:42,981 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
> > - Naming appender as [QUEUE]
> > 15:50:43,070 |-INFO in
> > ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing
> > component [filter] on top of the object stack.
> > 15:50:47,121 |-ERROR in
> > com.foo.bar.common.log.CustomJMSQueueAppender[QUEUE] - Error while
> > activating options for appender named [QUEUE]. javax.jms.JMSException:
> > java.io.EOFException
> > at javax.jms.JMSException: java.io.EOFException
> > at at
> >
> org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:49)
> > at at
> >
> org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1178)
> > at at
> >
> org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1262)
> > at at
> >
> org.apache.activemq.ActiveMQConnection.createSession(ActiveMQConnection.java:292)
> > at at
> >
> org.apache.activemq.ActiveMQConnection.createQueueSession(ActiveMQConnection.java:1123)
> > at at
> >
> ch.qos.logback.classic.net.JMSQueueAppender.start(JMSQueueAppender.java:113)
> > at at
> >
> ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:96)
> > at at
> >
> ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:315)
> > at at
> >
> ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:194)
> > at at
> >
> ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:180)
> > at at
> > ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:52)
> > at at
> > ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:332)
> > at at
> >
> ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126)
> > at at
> >
> ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:93)
> > at at
> >
> ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:52)
> > at at
> >
> ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:60)
> > at at
> >
> ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:121)
> > at at
> > org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
> > at at
> > org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
> > at at java.lang.J9VMInternals.initializeImpl(Native Method)
> > at at
> java.lang.J9VMInternals.initialize(J9VMInternals.java:194)
> > at at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
> > at at
> > org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
> > at at
> > org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
> > at at
> org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
> > at at
> org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
> > at at
> >
> com.foo.bar.common.log.CustomJMSQueueAppenderTest.<clinit>(CustomJMSQueueAppenderTest.java:13)
> > at at java.lang.J9VMInternals.initializeImpl(Native Method)
> > at at
> java.lang.J9VMInternals.initialize(J9VMInternals.java:194)
> > at at
> > sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> > at at
> >
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:67)
> > at at
> >
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> > at at
> > java.lang.reflect.Constructor.newInstance(Constructor.java:522)
> > at at
> >
> org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:202)
> > at at
> >
> org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:251)
> > at at
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> > at at
> >
> org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:248)
> > at at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
> > at at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> > at at
> org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> > at at
> > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> > at at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> > at at
> > org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> > at at
> > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> > at at
> org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> > at at
> >
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
> > at at
> >
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
> > at at
> >
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
> > at at
> org.apache.maven.surefire.Surefire.run(Surefire.java:177)
> > at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method)
> > at at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
> > at at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > at at java.lang.reflect.Method.invoke(Method.java:618)
> > at at
> >
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
> > at at
> >
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
> > Caused by: java.io.EOFException
> > at at
> java.io.DataInputStream.readFully(DataInputStream.java:204)
> > at at
> java.io.DataInputStream.readInt(DataInputStream.java:380)
> > at at
> >
> org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:268)
> > at at
> >
> org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:192)
> > at at
> >
> org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:184)
> > at at
> > org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:172)
> > at at java.lang.Thread.run(Thread.java:810)
> >
> >
> >
> > Now I'm very lost. Hoping someone can help me out.
> >
> > Best regards
> > Espen
> > _______________________________________________
> > Logback-user mailing list
> > Logback-user at qos.ch
> > http://qos.ch/mailman/listinfo/logback-user
> >
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20101011/f818822c/attachment-0001.html>
More information about the Logback-user
mailing list