Spring cloud ribbon

Spring cloud implements load balancing through the ribbon.

1、 Add Maven dependency

2、 Application YML configuration

3、 Main class preparation

4、 Write test related

1. Write test business interface class

Note: the blog-api is the name of the service instance and must be registered with Eureka server. Otherwise, it is invalid and the request will be 404.

Resttemplate implements restful related functions respectively, such as post, get, delete, put, etc.

By calling resttemplate postForEntity(url,respResult)、restTemplate. getForEntity(url,respResult)、restTemplate. delete(url,respResult)、restTemplate. Put (URL, respresult), etc. can be implemented immediately. You can also use the omnipotent resttemplate getForObject(url,respResult)。

The URL must be an instance existing in the Eureka service registry, and the relevant request interface URL behind the instance must exist, otherwise it is meaningless.

2. Write test routing class

5、 Testing

The requested interface is related to the third-party integration API of my personal blog system. The example in the figure is to enter a personal mobile phone number to obtain the relevant information of the mobile phone number. The effect diagram is as follows:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>