事件网关蟒蛇

event-gateway-sdk的Python项目详细描述


事件网关python sdk

用于与Event Gateway交互的python库。

内容

背景

这是python sdk,用于与Event Gateway交互,后者是将事件连接到无服务器函数的中心。

安装

pip install event-gateway-sdk

用法

使用emit命令向事件网关发出CloudEvent负载。此事件将由订阅您的事件的任何函数接收。

fromeventgatewayimportEventGatewayeg=EventGateway(url="https://mytenant-myapp.slsgateway.com")cloudEvent={"eventType":"user.created","cloudEventsVersion":"0.1","source":"/services/users","data":{"userId":"foo","userName":"bar"}}eg.emit(cloudEvent=configData,path="/user/send-mail-user")

emit()函数有三个参数:

  • 是一个有效的cloudevent,
  • 一个path,它是与函数关联的路径(默认值:/
  • 表示发送到网关的头的headers对象(默认值:{"Content-type": "application/json"}

函数返回一个请求对象。如果您的事件附加了sync订阅,则fetch响应将具有订阅的状态代码和正文。否则,响应将返回一个带有空正文的202 Accepted状态代码。

构造函数

在上面的示例中,我们使用serverless,inc.提供的hosted Event Gateway中的应用程序url创建了一个事件网关客户机。

您还可以将事件网关sdk与自己的自托管事件网关一起使用。下面列出了构造函数的详细信息。

参数

  • url-string-可选,事件api url,默认值:http://localhost:4000
  • space-string-可选,空间名称,默认值:default
  • configurationUrl-string-可选,配置API URL。默认情况下,它与url相同,但具有4001端口
  • connectorUrl-string-可选,连接器api url。默认情况下,它与url相同,但使用4002端口
  • accessKey-string-可选,宿主事件网关的访问密钥。在托管事件网关上使用配置API方法需要访问密钥

示例

fromeventgatewayimportEventGatewayeg=EventGateway(url="https://mytenant-myapp.slsgateway.com",space="user")

可用功能

检查连接

用于检查与事件网关的连接(使用/v1/status端点)。

示例

fromeventgatewayimportEventGatewayeg=EventGateway()ifeg.checkConnection():print("Connection succesfull")else:print("Issue while connecting")

打印配置

用于打印当前配置的实用程序。

示例

fromeventgatewayimportEventGatewayeg=EventGateway()eg.printConfig()

创建事件类型

函数创建事件类型。

示例

fromeventgatewayimportEventGatewayeventtype={"name":"http.request"}eg=EventGateway()eg.createEventType(eventtype)

获取事件类型

函数获取事件类型。

示例

fromeventgatewayimportEventGatewayeg=EventGateway()eg.getEventType("user.created")

GetAllEventType

函数获取所有事件类型。

示例

fromeventgatewayimportEventGatewayeg=EventGateway()eg.getAllEventType()

createFunction

函数创建函数触发器。

示例

fromeventgatewayimportEventGatewayfunction={"functionId":"new-user","type":"http","provider":{"url":"http://myapp.com/user/new"}}eg=EventGateway()eg.createFunction(function)

GetFunction

函数来获取函数。

示例

fromeventgatewayimportEventGatewayeg=EventGateway()eg.getFunction("new-user")

GetAllFunction

函数来获取所有函数。

示例

fromeventgatewayimportEventGatewayeg=EventGateway()eg.getAllFunction()

创建订阅

函数订阅函数。

示例

fromeventgatewayimportEventGatewaysubscription={"functionId":"new-user","event":"http","method":"POST","path":"/user/new","eventType":"http.request","type":"async"}eg=EventGateway()eg.createSubscription(subscription)

获取订阅

函数获取订阅。

示例

fromeventgatewayimportEventGatewayeg=EventGateway()eg.getSubscription("YXN5bmMsaHR0cC5yZXF1ZXN0LG5ldy11c2VyLW9wZW5wYWFzLCUyRmppcmE")

GetAllSubscription

函数获取所有订阅。

示例

fromeventgatewayimportEventGatewayeg=EventGateway()eg.getAllSubscription()

贡献

待定

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么我们不能将ArrayList<Integer>传递给具有(Integer…)的方法参数   java Spring RestTemplate映射JSON对映射的响应引发不匹配的PutException   在系统中找到java Selenium元素,但在Jenkins中未找到   java在Android中使用JavaMail API发送电子邮件,而不使用默认/内置应用程序   数组如何在Java数据结构中同时存储数字和相应的单词?   为什么“+”运算符未定义?JAVA   java如何在游戏中添加高分系统?   java在球门碰撞中区分球和球员   java如何使用SpringSecurity4.0.1使用Auth令牌实现Rest完整Web服务。释放   java如何解决这个错误:Android资源链接失败?   java多线程文件处理和数据库批插入   导致Tomcat失败的java无用块线程   java主线程做了太多的工作,尽管我使用了异步线程(laggy UI)   在Java FX 2.0中滚动锚定节点时,锚定始终可见?   java使用EJB3中的客户机jar和设计模式