当前位置: 首页 > news >正文

ballerina 学习 三十一 扩展开发(二)

上篇说了使用ballerina 语言开发扩展模块,对于注解类型的我们是需要使用java 语言进行
开发的

官方提供了一个hello 的demo可以参考 https://github.com/ballerinax/hello

注解扩展插件的使用

这个注解是调用方法之后,会生成一个文本文件

import ballerina/http;
import ballerinax/hello;

@hello:Greeting{
  salutation: "Guten Tag!"
}
service<http:Service> helloWorld bind {port:9091} {
   sayHello(endpoint outboundEP, http:Request request) {
       http:Response response = new;
       response.setTextPayload("Hello, World from service helloWorld ! \n");
       _ = outboundEP->respond(response);
   }
}

开发细节

开发需要的环境是jdk8 同时需要maven ,构建完成之后,用户需要安装扩展,为了测试我使用的是直接clone 代码

  • clone 代码
git clone https://github.com/ballerinax/hello.git
  • 导入项目
  • 构建&&测试
mvn clean package 
  • 构建结果
  • 说明
    hello-extension-0.980.0.jar 文件需要放ballerian 的 /bre/lib,同时repo 包需要解压,并放到
  • 测试
import ballerina/http;
import ballerinax/hello;

@hello:Greeting{salutation : "Guten Tag!"}
@http:ServiceConfig {
    basePath:"/dalong"
}
service<http:Service> helloWorld bind {port:9091} {
    sayHello(endpoint outboundEP, http:Request request) {
        http:Response response;
        response.setJsonPayload("Hello, World from service helloWorld ! \n");
        // Send response to the client.
        _ = outboundEP->respond(response);
    }
}
  • 效果

    会生成一个hello_world.txt 文件

Guten Tag!

说明

以下为代码的结构

  • 因为开发会有依赖的打包,官方的方式是使用maven 的maven-shade-plugin ,好多mapreduce 以及开发打包也是类似的
    详细使用说明,可以参考https://ballerina.io/learn/how-to-extend-ballerina/
  • 主要的处理代码是实现 AbstractCompilerPlugin 其中包含了具体的代码处理,以及逻辑
实现 init process codeGenerated 方法,docker 扩展是一个比较有价值的参考项目

参考资料

https://github.com/ballerinax/docker
https://github.com/ballerinax/hello
https://ballerina.io/learn/how-to-extend-ballerina/

 
 
 
 

相关文章:

  • ES7 之 Async/await 的使用(改进 Promise 链式操作)
  • LAMP+Postfix+Dovecot+Postfixadmin搭建邮件管理系统(三)
  • hadoop入门学习教程--DKHadoop完整安装步骤
  • webpack 4.x一起学习(二)
  • String类的常用方法详解
  • web开发原则
  • 视频文件应该怎样进行无损压缩
  • 删除小脚本 srm
  • python爬虫系列(2.1-requests库的基本的使用)
  • 我的原型链家族将要崛起。
  • 一步步实现web程序信息管理系统之二--后台框架实现跳转登陆页面
  • 基于CentOS设置和使用Yum软件仓库
  • 深入浏览器事件循环的本质
  • 镶锆石、侧边指纹、双屏翻盖机,三星的这款2万块手机,只有土豪能懂
  • 2018自媒体运营吸粉3大途径
  • .pyc 想到的一些问题
  • [Vue CLI 3] 配置解析之 css.extract
  • [译] 怎样写一个基础的编译器
  • Akka系列(七):Actor持久化之Akka persistence
  • Apache Zeppelin在Apache Trafodion上的可视化
  • CSS 三角实现
  • django开发-定时任务的使用
  • emacs初体验
  • flutter的key在widget list的作用以及必要性
  • JavaScript的使用你知道几种?(上)
  • laravel with 查询列表限制条数
  • mongo索引构建
  • MySQL几个简单SQL的优化
  • php面试题 汇集2
  • RxJS: 简单入门
  • 基于阿里云移动推送的移动应用推送模式最佳实践
  • 简析gRPC client 连接管理
  • 前端相关框架总和
  • 提醒我喝水chrome插件开发指南
  • 跳前端坑前,先看看这个!!
  • 王永庆:技术创新改变教育未来
  • 我的业余项目总结
  • 《TCP IP 详解卷1:协议》阅读笔记 - 第六章
  • ​草莓熊python turtle绘图代码(玫瑰花版)附源代码
  • #!/usr/bin/python与#!/usr/bin/env python的区别
  • #中国IT界的第一本漂流日记 传递IT正能量# 【分享得“IT漂友”勋章】
  • $emit传递多个参数_PPC和MIPS指令集下二进制代码中函数参数个数的识别方法
  • (10)ATF MMU转换表
  • (4) openssl rsa/pkey(查看私钥、从私钥中提取公钥、查看公钥)
  • (pojstep1.3.1)1017(构造法模拟)
  • (二)PySpark3:SparkSQL编程
  • (附源码)计算机毕业设计ssm基于Internet快递柜管理系统
  • . Flume面试题
  • .NET 4 并行(多核)“.NET研究”编程系列之二 从Task开始
  • .NET delegate 委托 、 Event 事件,接口回调
  • .net oracle 连接超时_Mysql连接数据库异常汇总【必收藏】
  • .NET 使用配置文件
  • .NET 应用启用与禁用自动生成绑定重定向 (bindingRedirect),解决不同版本 dll 的依赖问题
  • .NET/C# 判断某个类是否是泛型类型或泛型接口的子类型
  • .Net高阶异常处理第二篇~~ dump进阶之MiniDumpWriter