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

Source: Internet
Author: User

Tags:. com response pac localhost Aliyun version instance Prope also requires

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"?><Projectxmlns= "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>
View Code

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

Spring:  application:    name:tx-php-server-sidecar# Service  Registry Port number server:8203#服务注册中心实例的主机名, Port #是否向服务注册中心注册自己 # Whether to retrieve the configuration contents of the Service # Service registry, specify the location of the service  registry eureka:8200  instance:    hostname:localhost  client:    register-with-eureka:true    fetch-registry:true    serviceurl:      defaultzone:http:/ /${eureka.instance.hostname}:${eureka.port}/eureka/sidecar:  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

function {    $content = ' {' status ': ' Up '} ';     $status = $;     $value = ' Application/json; Charset=utf-8 ';     return response ($content$status)        ,header$ 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

Related Article

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.

Tags Index: