This topic describes how to use Enterprise Distributed Application Service (EDAS) to implement interoperability between multi-language applications and Java Spring Cloud applications.

Background information

As non-Java applications are widely used, the interoperability between Java applications and non-Java applications becomes an urgent need. To meet this need, EDAS provides an architecture that allows you to implement interoperability between multi-language applications and Java Spring Cloud applications. The following figure shows the architecture:

Application hosting overview
  • Java applications use an agent to retrieve the data of multi-language applications that are deployed in an Alibaba Cloud Service Mesh (ASM) instance.
  • Java applications use the service names of multi-language applications to call the multi-language applications.

Prerequisites

The following conditions must be met:
  • A multi-language application is deployed in EDAS.
  • A Java Spring Cloud application is deployed in EDAS.
  • The required environment variables are configured for the interoperability between multi-language applications and Java Spring Cloud applications.

    For more information, see Configure environment variables.

Scenarios

  • Scenario 1: use a Java Spring Cloud application to call a multi-language application

    The method for a Java Spring Cloud application to call a multi-language application is the same as that for the Java Spring Cloud application to call another Java application. For example, you can run the following command to use the restTemplate class to call the A API operation of the Java Spring Cloud application named go-sc-a.

    restTemplate.getForObject("http://go-sc-a/A", String.class)

    You can also use other methods to call the API operation. You can access the application without specifying the port number.

  • Scenario 2: use a multi-language application to call a Java Spring Cloud application

    You can use a multi-language application to call the Kubernetes service provided by a Java Spring Cloud application to access the Java Spring Cloud application.

Deploy a Java Spring Cloud application and a multi-language application

Deploy a Java Spring Cloud application

  1. Log on to the Container Service for Kubernetes (ACK) console.
  2. In the left-side navigation pane, click Clusters.
  3. On the Clusters page, find the cluster that you want to manage and click Applications in the Actions column.
  4. In the left-side navigation pane, choose Workloads > Deployments, select a namespace from the Namespace drop-down list, and then click Create from YAML.
  5. On the Create page, select a template from the Sample Template drop-down list, modify the content of the YAML file in the Template section, and then click Create.

    You can use the following YAML template to deploy a Java Spring Cloud application:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: sc-c
      name: sc-c
      namespace: default
    spec:
      progressDeadlineSeconds: 600
      replicas: 1
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: sc-c
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
            msePilotAutoEnable: "on"
            msePilotCreateAppName: "sc-c"
          labels:
            app: sc-c
        spec:
          containers:
            - env:
                - name: throwException
                  value: 'true'
                - name: JAVA_TOOL_OPTIONS
                  value: '-Dspring.cloud.nacos.discovery.server-addr=127.0.0.1:8848' // Replace the IP address with the IP address of the Nacos service registry in use. 
                - name: profile.micro.service.envoy.xds.server
                  value: 'istiod.istio-system:15012'
                - name: profile.micro.service.envoy.xds.enable
                  value: 'true'
              image: >-
                registry.cn-hangzhou.aliyuncs.com/alibabacloud-microservice-demo/sc-c:demo
              imagePullPolicy: Always
              name: sc-c
              resources:
                requests:
                  cpu: 250m
                  memory: 512Mi
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
    
    -----
    
    apiVersion: v1
    kind: Service
    metadata:
      name: sc-c
      labels:
        app: sc-c
        service: sc-c
    spec:
      ports:
      - port: 20003
        name: http
      selector:
        app: sc-c
    You can view the created Java Spring Cloud application on the Deployments page.

Deploy a multi-language application

  1. In the left-side navigation pane, choose Workloads > Deployments, select a namespace from the Namespace drop-down list, and then click Create from YAML.
  2. On the Create page, select a template from the Sample Template drop-down list, modify the content of the YAML file in the Template section, and then click Create.

    You can use the following YAML template to deploy a multi-language application:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        version: v1
      name: go-sc-a-v1
      namespace: default
    spec:
      progressDeadlineSeconds: 600
      replicas: 1
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          version: v1
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      template:
        metadata:
          labels:
            app: go-sc-a
            version: v1
        spec:
          containers:
            - env:
                - name: LOG_DIR
                  value: /tmp/logs
              image: 'registry.cn-hangzhou.aliyuncs.com/edas_test1/helloa:demo'
              imagePullPolicy: IfNotPresent
              name: go-sc-a
              ports:
                - containerPort: 8085
                  protocol: TCP
              resources: {}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
              volumeMounts:
                - mountPath: /tmp
                  name: tmp
                - mountPath: /opt/ibm/wlp/output
                  name: wlp-output
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
          volumes:
            - emptyDir: {}
              name: wlp-output
            - emptyDir: {}
              name: tmp
              
    -----
    
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: go-sc-a
        service: go-sc-a
      name: go-sc-a
      namespace: default
    spec:
      ports:
      - port: 8085
        name: http
      selector:
        app: go-sc-a
    You can view the created multi-language application on the Deployments page.

Configure environment variables

  1. Log on to the ACK console.
  2. In the left-side navigation pane, click Clusters.
  3. On the Clusters page, find the cluster that you want to manage and click Applications in the Actions column.
  4. In the left-side navigation pane, choose Workloads > Deployments. On the Deployments page, select ARMS-pilot from the Namespace drop-down list, find the created multi-language application, and then click Edit in the Actions column.
  5. In the Environment Variable section, click Add. Create the following environment variable, and click Update.

    Environment variable:

    profile.micro.service.envoy.xds.enable: true

  6. On the Deployments page, select the namespace of the created Java Spring Cloud application from the Namespace drop-down list, find the application, and then click Edit in the Actions column.
  7. In the Environment Variable section, click Add. Create the following environment variable and startup parameter, and click Update.

    Environment variable and startup parameter:

    • profile.micro.service.envoy.xds.server: istiod.istio-system:15012
    • profile.micro.service.envoy.xds.enable: true

Implement interoperability between the Java Spring Cloud application and multi-language application

Java Spring Cloud applications can interoperate with multi-language applications that are deployed in an ASM instance. The method for a Java Spring Cloud application to call a multi-language application is the same as that for the Java Spring Cloud application to call another Java application. You do not need to modify the code.

Use the Java Spring Cloud application to call the multi-language application

Run the following command to use the created Java Spring Cloud application to call the created multi-language application:
curl localhost:20003/go
Note The Java application can use its internal API to access the multi-language application.
The following result is returned:
[Java Spring Cloud ] -> [Service Mesh APP10.191.XX.XX ]

Use the multi-language application to call the Java Spring Cloud application

Run the following command to use the created multi-language application to call the created Java Spring Cloud application:
curl localhost:8085/java
The following result is returned:
[ Service Mesh APP ] -> [Java Spring Cloud10.191.XX.XX]