zoukankan      html  css  js  c++  java
  • ballerina 学习一 基本项目安装试用

    ballerina介绍
       建议参考这篇文章: https://mp.weixin.qq.com/s/DqdlOhquqMaGOJf26lANPw
     
    1. 安装
    直接下载对应操作系统的二进制文件即可,同时官方也提供了linux 操作系统对应的各种发行包(deb, rpm)
    
    参考地址:
    https://ballerina.io/downloads/
    2. 基本代码
    // Packages contain functions, annotations and connectors.
    // This package is referenced by ‘http’ namespace in the code
    // body.
    import ballerina/http;
    import ballerina/io;
    
    // A service is a network-accessible API. This service
    // is accessible at '/hello', and bound to a the listener on
    // port 9090. `http:Service`is a connector in the `http`
    // package.
    service<http:Service> hello bind { port: 9090 } {
    
      // A resource is an invokable API method.
      // Accessible at '/hello/sayHello’.
      // 'caller' is the client invoking this resource.
      sayHello (endpoint caller, http:Request request) {
    
        // Create object to carry data back to caller.
        http:Response response = new;
    
        // Objects have function calls.
        response.setTextPayload("Hello Ballerina!
    ");
    
        // Send a response back to caller.
        // Errors are ignored with '_'.
        // ‘->’ is a synchronous network-bound call.
        _ = caller -> respond(response);
      }
    }
    备注:第一眼看上去,代码还是很清晰的,也比较简单,比较完整的代码可以参考
    https://github.com/ballerina-platform/ballerina-examples
    3. 运行
    ballerina  run  app.bal
    
    备注: 很简单,就是可能启动会稍微有点慢
    4. 访问
    上面的代码已经说明了访问方式
    http://hostip:port(9090)/hello/sayHello
    
    结果:
    
    HTTP/1.1 200 OK
    content-type: text/plain
    content-length: 17
    server: ballerina/0.970.1
    date: Mon, 14 May 2018 10:01:38 +0800
    
    Hello Ballerina!
    5. 总结
    从官方介绍的特性来说还是很不错的,同时开发团队也提供了主流编辑器的可用插件,vscode idead 。。。
    开发也比较简单,总的来说还是比较看好,具体的性能测试,目前暂时没有看到相关的结果,比较期待。
    6. 参考资料
    https://github.com/rongfengliang/ballerina-basic-demo
    https://github.com/ballerina-platform/ballerina-examples
    https://ballerina.io/
  • 相关阅读:
    C#:将子Form加入父Form中
    C#:简单线程样例
    C#:实现接口中定义的事件
    easyui设置界面的高度自适应
    JQuery
    vim常用命令(iOS)
    Linux的IO性能监控工具iostat详解
    php多线程抓取信息测试例子
    使用Gitosis搭建Git服务器
    CentOS 6.4 搭建git 服务器
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/9034726.html
Copyright © 2011-2022 走看看