Repository: camel Updated Branches: refs/heads/master ea96c3e6b -> 18198a38d
Added camel-ehcache docs to Gitbook Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/18198a38 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/18198a38 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/18198a38 Branch: refs/heads/master Commit: 18198a38d1191f5fa9e8c01475994ecb2134df20 Parents: ea96c3e Author: Andrea Cosentino <[email protected]> Authored: Thu Jun 30 13:48:22 2016 +0200 Committer: Andrea Cosentino <[email protected]> Committed: Thu Jun 30 13:48:22 2016 +0200 ---------------------------------------------------------------------- .../camel-ehcache/src/main/docs/ehcache.adoc | 198 +++++++++++++++++++ docs/user-manual/en/SUMMARY.md | 1 + 2 files changed, 199 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/18198a38/components/camel-ehcache/src/main/docs/ehcache.adoc ---------------------------------------------------------------------- diff --git a/components/camel-ehcache/src/main/docs/ehcache.adoc b/components/camel-ehcache/src/main/docs/ehcache.adoc new file mode 100644 index 0000000..2b1815f --- /dev/null +++ b/components/camel-ehcache/src/main/docs/ehcache.adoc @@ -0,0 +1,198 @@ +[[Ehcache-EhcacheComponent]] +Ehcache Component +~~~~~~~~~~~~~~~~~ + +*Available as of Camel 2.18.x* + +The *ehcache* component enables you to perform caching operations using +Ehcache 3 as the Cache Implementation. + +This component supports producer and event based consumer endpoints. + +The Cache consumer is an event based consumer and can be used to listen +and respond to specific cache activities. + +Maven users will need to add the following dependency to +their `pom.xml` for this component: + +[source,xml] +------------------------------------------------------------ +<dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-ehcache</artifactId> + <version>x.x.x</version> + <!-- use the same version as your Camel core version --> +</dependency> +------------------------------------------------------------ + +[[Ehcache-URIformat]] +URI format +^^^^^^^^^^ + +[source,java] +----------------------------- +ehcache://cacheName[?options] +----------------------------- + +You can append query options to the URI in the following +format, `?option=value&option=#beanRef&...` + +[[Ehcache-Options]] +Options +^^^^^^^ + + +// component options: START +The Ehcache component has no options. +// component options: END + + + +// endpoint options: START +The Ehcache component supports 5 endpoint options which are listed below: + +{% raw %} +[width="100%",cols="2s,1,1m,1m,5",options="header"] +|======================================================================= +| Name | Group | Default | Java Type | Description +| cacheName | common | | String | *Required* the cache name +| bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored. +| exceptionHandler | consumer (advanced) | | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored. +| exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange +| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). +|======================================================================= +{% endraw %} +// endpoint options: END + + +[[Ehcache-MessageHeadersCamel]] +Message Headers Camel +++++++++++++++++++++++ + + +[width="100%",cols="10%,10%,80%",options="header",] +|======================================================================= +|Header |Type |Description + +|CamelEhcacheAction |`String` |The operation to be perfomed on the cache, valid options are: + +* CLEAR +* PUT +* PUT_ALL +* PUT_IF_ABSENT +* GET +* GET_ALL +* REMOVE +* REMOVE_ALL +* REPLACE + +|CamelEhcacheActionHasResult |Boolean |Set to true if the action has a result + +|CamelEhcacheActionSucceeded |`Boolean` |Set to true if the actionsuccedded + +|CamelEhcacheKey |Object |The cache key used for an action + +|CamelEhcacheKeys |Set<Object> |A list of keys, used in + +* PUT_ALL +* GET_ALL +* REMOVE_ALL + +|CamelEhcacheValue |Object |The value to put in the cache or the result of an operation + +|CamelEhcacheOldValue |Object |The old value associated to a key for actions like PUT_IF_ABSENT or the +Object used for comparison for actions like REPLACE + +|CamelEhcacheEventType |EventType |The type of event received +|======================================================================= + +[[Ehcache-Ehcachebasedidempotentrepositoryexample:]] +Ehcache based idempotent repository example: +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +[source,java] +------------------------------------------------------------------------------------------------ +CacheManager manager = CacheManagerBuilder.newCacheManager(new XmlConfiguration("ehcache.xml")); +EhcacheIdempotentRepository repo = new EhcacheIdempotentRepository(manager, "idempotent-cache"); + +from("direct:in") + .idempotentConsumer(header("messageId"), idempotentRepo) + .to("mock:out"); +------------------------------------------------------------------------------------------------ + + + +[[Ehcache-Ehcachebasedaggregationrepositoryexample:]] +Ehcache based aggregation repository example: +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +[source,java] +--------------------------------------------------------------------------------------------------------------------------------- +public class EhcacheAggregationRepositoryRoutesTest extends CamelTestSupport { + private static final String ENDPOINT_MOCK = "mock:result"; + private static final String ENDPOINT_DIRECT = "direct:one"; + private static final int[] VALUES = generateRandomArrayOfInt(10, 0, 30); + private static final int SUM = IntStream.of(VALUES).reduce(0, (a, b) -> a + b); + private static final String CORRELATOR = "CORRELATOR"; + + @EndpointInject(uri = ENDPOINT_MOCK) + private MockEndpoint mock; + + @Produce(uri = ENDPOINT_DIRECT) + private ProducerTemplate producer; + + @Test + public void checkAggregationFromOneRoute() throws Exception { + mock.expectedMessageCount(VALUES.length); + mock.expectedBodiesReceived(SUM); + + IntStream.of(VALUES).forEach( + i -> producer.sendBodyAndHeader(i, CORRELATOR, CORRELATOR) + ); + + mock.assertIsSatisfied(); + } + + private Exchange aggregate(Exchange oldExchange, Exchange newExchange) { + if (oldExchange == null) { + return newExchange; + } else { + Integer n = newExchange.getIn().getBody(Integer.class); + Integer o = oldExchange.getIn().getBody(Integer.class); + Integer v = (o == null ? 0 : o) + (n == null ? 0 : n); + + oldExchange.getIn().setBody(v, Integer.class); + + return oldExchange; + } + } + + @Override + protected RoutesBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from(ENDPOINT_DIRECT) + .routeId("AggregatingRouteOne") + .aggregate(header(CORRELATOR)) + .aggregationRepository(createAggregateRepository()) + .aggregationStrategy(EhcacheAggregationRepositoryRoutesTest.this::aggregate) + .completionSize(VALUES.length) + .to("log:org.apache.camel.component.ehcache.processor.aggregate.level=INFO&showAll=true&mulltiline=true") + .to(ENDPOINT_MOCK); + } + }; + } + + protected EhcacheAggregationRepository createAggregateRepository() throws Exception { + CacheManager cacheManager = CacheManagerBuilder.newCacheManager(new XmlConfiguration("ehcache.xml")); + cacheManager.init(); + + EhcacheAggregationRepository repository = new EhcacheAggregationRepository(); + repository.setCacheManager(cacheManager); + repository.setCacheName("aggregate"); + + return repository; + } +} +--------------------------------------------------------------------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/18198a38/docs/user-manual/en/SUMMARY.md ---------------------------------------------------------------------- diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md index ec75f76..005396c 100644 --- a/docs/user-manual/en/SUMMARY.md +++ b/docs/user-manual/en/SUMMARY.md @@ -152,6 +152,7 @@ * [Dozer](dozer.adoc) * [Dropbox](dropbox.adoc) * [Eclipse](eclipse.adoc) + * [Ehcache](ehcache.adoc) * [EJB](ejb.adoc) * [ElasticSearch](elasticsearch.adoc) * [Elsql](elsql.adoc)
