You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/11/25 12:17:34 UTC

[11/28] camel git commit: Revert "Added first version of the documentation which should be complete."

Revert "Added first version of the documentation which should be complete."

This reverts commit 0624507966ea9a6c53c0e0c14c19b77ec548e217.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/827fd43d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/827fd43d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/827fd43d

Branch: refs/heads/master
Commit: 827fd43d7c2213db6f5c31db7021d3de5d04df7b
Parents: 93291ec
Author: Andrea Cosentino <an...@gmail.com>
Authored: Fri Nov 25 12:49:53 2016 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Fri Nov 25 12:49:53 2016 +0100

----------------------------------------------------------------------
 .../src/main/docs/firebase-component.adoc       | 220 +++++++++++--------
 1 file changed, 131 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/827fd43d/components/camel-firebase/src/main/docs/firebase-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-firebase/src/main/docs/firebase-component.adoc b/components/camel-firebase/src/main/docs/firebase-component.adoc
index c0701cf..e3ca1bb 100644
--- a/components/camel-firebase/src/main/docs/firebase-component.adoc
+++ b/components/camel-firebase/src/main/docs/firebase-component.adoc
@@ -2,7 +2,7 @@
 Firebase Component
 ~~~~~~~~~~~~~~~~~
 
-*Available as of Camel 2.19.x*
+*Available as of Camel 2.18.x*
 
 The *firebase*�component enables you to save, modify data in Google Firebase database
 and consume to all child of a specific reference.
@@ -25,32 +25,41 @@ their�`pom.xml`�for this component:
 </dependency>
 ------------------------------------------------------------
 
-[[Firebase-URIformat]]
+[[Ehcache-URIformat]]
 URI format
 ^^^^^^^^^^
 
 [source,java]
 -----------------------------
-firebase://[endpoint]?[options]
+firebase://databaseUrl[?options]
 -----------------------------
 
 You can append query options to the URI in the following
-format,�`?option=value&option=value1&...`
+format,�`?option=value&option=#beanRef&...`
 
-Do not forget to URL encode the option values.
+Do not forget to URL encode the parameters
 
 [[Firebase-Options]]
 Options
 ^^^^^^^
 
+
+// component options: START
+The Firebase component has no options.
+// component options: END
+
+
+
 // endpoint options: START
 The Firebase component supports 9 endpoint options which are listed below:
 
+{% raw %}
 [width="100%",cols="2,1,1m,1m,5",options="header"]
 |=======================================================================
 | Name | Group | Default | Java Type | Description
+| databaseUrl | common |  | String | *Required* The Firebase database URL. Always uses https
+| async | common | async | boolean | If true the save or update request (set value in Firebase terms) is fired and the reply will be ignored else the routing thread will wait and the reply will be saved in the exchange message
 | keyName | common | firebaseKey | String | The Camel exchange header name in which the Firebase key is specified. Only needed in case you are saving or updating data
-| reply | common | false | boolean | If *false* the save or update request (*setValue* in Firebase terms) is fired and the reply will be ignored, otherwise the routing thread will wait and the reply will be saved in the body of the exchange message
 | rootReference | common |  | String | *Required* The path in the database tree where the key value pairs are to be stored
 | serviceAccountFile | common |  | String | *Required* The path to the JSON file which provided the keys used to connect to Firebase. This file is typically generated when you create the database
 | 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.
@@ -58,105 +67,138 @@ The Firebase component supports 9 endpoint options which are listed below:
 | exchangePattern | consumer (advanced) |  | ExchangePattern | Sets the exchange pattern when the consumer creates 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
 
 
-[[Firebase-MessageHeadersCamel]]
+[[Ehcache-MessageHeadersCamel]]
 Message Headers Camel�
 ++++++++++++++++++++++
 
-
-[width="100%",cols="20%,10%,70%",options="header"]
-|=======================================================================
-| Header | Type | Description
-| firebaseKey | `String` | The Firebase key to which a child listener is attached. This name of this parameter can be overriden using the *firebaseKey* option
+�
+[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
 
-[[Firebase-Usageexamples]]
+|CamelEhcacheActionHasResult |Boolean |Set to true if the action has a result
 
-Usage examples
-^^^^^^^^^^^^^^
+|CamelEhcacheActionSucceeded |`Boolean` |Set to true if the actionsuccedded
 
-[[Firebase-Consumer]]
-Firebase Consumer
-+++++++++++++++++
+|CamelEhcacheKey |Object |The cache key used for an action
 
-The code below demonstrates how you can create a route which consumes the messages coming from a Firebase listener.
+|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]
---------------------------------------------------------------------------------------
-@Override
-protected RouteBuilder createRouteBuilder() throws Exception {
-    final String databaseUrl = "gil-sample-app.firebaseio.com";
-    final String originalRootReference = "server/saving-data";
-    String serviceAccountFile = ConfigurationProvider.createFirebaseConfigLink();
-    String rootReference = URLEncoder.encode(originalRootReference, "UTF-8");
-    insertDummyData(String.format("https://%s", databaseUrl), originalRootReference, serviceAccountFile);
-
-    return new RouteBuilder() {
-        public void configure() {
-            try {
-                from(String.format("firebase://" + databaseUrl + "?rootReference=%s&serviceAccountFile=%s",
-                        rootReference, serviceAccountFile))
-                        .to("log:firebasetest?level=WARN")
-                        .to("mock:result");
-            } catch (Exception e) {
-                fail(e.toString());
-            }
-        }
-    };
-}
---------------------------------------------------------------------------------------
+------------------------------------------------------------------------------------------------
+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");
+------------------------------------------------------------------------------------------------
 
-[[Firebase-Producer]]
-Firebase Producer
-+++++++++++++++++
+�
 
-The example below shows how you can send data to Firebase.
+[[Ehcache-Ehcachebasedaggregationrepositoryexample:]]
+Ehcache based aggregation repository example:
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 [source,java]
---------------------------------------
-CamelContext context = new DefaultCamelContext();
-context.addRoutes(new RouteBuilder() {
+---------------------------------------------------------------------------------------------------------------------------------
+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
-    public void configure() throws Exception {
-        String rootReference = URLEncoder.encode("server/saving-data", "UTF-8");
-        String serviceAccountFile = "firebase-admin-connection.json";
-        from(sampleInputProvider.getTargetFolder().toUri().toString())
-            .process(exchange -> {
-                GenericFile file = (GenericFile) exchange.getIn().getBody();
-                String content = new String(Files.readAllBytes(Paths.get(file.getAbsoluteFilePath())), "UTF-8");
-                String[] keyValue = content.split("=");
-                final Message out = exchange.getOut();
-                out.setHeader("firebaseKey", keyValue[0]);
-                out.setBody(keyValue[1].trim());
-            })
-            .to(String.format("firebase://%s?rootReference=%s&serviceAccountFile=%s&reply=%b",
-                    "gil-sample-app.firebaseio.com", rootReference, serviceAccountFile, reply))
-            .to("log:whenFirebaseSet?level=WARN")
-            .process(exchange1 -> {
-                assertThat(exchange1.getIn().getBody().getClass()).isEqualTo(expectedBodyClass);
-                if (reply) {
-                    assertThat(exchange1.getIn().getHeader("firebaseKey")).isNotNull();
-                }
-                try {
-                    reentrantLock.lock();
-                    wake.signal();
-                } finally {
-                    reentrantLock.unlock();
-                }
-            });
+    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);
+            }
+        };
     }
-});
---------------------------------------
-
-[[Exec-SeeAlso]]
-See Also
-^^^^^^^^
-
-* link:configuring-camel.html[Configuring Camel]
-* link:component.html[Component]
-* link:endpoint.html[Endpoint]
-* link:getting-started.html[Getting Started]
-* link:https://firebase.google.com/[Firebase]
-* link:https://console.firebase.google.com/[Firebase console]
\ No newline at end of file
+
+    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;
+    }
+}
+---------------------------------------------------------------------------------------------------------------------------------