airlift 简单试用

airlift 使用简单,而且周边集成也不少,只是官方文档比较少,使用最多的也是trino 以及presto 中,trino 代码基于airlift 框架的开发代码看起来是
很简洁的

项目结构

 
├── README.md
├── app # 实际应用,使用airlift 开发的,包含了静态页面以及简单的rest api 
├── pom.xml
└── src
├── main
├── java
└── com
└── dalong
├── App.java
└── MyDemoResource.java
└── resources
└── webapp
├── app.css
└── index.html
└── test
└── java
├── package # 专门用来进行项目打包使用的,基于了一个类似maven assembly 的插件provisio,此插件在trino 中也有使用到
├── pom.xml
├── src
├── etc
└── config.properties
├── main
├── java
├── provisio
└── myapp.xml
└── resources
└── test
└── java
├── pom.xml

代码简单说明

  • app 部分
    主要是要一个rest api ,包装了静态页面以及应用的启动入口(airlift 自带的bootstrap 能力)
    App.java
 
public class App {
    public static void main(String[] args) {
        Bootstrap app = new Bootstrap(ImmutableList.<Module>builder()
                .add(new NodeModule())
                .add(new Module() {
                    @Override
                    public void configure(Binder binder) {
                       // node 环境配置,还是比较重要的
                        configBinder(binder).bindConfigDefaults(NodeConfig.class, nodeConfig -> {
                           nodeConfig.setEnvironment("test");
                        });
                        // rest api 注册
                        jaxrsBinder(binder).bind(MyDemoResource.class);
                        // 静态页面配置
                        httpServerBinder(binder).bindResource("/","webapp").withWelcomeFile("index.html");
                        httpServerBinder(binder).bindResource("/dalongdemoapp","webapp").withWelcomeFile("index.html");
                    }
                })
                .add(new HttpServerModule())
                .add(new JsonModule())
                .add(new JaxrsModule())
                .add(new EventModule())
                .build());
        app.initialize();
    }
}

MyDemoResource.java

@Path("/")
public class MyDemoResource
{
    private static final Logger log = Logger.get(MyDemoResource.class);
 
    @GET
    @Path("/v1/info")
    @Produces(APPLICATION_JSON)
    public String getInfo(
            @Context HttpServletRequest servletRequest) {
       return  "dalongdemo";
    }
} 
  • package 部分
    实际上参考了trino 的打包
    package/src/main/provisio/myapp.xml
 
<runtime>
    <!-- Target -->
    <archive name="${project.artifactId}-${project.version}.tar.gz" hardLinkIncludes="**/*.jar" />
 
    <!-- Server -->
    <artifactSet to="lib">
        <artifact id="${project.groupId}:app:${project.version}" />
    </artifactSet>
 
</runtime>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.dalong</groupId>
        <artifactId>mywebapp-airlift</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
 
    <artifactId>package</artifactId>
 
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.dalong</groupId>
            <artifactId>app</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>ca.vanzyl.provisio.maven.plugins</groupId>
                <artifactId>provisio-maven-plugin</artifactId>
                <version>1.0.19</version>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>provision</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
 
</project>

说明

airlift 实际上就是对于不少现有框架的包装,使用起来还是很方便的,值得试试,上边app pom 文件就没贴,需要的可以github 查看

参考资料

https://github.com/airlift/airlift/tree/master/docs
https://github.com/rongfengliang/airlift-learning
https://github.com/jvanzyl/provisio

posted on   荣锋亮  阅读(396)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-01-27 升级版本的dremio cratedb arp 开发
2022-01-27 dremio arp 开发值得参考的链接
2022-01-27 dremio 链接starrocks 的方法
2021-01-27 cube.js 上下文变量
2021-01-27 cube.js 多租户的实践
2019-01-27 sofa graphql 2 rest api webhook 试用
2019-01-27 sofa graphql 2 rest api 试用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示