ballerina 学习二十七 项目k8s部署&& 运行

时间:2022-09-06 19:12:46

ballerina k8s 部署和docker 都是同样的简单,编写service 添加注解就可以了

参考项目 https://ballerina.io/learn/by-guide/restful-service/

项目准备

  • 项目代码
import ballerina/http;
import ballerinax/kubernetes; // 支持k8s 的注解
@kubernetes:Ingress {
hostname:"dalongrong",
name:"ballerina-guides-restful-service",
path:"/"
}
@kubernetes:Service {
serviceType:"NodePort",
name:"ballerina-guides-restful-service"
}
@kubernetes:Deployment {
image:"dalongrong/restful_service_k8s:v1.0",
name:"ballerina-guides-restful-service"
}
endpoint http:Listener listener {
port:9090
}; // Order management is done using an in memory map.
// Add some sample orders to 'ordersMap' at startup.
map<json> ordersMap; // RESTful service.
@http:ServiceConfig { basePath: "/ordermgt" }
service<http:Service> orderMgt bind listener { // Resource that handles the HTTP GET requests that are directed to a specific
// order using path '/order/<orderId>'.
@http:ResourceConfig {
methods: ["GET"],
path: "/order/{orderId}"
}
findOrder(endpoint client, http:Request req, string orderId) {
// Find the requested order from the map and retrieve it in JSON format.
json? payload = ordersMap[orderId];
http:Response response;
if (payload == null) {
payload = "Order : " + orderId + " cannot be found.";
} // Set the JSON payload in the outgoing response message.
response.setJsonPayload(untaint payload); // Send response to the client.
_ = client->respond(response);
} // Resource that handles the HTTP POST requests that are directed to the path
// '/order' to create a new Order.
@http:ResourceConfig {
methods: ["POST"],
path: "/order"
}
addOrder(endpoint client, http:Request req) {
json orderReq = check req.getJsonPayload();
string orderId = orderReq.Order.ID.toString();
ordersMap[orderId] = orderReq; // Create response message.
json payload = { status: "Order Created.", orderId: orderId };
http:Response response;
response.setJsonPayload(untaint payload); // Set 201 Created status code in the response message.
response.statusCode = 201;
// Set 'Location' header in the response message.
// This can be used by the client to locate the newly added order.
response.setHeader("Location", "http://localhost:9090/ordermgt/order/" +
orderId); // Send response to the client.
_ = client->respond(response);
} // Resource that handles the HTTP PUT requests that are directed to the path
// '/order/<orderId>' to update an existing Order.
@http:ResourceConfig {
methods: ["PUT"],
path: "/order/{orderId}"
}
updateOrder(endpoint client, http:Request req, string orderId) {
json updatedOrder = check req.getJsonPayload(); // Find the order that needs to be updated and retrieve it in JSON format.
json existingOrder = ordersMap[orderId]; // Updating existing order with the attributes of the updated order.
if (existingOrder != null) {
existingOrder.Order.Name = updatedOrder.Order.Name;
existingOrder.Order.Description = updatedOrder.Order.Description;
ordersMap[orderId] = existingOrder;
} else {
existingOrder = "Order : " + orderId + " cannot be found.";
} http:Response response;
// Set the JSON payload to the outgoing response message to the client.
response.setJsonPayload(untaint existingOrder);
// Send response to the client.
_ = client->respond(response);
} // Resource that handles the HTTP DELETE requests, which are directed to the path
// '/order/<orderId>' to delete an existing Order.
@http:ResourceConfig {
methods: ["DELETE"],
path: "/order/{orderId}"
}
cancelOrder(endpoint client, http:Request req, string orderId) {
http:Response response;
// Remove the requested order from the map.
_ = ordersMap.remove(orderId); json payload = "Order : " + orderId + " removed.";
// Set a generated payload with order status.
response.setJsonPayload(untaint payload); // Send response to the client.
_ = client->respond(response);
}
}

构建&&运行

  • 构建
ballerina build restful_service_k8s
  • 生成的k8s部署文件
    ballerina 学习二十七  项目k8s部署&& 运行
    同时生成了helm 以及普通的部署文件(server ingress deploy ),很方便
    ballerina 学习二十七  项目k8s部署&& 运行
  • 运行图
    ballerina 学习二十七  项目k8s部署&& 运行

参考资料

https://ballerina.io/learn/by-guide/restful-service/
https://github.com/ballerina-guides/restful-service

 
 
 
 

ballerina 学习二十七 项目k8s部署&& 运行的更多相关文章

  1. idea14导入eclipse项目并部署运行完整步骤

    idea14导入eclipse项目并部署运行完整步骤 2015年05月12日 14:08:04 阅读数:40456 首先说明一下:idea里的project相当于eclipse里的workspace, ...

  2. AgileEAS&period;NET SOA 中间件平台5&period;2版本下载、配置学习&lpar;二&rpar;:配置WinClient分布式运行环境

    一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...

  3. 玩转Django2&period;0---Django笔记建站基础十二&lpar;Django项目上线部署&rpar;

    第十二章 Django项目上线部署 目前部署Django项目有两种主流方案:Nginx+uWsGI+Django或者Apache+uWSGI+Django.Nginx作为服务器最前端,负责接收浏览器的 ...

  4. ballerina 学习二十三 扩展ballerina

    扩展ballerina 目前有三种方式: 扩展client connector的包 (数据库访问,基础设施,api) 扩展server listenner 绑定为不同的协议 添加新的注解到baller ...

  5. ballerina 学习二十六 项目docker 部署&amp&semi;&amp&semi; 运行(二)

    ballerina 从发布,到现在官方文档的更新也是很给力的,同时也有好多改进,越来越好用了 可以参考官方文档 https://ballerina.io/learn/by-guide/restful- ...

  6. ballerina 学习二十五 项目docker 部署&amp&semi;&amp&semi; 运行

    ballerina 官方提供了docker 的runtime,还是比较方便的 基本项目创建 使用cli创建项目 按照提示操作就行 ballerina init -i 项目结构 添加了dockerfil ...

  7. rocketmq学习&lpar;二&rpar; rocketmq集群部署与图形化控制台安装

    1.rocketmq图形化控制台安装 虽然rocketmq为用户提供了使用命令行管理主题.消费组以及broker配置的功能,但对于不够熟练的非运维人员来说,命令行的管理界面还是较难使用的.为此,我们可 ...

  8. ballerina 学习二十九 数据库操作

    ballerina 数据操作也是比较方便的,官方也我们提供了数据操作的抽象,但是我们还是依赖数据库驱动的. 数据库驱动还是jdbc模式的 项目准备 项目结构 ├── mysql_demo │ ├── ...

  9. ballerina 学习二十八 快速grpc 服务开发

    ballerina 的grpc 开发模型,对于开发者来说简单了好多,不是schema first 的方式,而是我们 只要编写简单的ballerina service 就可以了,proto 文件是自动帮 ...

随机推荐

  1. &lbrack;Top-Down Approach&rsqb; Chatper 3 Notes

    这里留下空白,提醒自己,第一章第二章尚待整理回顾. 此处缺了3.6/3.7两节拥塞控制的内容

  2. javaScript系列:js中获取时间new Date&lpar;&rpar;详细介绍

    var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份(4位,1970-????)m ...

  3. Js C&num; 实现跨域访问数据

    使用项目一的js调用项目二的数据 1.项目一 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta ...

  4. F4IF&lowbar;FIELD&lowbar;VALUE&lowbar;REQUEST 和 F4IF&lowbar;INT&lowbar;TABLE&lowbar;VALUE&lowbar;REQUEST的不同

    F4IF_FIELD_VALUE_REQUEST 和 F4IF_INT_TABLE_VALUE_REQUEST的不同 F4IF_FIELD_VALUE_REQUEST主要功能是将表里的字段对应的sea ...

  5. heartbeat单独提供高可用服务

    本文目录:1.简介2.安装heartbeat 2.1 编译安装Heartbeat3.heartbeat相关配置文件 3.1 配置文件ha.cf 3.2 配置文件authkeys 3.3 配置文件har ...

  6. TNS-12535&sol;12606 and ORA-3136 on Connection to Database &lpar;Doc ID 2313573&period;1&rpar;

    今天遇到一问题 telnet 都是通的,但是两台数据库服务器还是无法 sqlplus 连接 ,最后发现 两台服务器的 mtu 值不同,其中一台为 1500 一台为9000, 以前只是认为 telnet ...

  7. docker 删除所有退出的容器

    方法一: #显示所有的容器,过滤出Exited状态的容器,取出这些容器的ID, sudo docker ps -a|grep Exited|awk '{print $1}' #查询所有的容器,过滤出E ...

  8. 《剑指offer》 树的子结构

    本题来自<剑指offer> 树的子结构 题目: 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) 思路: 分两步走: 第一步:判断根节点,两个根节 ...

  9. 数组 this&period;setData快捷赋值

    let list=this.data.list; let listString = `{"list[${index}].sliderSure":${!list[index].sli ...

  10. BBC 记录片planet earth

    He'll have to remain on guard for another two weeks, but in the jungle, just surviving the day can c ...