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 2018/10/01 15:11:31 UTC

[camel-k] 01/01: Added an example of binding object in Camel registry in groovy

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

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

commit 0c15ccbe1e150cdda352731890eb305f38e1bc4c
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}');