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. IntelliJ IDEA安装lombok插件

    Settings→Plugins→Browse repositories 输入lom后选择Install Plugin 按照提示重启IDEA   来自为知笔记(Wiz)

  2. 设计模式的一些杂谈与反思---functionn和signals

    以下关于GOF的一些例子命名不是很准确,但是大概意思差不多,懒得再去翻书了 模拟观察者模式 模拟中介者模式 模拟command模式 模拟memento和command   模拟观察者模式 观察者与职责 ...

  3. Android中使用am命令实现在命令行启动程序详解

    在Android中,除了从界面上启动程序之外,还可以从命令行启动程序,使用的是命令行工具am. 复制代码代码如下: usage: am [subcommand] [options] start an ...

  4. asp.net和脚本获取当前的URL、IP地址

    介绍一下ASP.NET取得当前页面的完整URL 的方放,icech做成了函数,直接用吧! private string GetPath() { string strPath = "http: ...

  5. Env:Winmanager插件使用

    转自:http://www.cnblogs.com/feichexia/archive/2012/11/06/vim_WinManager.html 1.准备winmanger插件,从下面网址下即可: ...

  6. purgeIdleCellConnections: found one to purge conn = 0x1e09f7d0

    purgeIdleCellConnections: found one to purge conn = 0x1e09f7d0 你在iOS6下使用3G网络时可能会遇到这条log,不用紧张,这只是苹果的工 ...

  7. [JS]深入理解JavaScript系列(4):立即调用的函数表达式

    转自:汤姆大叔的博客 前言 大家学JavaScript的时候,经常遇到自执行匿名函数的代码,今天我们主要就来想想说一下自执行.在详细了解这个之前,我们来谈了解一下"自执行"这个叫法 ...

  8. catalan---卡特兰数(小结)

    (关于卡特兰数的详细介绍)http://baike.baidu.com/view/2499752.htm 下面有练习的题目: 经过测试,_int64/long long 最大只能表示到33位,超过这个 ...

  9. ADO.NET(查询、属性扩展)

    一.ADO.NET 融合面向对象的查询语句 1.只查询一条数据 //数据访问中的select方法 public stu select(string xuehao) { stu s = null; cm ...

  10. 用happen-before规则重新审视DCL(转)

    编写Java多线程程序一直以来都是一件十分困难的事,多线程程序的bug很难测试,DCL(Double Check Lock)就是一个典型,因此对多线程安全的理论分析就显得十分重要,当然这决不是说对多线 ...