官术网_书友最值得收藏!

  • Java EE 8 and Angular
  • Prashant Padmanabhan
  • 370字
  • 2021-07-02 19:22:40

Running our services

Download the Payara Micro server if you haven't already, from this link: https://www.payara.fish/downloads.

The micro server will have the name payara-micro-xxx.jar, where xxx will be the version number, which might be different when you download the file.

Here's how you can start Payara Micro with our services deployed locally. When doing so, we need to ensure that the instances start on different ports, to avoid any port conflicts:

>java -jar payara-micro-xxx.jar --deploy ims-micro-users/target/ims-micro-users.war --port 8081
>
java -jar payara-micro-xxx.jar --deploy ims-micro-tasks/target/ims-micro-tasks.war --port 8082
>java -jar payara-micro-xxx.jar --deploy ims-micro-notify/target/ims-micro-notify.war --port 8083

This will start three instances of Payara Micro running on the specified ports. This makes our applications available under these URLs:

  • http://localhost:8081/ims-micro-users/resources/users/
  • http://localhost:8082/ims-micro-tasks/resources/tasks/
  • http://localhost:8083/ims-micro-notify/resources/notifications/

Payar Micro can be started on a non-default port by using the --port parameter, as we did earlier. This is useful when running multiple instances on the same machine.

Another option is to use the --autoBindHttp parameter, which will attempt to connect on 8080 as the default port, and if that port is unavailable, it will try to bind on the next port up, repeating until it finds an available port.

Examples of starting Payra Micro:

Uber JAR option: Now, there's one more feature that Payara Micro provides. We can generate an Uber JAR as well, which would be the Fat JAR approach that we learnt in the Fat JAR section.

To package our ims-micro-users project as an Uber JAR, we can run the following command:

java -jar payara-micro-xxx.jar --deploy ims-micro-users/target/ims-micro-users.war --outputUberJar users.jar

This will generate the users.jar file in the directory where you run this command. The size of this JAR will naturally be larger than our WAR file, since it will also bundle the Payara Micro runtime in it. Here's how you can start the application using the generated JAR:

java -jar users.jar

The server parameters that we used earlier can be passed to this runnable JAR file too. Apart from the two choices we saw for running our microservice projects, there's a third option as well. Payara Micro provides an API based approach, which can be used to programmatically start the embedded server.

We will expand upon these three services as we progress further into the realm of cloud-based Java EE.

主站蜘蛛池模板: 翼城县| 泸溪县| 攀枝花市| 灵宝市| 讷河市| 德江县| 南澳县| 黎平县| 体育| 津南区| 黄冈市| 嘉定区| 玛曲县| 胶南市| 竹北市| 花垣县| 昌图县| 黔南| 长沙县| 宁波市| 武穴市| 河池市| 清水河县| 嵊泗县| 榆社县| 望江县| 二手房| 赞皇县| 丰原市| 东乡族自治县| 灌南县| 阿克苏市| 右玉县| 科尔| 嵊州市| 广南县| 石渠县| 寻甸| 卢氏县| 苍山县| 陆川县|