At this moment, Azure Service Fabric does not support JAVA application natively (but it's on the support roadmap). However, we can host the JAVA application as a Guest Executable for the time being.

In this article, I will walk you through how to deploy JAVA application on Azure Service Fabric in details.

  1. Prepare JAVA Application
    I follow the Embedded Jetty Examplesto create a simple file server.
    The source code is like below.

     package org.eclipse.jetty.embedded;
    
     import org.eclipse.jetty.server.Handler;
    import org.eclipse.jetty.server.Server;
    import org.eclipse.jetty.server.handler.DefaultHandler;
    import org.eclipse.jetty.server.handler.HandlerList;
    import org.eclipse.jetty.server.handler.ResourceHandler; public class FileServer { public static void main(String[] args) throws Exception{
    // TODO Auto-generated method stub
    // Create a basic Jetty server object that will listen on port 8080. Note that if you set this to port 0
    // then a randomly available port will be assigned that you can either look in the logs for the port,
    // or programmatically obtain it for use in test cases.
    Server server = new Server(8080); // Create the ResourceHandler. It is the object that will actually handle the request for a given file. It is
    // a Jetty Handler object so it is suitable for chaining with other handlers as you will see in other examples.
    ResourceHandler resource_handler = new ResourceHandler(); // Configure the ResourceHandler. Setting the resource base indicates where the files should be served out of.
    // In this example it is the current directory but it can be configured to anything that the jvm has access to.
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[]{ "index.html" });
    resource_handler.setResourceBase("."); // Add the ResourceHandler to the server.
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
    server.setHandler(handlers); // Start things up! By using the server.join() the server thread will join with the current thread.
    // See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
    server.start();
    server.join();
    } }

    Then you need to Export this application to a runnable JAR file. (Note: Choose "Package required libraries into generated JAR" as the Library handing option. In my first environment, I choose the first option which runs into issue.)

  2. Set up Service Fabric project
    • Create Service Fabric Application in Visual Studio

    • Select Guest Executable as the Template;
      Choose the folder where you exported JAR file as the Code Package Folder
      Choose "Copy folder contents to project" as Code Package Behavior
      Choose CodeBase as Working Folder
    • The Application package file structure is shown as below.
      |-- ApplicationPackageRoot
      |-- JettyGuestAppPkg
      |-- Code
      |-- FileServer8080.jar
      |-- Config
      |-- Settings.xml
      |-- Data
      |-- ServiceManifest.xml
      |-- ApplicationManifest.xml
    • Copy JDK to the code base folder. The package file structure looks as below, where jre1.8.0_111 is JAVA runtime.
    • Configure ServiceManifest.xml to set the program entry point and http listening port. (Note: Be careful about the JAR file path. It is relative to java.exe)
      <EntryPoint>
      <ExeHost>
      <Program>jre1.8.0_111\bin\java.exe</Program>
      <Arguments>-jar ..\..\FileServer8080.jar</Arguments>
      <WorkingFolder>CodeBase</WorkingFolder>
      <!-- Uncomment to log console output (both stdout and stderr) to one of the
      service's working directories. -->
      <!-- <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/> -->
      </ExeHost>
      </EntryPoint>
      <Endpoints>
      <!-- This endpoint is used by the communication listener to obtain the port on which to
      listen. Please note that if your service is partitioned, this port is shared with
      replicas of different partitions that are placed in your code. -->
      <Endpoint Name="JettyGuestAppTypeEndpoint" Protocol="http" Port="8080" Type="Input"/>
      </Endpoints>
  3. It's ready to deploy to Azure Service Farbic now. After deploy completed, you can check the application status via Service Fabric Explorer (http://localhost:19080/Explorer/index.html ).
  4. Verify JAVA application is running as expected by browsing to http://localhost:8080

Notes:

  1. How the JAVA Application is running on Local Service Fabric Cluster?
    ServiceFabricLocalClusterManager.exe creates a new process called java.exe under its own process tree to hold the JAVA application.
  2. During the process to export the JAVA application I choose "Extract required libraries into generated JAR" as the Library handing option, and the application does not run as expected. In this case, how can we tell the issue is with Service Fabric or with your own JAVA application?
    • I use Process Monitor to check how the java.exe is launched.

      The command line is:

      "C:\SfDevCluster\Data\_App\_Node_0\JettyAppType_App1\JettyGuestAppPkg.Code.1.0.0\jre1.8.0_111\bin\java.exe" -jar ..\..\FileServer.jar
    • Running the command above in Windows Command Window, and the issue happens there as well. Then I am pretty sure the issue is with JAVA code, and has nothing to do with Service Farbic.

How to deploy JAVA Application on Azure Service Fabric的更多相关文章

  1. Azure Service Fabric 开发环境搭建

    微服务体系结构是一种将服务器应用程序构建为一组小型服务的方法,每个服务都按自己的进程运行,并通过 HTTP 和 WebSocket 等协议相互通信.每个微服务都在特定的界定上下文(每服务)中实现特定的 ...

  2. Azure Service Fabric 踩坑日志

    近期项目上面用到了Azure Service Fabric这个服务,它是用来做微服务架构的,由于这套代码和架构都是以前同学留下来的,缺少文档,项目组在折腾时也曾遇到几个问题,这里整理如下,以供参考. ...

  3. 人人都可以开发高可用高伸缩应用——论Azure Service Fabric的意义

    今天推荐的文章其实是微软的一篇官方公告,宣布其即将发布的一个支撑高可用高伸缩云服务的框架--Azure Service Fabric. 前两天,微软Azure平台的CTO Mark Russinovi ...

  4. 如何把遗留的Java应用托管在Service Fabric中

    一.概述 众所周知,微服务化尤其对遗留系统进行微服务化一般采用"Lift and Shift"的模式进行. Service Fabric作为一个微服务托管平台,不仅仅可以在上面跑. ...

  5. Jenkins中使用Azure Powershell连接Service Fabric报错not recognized的原因与解决办法

    一.使用背景 在涉及Azure service Fabric的自动化应用场景中,依赖于Service Fabric的Azure Powershell cmdlets,我们可以使用Jenkins能实现c ...

  6. Service Fabric基本概念: Node, Application, Service, Partition/Replicas

    作者:张鼎松 (Dingsong Zhang) @ Microsoft 在上一节中,为大家简明扼要的介绍了微软针对现代分布式系统在Azure上实现的相关服务组件.紧接上文内容,本节将为大家介绍Azur ...

  7. 【Azure微服务 Service Fabric 】Service Fabric中应用开启外部访问端口及微服务之间通过反向代理端口访问问题

    问题描述 1) 当成功的在Service Fabric集群中部署了应用后,如何来访问呢?如果是一个Web服务,它的URL又是什么呢? 2) 当Service Fabric集群中,服务之间如需要相互访问 ...

  8. 微服务框架之微软Service Fabric

    常见的微服务架构用到的软件&组件: docker(成熟应用) spring boot % spring cloud(技术趋势) Service Fabric(属于后起之秀 背后是微软云的驱动) ...

  9. 转:微服务框架之微软Service Fabric

    常见的微服务架构用到的软件&组件: docker(成熟应用) spring boot % spring cloud(技术趋势) Service Fabric(属于后起之秀 背后是微软云的驱动) ...

随机推荐

  1. Java-Lambda

    1. 函数式接口 函数式接口可以包含多个默认方法.类方法,但是只能有一个抽象方法. Lambda表达式的目标类型是函数式接口. java.util.function包下,定义了大量的函数式接口 2. ...

  2. C语言每日一题之No.12

    文件操作知识:如何将一个文件的内容读取到另一个文件里? fread函数和fwrite函数   1.函数功能   用来读写一个数据块. 2.一般调用形式   fread(buffer,count,siz ...

  3. jQuery formValidator手册

    什么是jQuery formValidator? jQuery formValidator表单验证插件是客户端表单验证插件. 在做B/S开发的时候,我们经常涉及到很多表单验证,例如新用户注册,填写个人 ...

  4. activiti自定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义

    注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建        (2)创建流程模型:activiti自定义流程之Spring ...

  5. MyEclipse 设置注释

    MyEclipse设置注释的方法 windows-Preferences-(弹出窗口) 单击[Edit]后弹出编辑窗口,然后进行编辑

  6. ASP.NET MVC之从控制器传递数据到视图四种方式

    前言 本系列开始着手讲述ASP.NET MVC,也算是自己对基础的回顾以及进一步深入学习,保证每天发表一篇该系列文章,关于基本知识则不再叙述,园子有关文章不胜枚举,这一系列若有叙述不当或错误之处,欢迎 ...

  7. shell 的语法

    SHELL 的语法 n  变量:字符串,数字,环境和参数 n  条件:shell中的布尔值 n  程序控制:if, elif, for, while until, case n  命令列表 n  函数 ...

  8. HDU 4539 郑厂长系列故事――排兵布阵(曼哈顿距离)

    这虽然是中文题,然而没看懂,不懂的地方,就是在曼哈顿距离这块,网上搜索了一下,写了个程序,是测试曼哈顿距离的. 曼哈顿距离:两点(x1,y1)(x2,y2)的曼哈顿距离为|x1-x2|+|y1-y2| ...

  9. suibi11172

    http://blog.sina.com.cn/s/blog_12f37f0f00102wi8q.html 七.Python列表操作的函数和方法 列表操作包含以下函数: 1.cmp(list1, li ...

  10. python (16) 如何在linux下安装lxml(pip安装,ubuntu下,centos下)

    首先需要明白lxml包依赖其他包,必须先安装其他包然后再安装lxml 安装python-pip:方便安装python的第三方包 [root@******/]# wget https://bootstr ...