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 build spring cloud alibaba micro-service

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to build spring cloud alibaba micro-service". In daily operation, I believe many people have doubts about how to build spring cloud alibaba micro-service. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to build spring cloud alibaba micro-service"! Next, please follow the editor to study!

1.Feign is a declarative WebService client. Using Feign makes it easier to write Web Service clients. The way to use it is to define a service interface and then add comments to it. In actual development, because service-dependent calls can not be used in one place, often an interface will be invoked in multiple places, so it is usually for each micro-service to encapsulate some client classes to wrap these dependent service calls.

two。 Use our previous cloudalibaba-consumer-nacos-order83 project demo as the client

Introducing openfeign into 3.pom file

Org.springframework.cloud spring-cloud-starter-openfeign

4. Main startup class:

@ SpringBootApplication//@EnableDiscoveryClient@EnableFeignClients / / Open Feignpublic class OrderApplication83 {public static void main (String [] args) {SpringApplication.run (OrderApplication83.class,args);}}

5. Write an excuse for exposure and call it together.

6. Use our previous 9001 and 9002 as service providers, start these three services respectively, and visit the address: http://127.0.0.1:83/consumer/payment/nacos/1

Refresh the interface again

It turns out that payload calls are supported internally in Openfeign.

Openfeign timeout control

1. Set the timeout in the port 9001 service

two。 Call the interface added above in the port 83 service and visit: http://127.0.0.1:83/consumer/payment/feign/timeout

This error occurs because the feign default client only waits for one second, but the server-side processing takes more than a second.

Solution:

Add the following configuration to the yml file:

# set feign client timeout (openFeign supports ribbon by default) ribbon: # refers to the time it takes to establish a connection. When the network is in normal condition, the time it takes to connect to both ends of the server ReadTimeout: 5000 # refers to the time it takes to read the available resources from the server after the connection is established. ConnectTimeout: 5000

Openfeign log enhancement

Add the following configuration to the yml configuration file:

Logging: at what level does the level:#feign log monitor which interface com.yxw.springcloud.service.PaymentFeignService: debug

In configuring the log bean

@ Configurationpublic class FeignConfig {@ Bean Logger.Level feignLoggerLevel () {return Logger.Level.FULL;}}

Start the service provider to see the console to print the following information:

At this point, the study on "how to build spring cloud alibaba micro services" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report