You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Stream caching

While stream types (like StreamSource, InputStream and Reader) are commonly used in messaging for performance reasons, they also have an important drawback: they can only be read once. In order to be able to work with message content multiple times, the stream needs to be cached.

By default, streams are caching in memory. In Camel 2.0, large stream messages (over 64 Kb) will be cached in a temporary file instead – Camel itself will handle deleting the temporary file once the cached stream is no longer necessary.

Using stream caching

Implicitly enabled for multicast and dead letter channel

Some EIPs require that the message content can be read multiple times. Stream caching will be automatically enabled when using these EIPs in your routes:

  • Multicast will implicitly cache streams to ensure that all the endpoints can access the message content
  • Dead Letter Channel uses stream caching to ensure that the message content can actually be read again when redelivering a message

Explicitly enabling stream caching

In Apache Camel, you can explicitly enable stream caching for a single route with the streamCaching DSL method:

Error formatting macro: snippet: java.lang.NullPointerException

You can also enable it for all the routes in routebuilder:

Error formatting macro: snippet: java.lang.NullPointerException

How it works?

In order to determine if a type requires caching, we leverage the type converter feature. Any type that requires stream caching can be converted into an org.apache.camel.StreamCache instance.

  • No labels