sofa 的webhook实际上就是将graphql 的subscription 进行了扩展,当接受到sub 请求的时候
再作一次http 的转发处理,方便rest api 的访问html
环境仍是使用的docker-compose ,之前的代码,只是添加了一个webhook 的容器镜像
能够参考: http://www.javashuo.com/article/p-vysuzxim-my.htmlgit
version: "3" services: api: build: ./ image: dalongrong/sofa-graphql2rest ports: - "4000:4000" webhook: image: jeffail/benthos volumes: - "./configs/webhook.yaml:/benthos.yaml" ports: - "4195:4195"
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 up -d
{ "subscription":"sub schema name ", "variables":" some field just for filter data", "url": "the webhook address" }
使用curl 请求github
curl -X POST \ http://localhost:4000/webhook \ -H 'Content-Type: application/json' \ -H 'Postman-Token: f2098fda-1108-4981-83b4-7eae3f3828c8' \ -H 'cache-control: no-cache' \ -d '{ "subscription":"onBook", "url":"http://webhook:4195" }'
返回数据
包含了webhook 的idweb
curl -X POST \ http://localhost:4000/webhook \ -H 'Content-Type: application/json' \ -H 'Postman-Token: f2098fda-1108-4981-83b4-7eae3f3828c8' \ -H 'cache-control: no-cache' \ -d '{ "subscription":"onBook", "url":"http://webhook:4195" }' {"id":"2de735c3-5698-4cdd-9986-1941d1e20c88"}
webhook_1 | get webhook message: {"data":{"onBook":{"id":"23337599919478412","title":"dalongdemo"}}}
sofa 的设计仍是很不错的,给与咱们一个反向的操做,通常咱们的方式是rest2graphql ,可是这个是graphql2rest 同时提供了很不错的
功能支持docker
https://github.com/Urigo/sofa
https://github.com/rongfengliang/sofa-graphql2rest-docker-composejson