You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2018/10/01 22:03:09 UTC

[camel-k] branch master updated: Added an example of binding object in Camel registry in groovy

This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/master by this push:
     new c54af58  Added an example of binding object in Camel registry in groovy
c54af58 is described below

commit c54af58129a083d0faf1352c6a047efc700358e2
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Oct 1 14:55:58 2018 +0200

    Added an example of binding object in Camel registry in groovy
---
 runtime/examples/camel-caffeine.groovy | 43 ++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/runtime/examples/camel-caffeine.groovy b/runtime/examples/camel-caffeine.groovy
new file mode 100644
index 0000000..d1aada7
--- /dev/null
+++ b/runtime/examples/camel-caffeine.groovy
@@ -0,0 +1,43 @@
+//
+// To run this integrations use:
+//
+//     kamel run -d camel:groovy runtime/examples/camel-caffeine.groovy
+//
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
+  Cache cache = Caffeine.newBuilder().recordStats().build();
+
+  registry {
+      bind 'caffeineCache', cache
+  }
+
+  from('timer:tick')
+      .setBody().constant('Hello')
+      .process {
+        it.in.headers['CamelCaffeineAction'] = 'PUT'
+        it.in.headers['CamelCaffeineKey'] = 1
+      }
+      .toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
+      .log('Result of Action ${header.CamelCaffeineAction} with key ${header.CamelCaffeineKey} is: ${body}')
+      .setBody().constant(null)
+      .process {
+        it.in.headers['CamelCaffeineAction'] = 'GET'
+        it.in.headers['CamelCaffeineKey'] = 1
+      }
+      .toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
+      .log('Result of Action ${header.CamelCaffeineAction} with key ${header.CamelCaffeineKey} is: ${body}')
+      .setBody().constant(null)
+      .process {
+        it.in.headers['CamelCaffeineAction'] = 'INVALIDATE'
+        it.in.headers['CamelCaffeineKey'] = 1
+      }
+      .toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
+      .log('Invalidating entry with key ${header.CamelCaffeineKey}')
+      .setBody().constant(null)
+      .process {
+        it.in.headers['CamelCaffeineAction'] = 'GET'
+        it.in.headers['CamelCaffeineKey'] = 1
+      }
+      .toF('caffeine-cache://%s?cache=#caffeineCache', 'test')
+      .log('The Action ${header.CamelCaffeineAction} with key ${header.CamelCaffeineKey} has result? ${header.CamelCaffeineActionHasResult}');