In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly analyzes how to combine HttpClientFactory and Steeltoe to complete the relevant knowledge points of service discovery, the content is detailed and easy to understand, the operation details are reasonable, and has a certain reference value. If you are interested, you might as well follow the editor and learn more about "how to combine HttpClientFactory and Steeltoe to complete service discovery".
Preface
A simple fuse degradation is realized by using HttpClientFactory.
Let's briefly talk about using HttpClientFactory to implement service discovery. Because the title has clearly said Steeltoe.
Therefore, the relevant environment of Spring Clound will be required here, and by default, you have some knowledge about it, so it will not involve the building process.
Let's start with the text.
Define Service
The Service here can be simply understood as invoking a service registered with Eureka and then processing it later.
In the above Service, it is the conventional usage of HttpClient that can no longer be routinely used! I don't seem to see anything related to service discovery.
Indeed, the above code can not complete the service discovery, because our protagonist, HttpClientFactory has not yet appeared!
The Service is defined first because we are going to use another client approach (Typed Client) here.
Let's go to Startup for related configuration.
Configure in Startup
Before we configure, we need to add a reference to Steeltoe.Discovery.ClientCore.
Then follow the configuration instructions of Steeltoe to add the following configuration to appsettings.json
Finally, the operation is done in the ConfigureServices method.
Registering HttpClient here involves two points. One is Typed Client, the other is outgoing request middleware.
TypedClient is mainly AddTypedClient (), indicating that the registered HttpClient is for this type.
DiscoveryHttpMessageHandler indicates that when you use this HttpClient, you will use this Handler.
In addition, the BaseAddress specified here is http://bservicetest/api/values/.
This is another test service that has been registered with Eureka. We just want to find it and get the results from this service.
And then, of course, it's the controller.
Controller and log usage
Controller is very simple, there is no need to say more.
A log is also added here to make it easier to view the log after release, so NLog is added to output the log.
Add a nlog.config, which is roughly as follows.
Then add a line to Program that uses NLog.
Running effect
After the release, you can see that Eureka has successfully registered our ClientTest service.
Among them, the two arrows above are the services we use, and CLIENTTEST is the one we just released. BSERVICETEST is another testing service.
CLIENTTEST will call BSERVICETEST as a test service to get the data.
The following request to see the effect.
From the dynamic diagram, it has met the expectations, and since there are two instances of BSERVICETEST, you can also see that the above result is that the two instances are returning results at random.
Finally, take a look at the log
The request is indeed accessed to our BSERVICETEST, not directly through the direct address of the service.
This is the end of the introduction on "how to combine HttpClientFactory and Steeltoe to complete service discovery". More related content can be searched for previous articles, hoping to help you answer questions, please support the website!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.