Spring-cloud entry-eureka-client (Service Registration ),

Source: Internet
Author: User

Spring-cloud entry-eureka-client (Service Registration ),

Preface

In the previous section, we set up a service registration center to provide a bridge between service providers and consumers. In this section, we set up a service provider and register it with the Registration Center.

Open Source Address: https://github.com/bigbeef

Create eureka-client Module

The code structure is as follows:

Code Writing

Cppba-spring-cloud-eureka-client> pom. xml

<?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>  <artifactId>cppba-spring-cloud-eureka-client</artifactId>  <packaging>jar</packaging>  <name>${project.artifactId}</name>  <parent>    <groupId>com.cppba</groupId>    <artifactId>cppba-spring-cloud</artifactId>    <version>1.0.0</version>  </parent>  <dependencies>    <dependency>      <groupId>org.springframework.cloud</groupId>      <artifactId>spring-cloud-starter-eureka</artifactId>    </dependency>  </dependencies></project>

SpringCloudEurekaClientApplication. java

package com.cppba;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@EnableEurekaClient@RestControllerpublic class SpringCloudEurekaClientApplication {  public static void main(String[] args) {    SpringApplication.run(SpringCloudEurekaClientApplication.class, args);  }  @Value("${server.port}")  private String port;  @RequestMapping("/hi")  public String sayHi(@RequestParam String name) {    return "hi " + name + ",i am from port:" + port;  }}

Application. properties

server.port=8764eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/spring.application.name=service-say

The project has been established.

Start the project

Before starting eureka-client, we first start the eureka-server set up in the previous section. After both services are started, we access the registration center. We can see that:

This indicates that our service has been registered successfully! Visit http: // 127.0.0.1: 8764/hi? Name = hornet

At this point, the eureka-client (service discovery) project has been set up successfully.

Reference: https://github.com/bigbeef/cppba-spring-cloud
Github address: https://github.com/bigbeef

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.