Small D Class - New version of the micro-services springcloud + feign invocation of _4-05 micro tutorial service Docker combat orders calling Goods

notes


5, feign micro invocation of service calls Goods Orders combat service
    description: electric business transformation project orders for service calls Goods obtain product information
        Feign: pseudo-RPC client (or nature with http)
        official document: https: //cloud.spring. IO / Spring-Cloud-openfeign /


        . 1, used to explain the steps feign (old and new versions are not the same name dependent)
            was added dependent
                 <dependency>
                    <the groupId> org.springframework.cloud </ the groupId>
                    <the artifactId> Cloud-Spring-Starter-openfeign < / the artifactId>
                </ dependency>
            start classes increased @EnableFeignClients
            increase an interface and @FeignClient (name = "Product--Service")

        2, the actual coding


        3, attention points:
            1, path
            2, Http method must correspond to
            3 using requestBody, You should be used @PostMapping
            When 4, a plurality of parameters, by @RequestParam ( "id") int id) invoke

Start

feign http request is made to a client. Sending a request from the order service to Product service
suggest that you look at the official documentation: official document: https://cloud.spring.io/spring-cloud-openfeign/

first need to add the dependent packages

start classes annotated

the following method may delete ribbon do not delete. Here to retain

new ProductClient next service. His class form Interface

increase in notes. The value of the name which is the name of the calling service



product is a service starts two 8772 a 8773.

see Registry launched two services

Call client

Call the client inside the method. It acquired a json string.

Json need a utility class. New utils package and create a new class JsonUtils

spring jackson this is the default packet analyzing json. Note that these are in the packet jackson

string parsing json returns a JsonNode objects

here we look breakpoint debugging

request data


JsonNode data format

to obtain the value of the attribute json jsonNode inside

the transmission request




Precautions


Here you can also use RequestMapping but to develop value and method


of multiple parameters when calling int id) by way of @RequestParam ( "id").
Parameters and parameter must be the product of a method called consistent

if the parameter used requestBody so be sure to use the above comments postMapping up. Because requestBody post is received over the parameters of

the complex can call Baidu, find the corresponding article to see.








 

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11445843.html