上篇说了使用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/

 
 
 
 

ballerina 学习 三十一 扩展开发(二)的更多相关文章

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

    ballerina 主要是分为两大类 基于ballerina 语言开发的,一般是客户端的connector 使用java语言开发的(类似的基于jvm的都可以),一般是注解以及进行构件生成 baller ...

  2. “全栈2019”Java第三十一章:二维数组和多维数组详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  3. firefox扩展开发(二):用XUL创建窗口控件

    firefox扩展开发(二):用XUL创建窗口控件 2008-06-11 16:57 1.创建一个简单的窗口 <?xml version="1.0"?> <?xm ...

  4. Java开发学习(三十一)----Maven属性与版本管理

    一.属性 1.1 问题分析 如下图所示 你会发现,如果现在想更新Spring的版本,你会发现依然需要更新多个jar包的版本,这样的话还是有可能出现漏改导致程序出问题,而且改起来也是比较麻烦. 问题清楚 ...

  5. ballerina 学习 三十二 编写安全的程序

      ballerina编译器已经集成了部分安全检测,在编译时可以帮助我们生成错误提示,同时ballerina 标准库 已经对于常见漏洞高发的地方做了很好的处理,当我们编写了有安全隐患的代码,编译器就已 ...

  6. java web学习总结(六) -------------------servlet开发(二)

    一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些 ...

  7. javaweb学习总结(六)——Servlet开发(二)

    一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些 ...

  8. javaweb学习总结(六)——Servlet开发(二)(转)

    转载自 http://www.cnblogs.com/xdp-gacl/p/3763559.html 一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文 ...

  9. (转)MyBatis框架的学习(三)——Dao层开发方法

    http://blog.csdn.net/yerenyuan_pku/article/details/71700957 使用MyBatis开发Dao层,通常有两个方法,即原始Dao开发方法和Mappe ...

随机推荐

  1. Sqlite3,维基百科中的练习:

    https://en.wikibooks.org/wiki/SQL_Exercises/The_computer_store 两个相连的表格 Manufactures: code, name prod ...

  2. 安装 tensorflow 时遇到 OSError: [Errno 1] Operation not permitted 的解决办法

    Installing collected packages: numpy, scipy, six, pyyaml, Keras, opencv-python, h5py, html5lib, blea ...

  3. scrapy微信爬虫使用总结

    scrapy+selenium+Chrome+微信公众号爬虫 概述 1.微信公众号爬虫思路: 参考:记一次微信公众号爬虫的经历 2.scrapy框架图 3.scrapy经典教程 参考: python ...

  4. POJ-1511 Invitation Cards (双向单源最短路)

    Description In the age of television, not many people attend theater performances. Antique Comedians ...

  5. yum安装docker报 No package docker available错误

    解决方案: yum install epel-release 然后再安装 CentOS6 yum install http://mirrors.yun-idc.com/epel/6/i386/epel ...

  6. django url 使用总结

    1 无参数情况 配置URL及其视图如下: (r'^hello/$', hello) def hello(request): return HttpResponse("Hello World& ...

  7. vs2015 企业版、专业版如何破解(秘钥)

    安装完vs2015 企业版后,在菜单帮助---注册产品,显示产品试用期30天,怎么破解呢? 一.破解秘钥 企业版    HM6NR-QXX7C-DFW2Y-8B82K-WTYJV 专业版    HMG ...

  8. PHP:第三章——PHP中的可变函数

    PHP中的可变函数 <?php header("Content-Type:text/html;charset=utf-8"); function F(){ echo '999 ...

  9. hadoop kafka install (6)

    reference: http://kafka.apache.org/quickstart  http://dblab.xmu.edu.cn/blog/1096-2/ hadoop@iZuf68496 ...

  10. Java——File类成员方法

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...