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