Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "ai/docling-langchain4j-rag",
"title": "Document Analysis with Docling and LangChain4j RAG",
"description": "Documents dropped in a directory are converted by a running Docling service, chunked and summarised by a local Ollama model through langchain4j-chat, and written to an output directory; an HTTP endpoint answers questions against the converted documents.",
"description": "Documents dropped in a directory are converted to Markdown by a Docling service, analysed by a local Ollama model through langchain4j-chat, and written as a report to an output directory; an HTTP endpoint answers questions against the latest document.",
"level": "ai",
"teaches": {
"components": [
Expand Down Expand Up @@ -42,6 +42,8 @@
"docling",
"ollama"
],
"needs": "a local model",
"ciSkip": true,
"order": 4
},
{
Expand Down Expand Up @@ -88,6 +90,7 @@
"infraServices": [
"ollama"
],
"needs": "a local model",
"ciSkip": true,
"order": 1
},
Expand Down Expand Up @@ -164,6 +167,8 @@
"pii-redaction.camel.yaml",
"pii.schema.json"
],
"needs": "an OpenAI-compatible API",
"ciSkip": true,
"order": 3
},
{
Expand Down Expand Up @@ -504,7 +509,7 @@
"inbox",
"archive"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -555,7 +560,7 @@
"rest",
"client"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -601,7 +606,7 @@
"http",
"platform-http"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -686,7 +691,7 @@
"client",
"contract"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -736,7 +741,7 @@
"rest",
"contract"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -818,7 +823,7 @@
"retry",
"dead-letter"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand All @@ -827,8 +832,7 @@
"error-handling.camel.yaml",
"orders/order-1001.json",
"orders/order-1002.json",
"orders/order-1003.json",
"parked/order-1003.json"
"orders/order-1003.json"
],
"order": 1
},
Expand Down Expand Up @@ -856,7 +860,7 @@
],
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": false,
"hasCitrusTests": true,
"files": [
"README.md",
"application.properties",
Expand Down Expand Up @@ -885,7 +889,7 @@
],
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": false,
"hasCitrusTests": true,
"files": [
"Greeter.java",
"README.md",
Expand Down Expand Up @@ -920,7 +924,7 @@
],
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": false,
"hasCitrusTests": true,
"files": [
"README.md",
"splitter.camel.yaml"
Expand Down Expand Up @@ -948,7 +952,7 @@
],
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": false,
"hasCitrusTests": true,
"files": [
"README.md",
"application.properties",
Expand Down Expand Up @@ -987,7 +991,7 @@
"aggregator",
"batch"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1027,7 +1031,7 @@
"choice",
"routing"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1069,7 +1073,7 @@
"filter",
"multicast"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1110,7 +1114,7 @@
"splitter",
"split"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1145,7 +1149,7 @@
"cron",
"schedule"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1180,7 +1184,7 @@
"bean",
"json"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1215,7 +1219,7 @@
"profiles",
"configuration"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1407,7 +1411,7 @@
"file",
"transformation"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1448,7 +1452,7 @@
"json",
"transformation"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1489,7 +1493,7 @@
"validation",
"dependencies"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1530,7 +1534,7 @@
"jsonpath",
"transformation"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1567,7 +1571,7 @@
"jackson",
"transformation"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down Expand Up @@ -1599,7 +1603,7 @@
"xslt",
"transformation"
],
"bundled": false,
"bundled": true,
"requiresDocker": false,
"hasCitrusTests": true,
"files": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# File processing

The courier's billing system drops invoices into an inbox directory. Each invoice is checked, archived under a
month directory and moved to `done`; a bad one goes to `failed`; a file that is not an invoice is left alone.
The first route plays the courier: it copies the five files in `samples/` into `inbox/`.

## What you will see

```text
INFO ... file-processing.camel.yaml:47 : Invoice INV-2001 for ORD-1001: 49.4 EUR, archived as 2026-09/invoice-2001.json
INFO ... file-processing.camel.yaml:47 : Invoice INV-2002 for ORD-1002: 28.5 EUR, archived as 2026-09/invoice-2002.json
WARN ... file-processing.camel.yaml:11 : Invoice invoice-2003.json rejected: Validation failed for Predicate[bodyOgnl([amount]) > 0]. ...
ERROR ... DefaultErrorHandler : Failed delivery for (MessageId: ...). Exhausted after delivery attempt: 1 caught: ...PredicateValidationException: ...
WARN ... GenericFileOnCompletion : Rollback file strategy: ...GenericFileRenameProcessStrategy
INFO ... file-processing.camel.yaml:47 : Invoice INV-2004 for ORD-1003: 53.45 EUR, archived as 2026-09/invoice-2004.json
```

## Install Camel CLI

Install [JBang](https://www.jbang.dev/download/) and the Camel CLI as described in the
[root README](../../README.md#install-the-camel-cli); `camel --version` confirms the install.

## Run it

```shell
camel run *
```

Afterwards the directories tell the story: `inbox/done/` holds the three good invoices, `inbox/failed/` the
rejected one, `archive/<year-month>/` copies of the good ones, and `inbox/note-2005.txt` is still where it was.
Delete `inbox/` and `archive/` to run it again.

## How it works

- The `courier` route is a `file` consumer on `samples/` with `noop: true` writing to `file:inbox`, a copy.
- The `invoices` route is the lesson: a `file` consumer on `inbox/` with `include: .*\.json`, so the driver's
note is never picked up; `move: done` for files that went through, `moveFailed: failed` for files whose
exchange failed. Both are directories relative to the inbox.
- `validate` throws a `PredicateValidationException` when the amount is not positive; the `onException` logs a
warning without a stack trace and lets the exception through, which is what makes the consumer use `moveFailed`.
Had it set `handled: true`, the file would have been moved to `done` as if it had succeeded.
- The archive copy uses a `fileName` expression with `${date:now:yyyy-MM}` for the directory and `${file:name}`
for the name; the file component creates directories as needed.

## Build it step by step

1. A `file` route on `inbox` that logs `${file:name}`; drop a file in and see it logged, then note the
`.camel` directory the consumer moved it to by default.
2. Add `move: done` and `include: .*\.json`, drop the note in and see it ignored.
3. Add the `courier` route so the samples arrive by themselves, and `unmarshal` and log the invoice.
4. Add `validate` and `moveFailed: failed`, then the `onException` to tidy the log.

## Try changing

- Add `idempotent: true` with `idempotentKey: ${file:name}` and drop the same invoice twice.
- Replace `move: done` with `delete: true`.
- Point `archive` at a `sftp:` endpoint; the `ftp` example on the next rung shows how.

## Integration testing

The example comes with a test in the [Citrus](https://citrusframework.org/) YAML DSL,
`test/file-processing.citrus.it.yaml`, which the Camel CLI runs:

```shell
camel test run test/file-processing.citrus.it.yaml
```

The test starts the routes and verifies the archived and rejected lines.

## Help and contributions

If you hit any problem using Camel or have some feedback, then please
[let us know](https://camel.apache.org/community/support/).

We also love contributors, so
[get involved](https://camel.apache.org/community/contributing/) :-)

The Camel riders!
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
Loading
Loading