In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Oracle launched a lightweight Java micro-service framework Helidon example analysis, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Recently, Oracle launched a new open source framework, Helidon, a collection of Java libraries for creating microservice-based applications. Like Payara Micro, Thorntail (formerly WildFly Swarm), OpenLiberty, TomEE, etc., this project has joined the MicroProfile family.
Helidon, originally named J4C (Java for Cloud), is designed to be simple and fast, and includes two versions: Helidon SE and Helidon MP. Helidon SE provides three core API:Web servers, configuration, and security for creating microservices, which are used to build microservice-based applications without the need for an application server. Helidon MP supports the MicroProfile 1.1 specification for building microservice-based applications.
Web server
Inspired by NodeJS and other Java frameworks, Helidon's Web server is an asynchronous, reactive API that runs on top of Netty. The WebServer interface includes support for configuration, routing, error handling, and building metrics and healthy endpoints.
The following sample code demonstrates how to start a simple Helidon Web server that displays "It works!" on a randomly available port:
/ / start server public void startWebServerUsingRandomPort () throws Exception {WebServer webServer = WebServer .create (Routing.builder () .any ((req,res)-> res.send ("It works!" + "\ n") .build () .start () .toCompletableFuture () .get (10) on a randomly available port TimeUnit.SECONDS) System.out.println ("Server started at: http://localhost:" + webServer.port () +"\ n "); webServer.shutdown () .toCompletableFuture ();} configuration
The configuration component Config loads and handles configuration properties in key / value format. By default, configuration properties are read from defined application.properties or application.yaml files, which are located in the / src/main/resources directory.
The following sample code, based on the previous example, demonstrates how to use Config to start the Web server by reading the applications.yaml file to get the specified port.
/ / application.yamlserver: port: 8080 host: 0.0.0.0 / / start the server public void startWebServerUsingDefinedPort () throws Exception {Config config = Config.create () on the predefined port of application.yaml; ServerConfiguration serverConfig = ServerConfiguration.fromConfig (config.get ("server")) WebServer webServer = WebServer .create (serverConfig,Routing.builder () .any ((req,res)-> res.send ("It works!"+"\ n ") .build () .start () .toCompletableFuture () .get (10Jie TimeUnit.SECONDS) System.out.println ("Server started at: http://localhost:" + webServer.port () +"\ n "); webServer.shutdown () .toCompletableFuture ();} Security
Class Security provides support for authentication, authorization, and auditing. There are already many security provider implementations for Helidon applications. There are three ways to build security into Helidon applications: from the builder, through configuration, or a combination of the first two.
The following sample code demonstrates how to build an Security instance, use Config to obtain user authentication (using an encrypted password), and display the server time.
/ / application.yamlhttp-basic-auth: users: login: "mpredli" password: "${CLEAR=somePassword}" roles: ["user", "admin"] Config config = Config.create (); Security security = Security.builder () .config (config) .addProvider (...) .build (); String user = config.get ("http-basic-auth.users.login") .asString () String password = config.get ("http-basic-auth.users.password"). AsString (); System.out.println ("\ n"); System.out.println ("INFO: user =" + user); System.out.println ("INFO: password =" + password); SecurityTime time = SecurityTime.builder (). Build (); time = security.getServerTime (); System.out.println ("INFO: server time =" + time.toString ()); System.out.println ("\ n")
GitHub
Provides a more detailed security example.
Architecture of Helidon
The following architecture diagram shows the relationship between Helidon SE and Helidon MP.
The following figure illustrates the micro-service framework category to which Helidon SE and Helidon MP belong.
Getting started Guid
Helidon provides a quick start example to demonstrate the difference between Helidon SE and Helidon MP.
The following Maven and Java commands generate and package the Helidon SE example to create a REST service using Helidon's Web server.
$mvn archetype:generate-DinteractiveMode=false\-DarchetypeGroupId=io.helidon.archetypes\-DarchetypeArtifactId=helidon-quickstart-se\-DarchetypeVersion=0.10.1\-DgroupId=io.helidon.examples\-DartifactId=quickstart-se\-Dpackage=io.helidon.examples.quickstart.se $cd quickstart-se$ mvn package$ java-jar target/quickstart-se.jar
The following Maven and Java commands generate and package the Helidon MP example to create a REST service using MicroProfile's JAX-RS API.
$mvn archetype:generate-DinteractiveMode=false\-DarchetypeGroupId=io.helidon.archetypes\-DarchetypeArtifactId=helidon-quickstart-mp\-DarchetypeVersion=0.10.1\-DgroupId=io.helidon.examples\-DartifactId=quickstart-mp\-Dpackage=io.helidon.examples.quickstart.mp $cd quickstart-mp$ mvn package$ java-jar target/quickstart-mp.jar
Once the server is running, you can execute the following command
The entire Helidon project can be found on GitHub.
Dmitry Kornilov, senior software development manager at Oracle, introduced the new project to infoQ.
InfoQ: what inspired Oracle to develop this new micro-services framework?
Here I would like to recommend a framework to learn and communicate Jun Yang. Communication and Learning Junyang: 821169538 will share some videos recorded by senior architects: Spring,MyBatis,Netty source code analysis, principles of high concurrency, high performance, distributed, micro-service architecture, JVM performance optimization, distributed architecture, etc. these become the necessary knowledge system for architects. You can also get free learning resources and have benefited a lot at present.
Dmitry Kornilov: the work on Helidon has been going on for some time. When the micro-service architecture for creating cloud services becomes very popular, the development experience also needs to change. Java EE is a stable technology, but it has a lot of legacy code. Instead of building microservices on Java EE, we realized that we needed a new framework for building microservices designed from scratch. That's how Helidon came into being.
InfoQ: what makes Helidon unique compared to other MicroProfile implementations such as OpenLiberty, Thorntail, Payara Micro, and TomEE?
Kornilov:Helidon is more than just a MicroProfile implementation. It comes in two versions: Helidon SE and Helidon MP.
Helidon SE constitutes the core of Helidon. It is a lightweight set of libraries that can be used separately, but if used together, can meet the basic needs of developers to create micro-services: configuration, security, and Web servers. It brings a more modern reactive approach that developers like. We always try to be clear: do not use injection "magic" to make Helidon SE applications easy to debug. There is no special jar format, no special class loader. Your application is just a normal Java SE application. This also means that it is compatible with all IDE and does not require special plug-ins.
Helidon MP is our MicroProfile implementation, which is built on Helidon SE-- it is not derived from an application server. So, no deployment model, no Java EE packaging, no extra stuff you don't need.
InfoQ: why is the MicroProfile 1.1 specification implemented instead of a newer version?
The development of Kornilov:Helidon started some time ago, and we decided to stick with the latest version of MicroProfile at that time. We are constantly improving Helidon, and support for a new version of MicroProfile will come soon.
InfoQ: what will Helidon do next, especially in terms of Jakarta EE support and newer versions of the MicroProfile specification?
Kornilov: as I have mentioned, we are working on support for newer versions of MicroProfile. When new Jakarta EE specifications emerge, we will participate in their development and support them in Helidon. In addition, we plan to add Oracle Cloud integration features, HTTP client support, project initiator Web applications to Helidon, and constantly improve our examples and documentation.
After reading the above, have you mastered the method of sample analysis of Oracle's lightweight Java micro-service framework Helidon? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.