Use Butterfly in Ocelot, ocelotbutterfly

Source: Internet
Author: User

Use Butterfly in Ocelot, ocelotbutterfly

Ocelot (https://github.com/TomPallister/Ocelot) is a use. net core Implementation of API gateway, Butterfly (https://github.com/ButterflyAPM/butterfly) is used. net core implements full-program tracking. Now Butterfly can be used in Ocelot. For more information about Ocelot and Butterfly functions, see their respective github sites. For the implementation of Ocelot and Butterfly combinations, parameter: zhangshanyou blog.

For the code in the blog, see Logging.

Project Description:

Project name

Project Type

Port

Description

OcelotGateway

Web api

5000

Gateway project

API001

Web api

5001

Business api Project

API002

Web api

5002

Business api Project

TestAPI

Web api

5577

Test api Project

Ocelot

Class Library

None

Ocelot official source code, because there is a bug for pr, so now we have fixed the clone download and will fix it later.

Butterfly-web-preview-0.0.8

Web api

9618

The Butterrfly execution program is used to collect and display data of nodes. You can visit http: // localhost: 9618.

 

Project Structure:

 

The Code of API001 and API002 is very simple, that is, a time string is returned after the request. API001 will call API002 before the return, because a gateway exists, therefore, the implementation method of API001 is to request the API002 ing path in the gateway (see the project code), rather than directly accessing API002 (because API002 should have multiple nodes in the microservice cluster, these nodes only know the specific address after they are registered through the service. Therefore, they can access API002 by accessing the gateway address during the call.

TestAPI requests the ing of API001 In the gateway (For details, refer to the project code)

In the configuration file configuration. json in OcelotGateway, enable UseTracing: true under HttpHandlerOptions in each ReRoutes (see the project code for details)

You need to reference butterfly. client. aspNetCore projects include API001, API002, OcelotGateway, and TestAPI. Now butterfly. client. the version of AspNetCore is 0.0.8 and has bugs (which will be corrected when you contact the author later). You can reference 0.0.7 for testing.

The Request Path is as follows:

 

The request starts from the URL of TestAPI: http: // localhost: 5577/api/values/1. TestAPI uses HttpClient to request the gateway URL: http: // localhost: 5000/api001/values, in the gateway, the ing URL: http: // localhost: 5001/api/values in HttpClient to configuration will be used, and API001 will use HttpClient to request URL: http: // localhost: 5000/api002/values, the gateway uses HttpClient to configure the ing URL: http: // localhost: 5002/api/values

 

You need to start the project:

1. Use dotnet Butterfly. Web. dll -- EnableHttpCollector = true to start Butterfly-web-preview-0.0.8

2. Start OcelotGateway

3. Start API001

4. Start API002

 

Open http: // localhost: 9618

View Traces

 

 

We can see that the Request Path is consistent with the Request Path analyzed above through the upper and lower order of the request in the second figure of Traces.

View Dependencies

 

If the dual arrow header is changed to two single arrows in Dependencies, it is clearer to add the step sequence number.

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.

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.