Springcloud First experience: Five, Sidecar the PHP non-Java language services to the Spring Cloud

Source: Internet
Author: User



Start with a Sidecar service, a PHP service, an application, and PHP services deployed on the same machine, accessed through localhost, which solves the network overhead, equivalent to the local inter-process call



Sidecar service is relatively simple,



1. The configuration of Maven is recorded here


 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    Xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.taxiong</groupId>
    <artifactId>tx_php_server_side_car</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>tx_php_server_side_car</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <!--Configure the warehouse -->
    <repositories>
        <repository>
            <id>aliRepository</id>
            <name>aliRepository</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <!-- cloud -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-sidecar</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>





2, sidecar related configuration, and the configuration of the registration center



 
Spring:
   Application:
     Name: tx-php-server-sidecar

Service registry port number
Server:
   Port: 8203

#Hostname and port of the service registry instance
#Do you register yourself with the service registry?
#Whether to retrieve the service
#Configuration of the registration center, specify the location of the service registry
Eureka:
   Port: 8200
   Instance:
     Hostname: localhost
   Client:
     Register-with-eureka: true
     Fetch-registry: true
     serviceUrl:
       defaultZone: http://${eureka.instance.hostname}:${eureka.port}/eureka/

Sidecar:
   Port: 1215
   Instance:
     Hostname: localhost
   Health-uri: http://${sidecar.instance.hostname}:${sidecar.port}/health





3. Service startup class @EnableSidecar






4, also need in PHP service a check service interface or file, note the response header type Content-type



Take the Laravel framework as an example, the configured address is Http://127.0.0.1:1215/health



 
Route::get(‘health‘, function () {
    $content = ‘{ "status" : "UP" }‘;
    $status = 200;
    $value = ‘application/json; charset=utf-8‘;
    return response($content, $status)
        ->header(‘Content-Type‘, $value);
});



This is through the Eureka Center page, see Sidecar has been registered, note if the PHP Health page response content or response header is incorrect, the Sidecar service's up status will show down





This is the default page for PHP services












This is the PHP service page that was forwarded via Spring Cloud Gateway









Springcloud First experience: Five, Sidecar the PHP non-Java language services to the Spring Cloud


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.