Run your first Apache Camel route: log timer messages with the CLI and YAML
Apache Camel is an open-source integration framework that defines message flows between systems as routes. This guide uses the Camel CLI to log messages generated by a timer, with no broker or account. The example follows the Camel 4.18.x LTS component documentation; the CLI installation guide was checked on 2026-11-20.
Apache Camel is an open-source integration framework that defines message flows between systems as routes. This guide uses the Camel CLI to log messages generated by a timer, with no broker or account. The example follows the Camel 4.18.x LTS component documentation; the CLI installation guide was checked on 2026-11-20.
Prerequisites and scope
The CLI installer requires Java 21 or later. On Windows PowerShell, the official guide offers irm https://camel.apache.org/install.ps1 | iex; users who already have JBang can run jbang app install camel@apache/camel. The default installer selects the latest release; the guide also describes selecting LTS or a pinned version. Check your organization’s installation policy and version first. The CLI may need internet access or Maven proxy/mirror settings to download dependencies on first use.
camel versionIf the command prints a Camel version, the CLI is discoverable. If not, check the install location and PATH, then open a new terminal.
Create a YAML route
In a working directory, create hello.yaml with:
- route:
id: hello-timer
from:
uri: timer:tick?period=1000
steps:
- setBody:
expression:
constant:
expression: "Hello from Camel!"
- log:
message: "## كيف يعمل cache-aside؟
1. يبحث التطبيق عن مفتاح في الذاكرة المؤقتة.
2. عند العثور عليه يعيد القيمة.
3. عند غيابه أو انتهاء صلاحيته يقرأ مخزن البيانات الأصلي.
4. يحفظ النتيجة في الذاكرة المؤقتة ثم يعيدها.
5. عند الكتابة يحدّث المصدر أولًا ثم يحذف المفتاح المقابل؛ وتعيد القراءة التالية تحميله.
ينسّق التطبيق هذه الخطوات ولا يحمّل إلا العناصر المطلوبة. قد يرى القارئ قيمة قديمة لفترة قصيرة قبل الإبطال، أو يحدث إخفاق في الذاكرة بعد الحذف. توثق Microsoft ترتيب تحديث المصدر ثم الإبطال. ([Microsoft Cache-Aside](https://learn.microsoft.com/en-gb/azure/architecture/patterns/cache-aside)، [AWS Caching strategies](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Strategies.html))
## ما البيانات المناسبة وكيف تحدد TTL؟
انظر في البيانات كثيرة القراءة، الأقل تغييرًا، والتي يمكن قبول تقادمها لفترة محدودة. قد لا تستفيد البيانات المتغيرة باستمرار أو قليلة الإصابة كثيرًا. قد لا تناسب البيانات الحساسة أو المستخدمة في قرارات الأمان ذاكرة مشتركة؛ اقرأ المصدر أو طبّق حدودًا صارمة للمستخدم/المستأجر. ([Microsoft Cache-Aside](https://learn.microsoft.com/en-gb/azure/architecture/patterns/cache-aside))
مدة البقاء (TTL) تحدد وقت انتهاء الإدخال. قصرها كثيرًا يسبب إخفاقات متكررة؛ وطولها كثيرًا يطيل تقديم القيم القديمة. اخترها وفق وتيرة التغيير والتقادم المقبول وكلفة قراءة المصدر وإمكان الإبطال عند الكتابة. تحدد TTL حدًا لعمر القيمة، لكنها لا تضمن اتساقًا فوريًا إذا عدّلت أنظمة أخرى المصدر.
## كيف تتعامل مع الكتابة والإخفاقات المتزامنة وتعطل الذاكرة؟
- حدّث المصدر بنجاح ثم أبطل المفتاح. حذف الذاكرة أولًا قد يجعل طلبًا فاشلًا يعيد تحميل القيمة القديمة من المصدر. خطط للأعطال بين العمليتين وإعادة المحاولة وTTL قصير؛ لا يضمن cache-aside اتساقًا كاملًا. ([Microsoft Cache-Aside](https://learn.microsoft.com/en-gb/azure/architecture/patterns/cache-aside))
- قد تستعلم طلبات متزامنة كثيرة عن مفتاح شائع منتهي الصلاحية من المصدر دفعة واحدة (cache stampede). ادرس التحميل المنفرد أو القفل أو التحديث قبل الانتهاء وفق الحمل والاتساق. لم يتحقق المقال من تطبيق قفل بعينه. ([Redis cache-aside](https://redis.io/docs/latest/develop/use-cases/cache-aside/))
- قرر هل يؤدي تعطل الذاكرة إلى الرجوع للمصدر أم إلى خطأ مضبوط. الرجوع بلا حدود قد يرهق قاعدة البيانات؛ خطط للمهلات وحدود التزامن وقاطع الدائرة والسعة. تعتمد السلامة على السعة الفعلية للمصدر. ([Microsoft Cache-Aside](https://learn.microsoft.com/en-gb/azure/architecture/patterns/cache-aside))
- قد تختلف الذاكرة المحلية الخاصة بين النسخ. توحّد الذاكرة المشتركة النسخ لكنها تضيف اعتمادًا على الشبكة والتشغيل.
## كيف تتحقق من فائدة التخزين المؤقت؟
قبل الإطلاق قارن خط أساس بلا ذاكرة مع المدخلات نفسها عند استخدامها. قِس الإصابات والإخفاقات واستدعاءات المصدر وتأخير القراءة والذاكرة والأخطاء. إن قلّت الإصابات أو لم تنخفض الاستدعاءات، راجع المفاتيح وTTL واختيار البيانات. اختبر استمرار العمل من المصدر عند إفراغ عقد التخزين أو استبدالها. تذكر AWS أن التحميل الكسول يستمر بعد فقد عقدة، لكن التأخير وقراءات المصدر تزداد أثناء إعادة التعبئة. ([AWS Caching strategies](https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/Strategies.html))
إذا أدى حذف الذاكرة إلى نتائج خاطئة أو فقد بيانات دائمة، فهي تُستخدم خطأً كمصدر للحقيقة. أضف التخزين المؤقت بعد تأكيد مشكلة فعلية في التأخير أو الحمل وتحديد التقادم المقبول وسلوك الأعطال."A YAML file starts with a - route: entry. from names the input endpoint and steps lists processing steps in order. timer:tick?period=1000 creates an exchange every second. setBody sets a constant body and log records it. This example does not send data to an external service.
camel run hello.yamlAfter the startup log, Hello from Camel! should appear repeatedly. Press Ctrl+C to stop. Repeated output is expected because the timer keeps firing.
Verify and troubleshoot
If `camel` is not found, check that installation completed and the executable directory is on PATH.
For a Java error, use `java -version` and confirm Java 21 or later.
If the first dependency download fails, check the network and Maven proxy/mirror settings, then retry.
For a YAML error, check indentation, colons, and the filename. You can create a fresh scaffold with `camel init hello.yaml` and compare it.
If no message appears, inspect the startup error and full output to see whether the route started. Check documentation and component options for your installed version.
A Camel route begins at an input endpoint, passes through processing steps, and continues to an output endpoint. For a real integration, replace the timer and log with suitable components, then design their dependencies, authentication, retries, error handling, and delivery guarantees separately. A route alone does not guarantee these operational properties.
References
[Camel CLI getting started](https://camel.apache.org/manual/camel-jbang-getting-started.html)
[Camel routes](https://camel.apache.org/manual/routes.html)
[Timer component 4.18.x](https://camel.apache.org/components/4.18.x/timer-component.html)
[Log component 4.18.x](https://camel.apache.org/components/4.18.x/log-component.html)