hasura graphql server event trigger 试用

hasura graphql server 是一个很不错的graphql 引擎,当前版本已经支持event triiger 了
使用此功能我们可以方便的集成webhook功能,实现灵活,稳定,快捷的消息驱动的应用

webhook 使用benthos ,简单例子参考 https://www.cnblogs.com/rongfengliang/p/9569811.html

一张参考图

环境搭建

使用docker-compose

  • docker-compose 文件
version: '3.6'
services:
  postgres:
    image: postgres
    ports:
    - "5432:5432"
    environment:
    - "POSTGRES_PASSWORD:dalong"
    volumes:
    - ./db_data:/var/lib/postgresql/data
  benthos:
    image: jeffail/benthos
    volumes:
    - "./configs/webhook.yaml:/benthos.yaml"
    ports:
    - "4195:4195"
  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-alpha16
    ports:
    - "8080:8080"
    depends_on:
    - "postgres"
    environment:
    - "POSTGRES_PASSWORD:dalong"
    command: >
      /bin/sh -c "
      graphql-engine --database-url postgres://postgres:dalong@postgres:5432/postgres serve --enable-console;
      "
  • benthos webhook 配置
    webhook.yaml 文件
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

启动&&运行

  • 启动graphql server&& benthos stream webhook
docker-compose up -d
  • 效果

测试event trigger

  • 添加基本数据
  • 添加evnet triiger

    具体webhook 地址参考自己电脑ip,我使用docker-compose 的service

  • 添加数据测试

说明

类似的支持框架有prisma 都是挺不错的,但是hasura graphql 看起来潜力是无限的,只是在crud 这方便如果能扩展到不止pg 就更好了。

参考资料

https://www.cnblogs.com/rongfengliang/p/9569811.html
https://hasura.io/
https://github.com/Jeffail/benthos/tree/master/resources/docker/streams
https://github.com/rongfengliang/hasura-graphql-event-benthos

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

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

导航

< 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
点击右上角即可分享
微信分享提示