Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get started with Service-Center

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

How to get started with Service-Center? for this question, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

We will introduce how to use Service-Center.

one。 What is Service-Center?

ServiceCenter is a service registry. Service providers can register their own instance information with ServiceCenter for service consumers to discover and use it.

two。 Why use Service-Center

In the micro-service architecture, an application consists of a set of services with single responsibilities, and each service is dynamically deployed to different nodes. In the face of such a set of services, how to manage the dependencies between services?

The emergence of the service registry is to solve this problem, it provides a registration mechanism that allows service providers to register their own information with the center, and a discovery mechanism for service consumers to find service provider information from the center.

Service registry advantages:

1. Decoupling the service provider from the service consumer, the service consumer does not need to hard-code the service provider address.

two。 Service dynamic discovery and scalability, the dynamic increase or decrease of service provider instances can be dynamically pushed to the service consumer through the registry.

3. Through the registry, we can dynamically monitor the service operation quality and service dependence, and provide the service governance ability for the service.

three。 Registration Discovery process

As shown in the figure above, the service discovery process in Service-Center consists of the following steps:

The service provider registers the service information with Service-Center

The service provider sends a heartbeat to maintain the "UP" state in the Service-Center

Service consumers register service information with Service-Center

Service consumers discover service provider information from Service-Center

The service consumer sends a request to the service provider and obtains the communication result

The Service-Center registration discovery API is implemented based on the RESTful standard and is not restricted by the development language. To implement the corresponding API, please refer to the official API documentation:

Https://rawcdn.githack.com/ServiceComb/service-center/master/docs/api-docs.html

Service-Center provides Client for simple registration and discovery, which encapsulates the API implementation and can be used directly. For more information, please see:

Https://github.com/apache/servicecomb-service-center/tree/master/pkg/client/sc

four。 Use Service-Center

In order to better understand the process, we will use the example of "helloword" to achieve Service-Center-based registration discovery and complete the communication between Consumer and Provider.

Only the main process code is shown below. For a complete example, please refer to:

Https://github.com/ChinX/service-center-demo/tree/simple-demo

1. Catalog referenc

Create a project named "helloworld". The following is the reference directory structure:

two。 Service provider implementation

Create a new service provider profile: helloworld/rest/provider/conf/microservice.yaml

New project entry file: helloworld/rest/provider/provider.go

01. Complete the startup process in the main function:

02. Start http snooping on the service provider

03. Register your own service with Service-Center, which includes three parts: micro-service creation, instance registration and heartbeat keeping alive. The specific code is as follows:

3. Service consumer implementation

Configuration file: helloworld/rest/provider/conf/microservice.yaml

Entry file: helloworld/rest/consumer/consumer.go

1. Complete the startup process in the main function:

two。 Discovering a service provider from a Service-Center service involves creating services and service discovery interfaces:

3. Request interface "/ hello" to complete communication with the service provider

4. Build and compile

The following builds on go 1.11 +, please test your own go environment.

Enter the service-center-demo directory:

five。 Functional verification

1. Install and start Service-Center

Obtain the binary package from the Service-Center official website:

Http://servicecomb.apache.org/release/, decompress and run binary

If you execute the above command and get the corresponding feedback, the installation and deployment is successful.

two。 Start provider

Output information analysis:

The service provider starts and listens to the local port 8080

The microservice was successfully created and the returned serviceId was printed.

Successfully registered your own instance and printed the returned instanceId

The service provider successfully sent a heartbeat 30 seconds after startup.

3. Start consumer

Output information analysis:

The service consumer successfully created the microservice and printed the returned serviceId

The service consumer successfully discovers the provider instance and prints the returned provider endpoints

The service provider successfully sends a request to the service provider and obtains the returned information "hello world"

Looking at the provider console at this time, if a print similar to "21:13:02 request from consumer on 2019-02-17" appears, it means that the provider side has received a request from the provider side, which together confirms the success of the communication.

This is the answer to the introductory question on how to use Service-Center. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report