ballerina 学习二十三 扩展ballerina

扩展ballerina 目前有三种方式:

  • 扩展client connector的包 (数据库访问,基础设施,api)
  • 扩展server listenner 绑定为不同的协议
  • 添加新的注解到ballerina 源码进行编译并修改运行软件包

创建client connector

client connector 由开发人员在创建endpoint 时进行初始化,你自己可以开发自己的connector 并发布到私服,或者照中央仓库

  • 创建 client connector 的步骤

参考例子 https://github.com/muthulee/package-twilio-super-simple/blob/master/twilio/twilio_endpoint.bal
https://github.com/muthulee/package-client-endpoint-guide/tree/master/clientendpointsample

a.  创建包
b.  创建一个对象(object) 包含init()  && getClient() function
c.  实现init() function  ,这个方法是在用户(开发人员)初始化endpoint 的时候被调用的
d.  实现getClient()  function ,这个方法是在connection 被返回的时候调用
e.  构建包&&push 到仓库

创建自定义注解&& builder extension

  • 注解说明:
 注解实际上就是一段代码片段,可以附加到ballerina 代中,其中包含了一些关联的元数据信息,
 注解不可以执行,只是可以用来修改执行代码的一些行为
 注解可以被附加到 Services Resources Functions Connectors Actions (of Connectors) TypeMappers Structs Constants Annotations Object Record Enum Transformer Endpoint
java 代码,在ballerina 的编译阶段进行执行

参考资料

https://github.com/muthulee/package-twilio-super-simple/blob/master/twilio/twilio_endpoint.bal
https://github.com/muthulee/package-client-endpoint-guide/tree/master/clientendpointsample
https://github.com/ballerinax/hello

猜你喜欢

转载自www.cnblogs.com/rongfengliang/p/9126896.html