数据读写
写入文件
type toFile
把消息体写入本地文件(camel-file 内置)
使用说明
要点:把消息体写入本地文件。fileName 支持 Simple,例如按 header 动态命名;fileExist 默认 Override。
属性
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
path目录 |
文本 | 必填 | — | /data/outbox |
fileName文件名 |
文本 | 可选 | — | ${header.CamelFileName} 或 order-${header.id}.json |
charset字符集 |
文本 | 可选 | — | |
fileExist文件已存在时 |
枚举 | 可选 | Override |
|
append追加写入 |
布尔 | 可选 | false |
示例流程
可直接保存为 demo-toFile.json 并部署;非入口节点默认套了一个 REST 入口。
{
"id": "demo-toFile",
"desc": "写入文件 示例",
"group": "示例/数据读写",
"schemaVersion": 1,
"nodes": [
{
"id": "n1",
"type": "rest",
"props": {
"method": "POST",
"path": "/demo/toFile",
"desc": "示例入口"
}
},
{
"type": "toFile",
"props": {
"path": "./data/out",
"fileName": "demo-${header.id}.txt",
"charset": "UTF-8",
"fileExist": "Override"
},
"id": "n1"
}
]
}
curl -X POST 'http://localhost:8086/flow' \
-H 'Content-Type: application/json' \
-H 'X-Flow-Token: change-me' \
--data-binary @demo-toFile.json
调用方式
curl -X POST 'http://localhost:8086/demo/toFile' \
-H 'Content-Type: application/json' \
-d '{"id":1001,"message":"hello"}'