简体   繁体   中英

How to log a message / route (stream) in camel properly?

I'm using Apache camel to route some SOAP messages from A to B.

I'd like to add logging for some specific routes, but the problem is that the message body is a stream.

My solution is to convert that stream into a string and afterwards send it to the endpoint B.

This seems to work fine, but I'm not sure how clean this method is?

This is how my route looks like now:

<route>
    <from uri="cxf:bean:ServiceA?dataFormat=MESSAGE" />
    <convertBodyTo type="java.lang.String"/>
    <to uri="log:my.company?level=WARN"/>
    <to ref="ServiceB" />
</route>

Question is if I should use a wireTap and stream caching to copy the stream, convert it to a string, log it and send the other untouched stream to ServiceB. I couldn't find a way to do this properly. This is my attempt of doing it:

<route streamCache="true">
    <from uri="cxf:bean:ServiceA?dataFormat=MESSAGE" />
    <wireTap uri="log:my.company?level=WARN" /> <!-- how to convert this stream to a string? -->
    <to ref="ServiceB" />
</route>

So, what do you say? WireTap or the above solution?

You can just enable the showStreams=true option on the log endpoint. Then it will log streams as well ; and you wont need to convert the body prior to that. You would still need though to enable stream caching to ensure the stream can be re-read later when you continue processing the message.

See the options on the log component from its documentation: http://camel.apache.org/log

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM