Communicate across applications

Update time: 2019-07-25

Project address


During merged deployment, Biz packages can communicate with each other by releasing and referencing JVM services apart from using the RPC framework. This sample project is intended to demonstrate how two Biz packages communicate by JVM services.

Within the biz-jvm-invocation-sample project, there are three sub-projects whose functions are as follows: + facade: A common Java module that defines the SampleJvmService interface.


public interface SampleJvmService {
    String service();
  • app-one: A SOFABoot Web application that defines a simple rest request and use the @SofaReference annotation to reference the SampleJvmService. When a page request is triggered, an attempt is made to call the JVM service. The key code is:
package me.qlong.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class HelloController {

    private SampleJvmService sampleJvmService;

    public String hello() {
        return sampleJvmService.service();

  • app-two: A non-web application in SOFABoot that uses the @SofaService annotation to publish the SampleJvmService. ```java package;

import; import; import org.springframework.stereotype.Component;

@SofaService @Component public class AppTwoSampleService implements SampleJvmService{ public String service() { return “App Two”; } }

## Dependency

To communicate between Biz packages through JVM services, you must add dependencies on the SOFARuntime package and the corresponding Ark Plugin as follows:


For detailed information about publishing and referencing JVM services, see the SOFABoot Documentation. You are advised to use annotations in Jarslink2.0.


  • cd biz-jvm-invocation-sample/facade && mvn clean install Execute the mvn clean install command in the facade root directory, and install the facade package in the local Maven repository so that you can add a facade dependency in app-one and app-two:
<!--service facade-->
  • cd biz-jvm-invocation-sample/app-one && mvn clean package Execute the mvn clean package command in the app-one root directory and package the application into Ark and Biz packages. The files will be exported to the biz-jvm-invocation-sample/app-one/target directory.

  • cd biz-jvm-invocation-sample/app-two && mvn clean package Execute the mvn clean package command in the app-two root directory and package the application into Ark and Biz packages. The files will be exported to the biz-jvm-invocation-sample/app-two/target directory.

  • Use java -jar to start the Ark package for app-one.

  • After the Ark package has started, visit http://localhost:8080/hello in the browser. The following error message is displayed on the page warning that the JVM service for cannot be found:

There was an unexpected error (type=Internal Server Error, status=500).
JVM Reference[interface] cant not find the corresponding JVM service. Please check if there is a SOFA deployment publish the corresponding JVM service. If this exception occurred when the application starts up, please add Require-Module to SOFA deployment's MANIFEST.MF to indicate the startup dependency of SOFA modules.
  • The error message appears because handling the /hello request triggers app-one to call the and no other Biz packages are publishing the service at this moment.
  • Run telnet localhost 1234 to access the Jarslink2.0 command interface and execute the install -b command to install the Biz package that starts app-two.
  • Visit http://localhost:8080/hello again in the browser and the page displays “App Two.” This indicates that the request successfully triggered app-one to call the published by app-two.