benthos stream nats 集成试用

测试demo 来自官方例子

使用docker-compose 进行运行

nats docker-compose file

version: '3.3'
services:
  nats:
    image: nats
    ports:
      - "4222:4222"
      - "8222:8222"
      - "6222:6222"

benthos stream 配置

参考 https://github.com/Jeffail/benthos/tree/master/resources/docker/streams

  • 整体说明
    里面的例子就是数据从文件读取到nats 之后不同的消费者进行nats 消息消费,再到webhook,webhook 标准输出

  • 文件读取说明

    读取文件,之后到nats

input:
  type: read_until
  read_until:
    condition:
      type: static
      static: false
    input:
      type: file
      file:
        path: ./sample.json
    restart_input: true
pipeline:
  processors:
    - type: throttle
      throttle:
        period: 3s
output:
  type: nats
  nats:
    subject: benthos_messages
    urls:
      - nats://localhost:4222
  • nats 消费者(三个)
input:
  type: nats
  nats:
    subject: benthos_messages
    urls:
    - nats://localhost:4222
pipeline:
  processors:
    - type: filter
      filter:
        type: jmespath
        jmespath:
          query: |
            keys(@) | contains(@, 'title')
output:
  type: http_client
  http_client:
    url: http://localhost:4195/webhooks/post/customer1
    verb: POST
  • webhook 配置
input:
  type: broker
  broker:
    inputs:
      - type: http_server
        http_server:
          path: /post/customer1
        processors:
          - type: text
            text:
              operator: prepend
              value: "Customer 1 received: "
      - type: http_server
        http_server:
          path: /post/customer2
        processors:
          - type: text
            text:
              operator: prepend
              value: "Customer 2 received: "
      - type: http_server
        http_server:
          path: /post/customer3
        processors:
          - type: text
            text:
              operator: prepend
              value: "Customer 3 received: "
output:
  type: stdout

运行

  • docker-compose
dokcer-compose up -d
  • 启动benthos,基于文件stream 配置
benthos --streams --streams-dir ./configs

运行效果


修改sample.json 测试

参考资料

https://github.com/Jeffail/benthos/tree/master/resources/docker/streams

posted on   荣锋亮  阅读(637)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2017-09-01 kafka ksql && docker 安装试用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示