Eurekaマイクロサービス間相互呼び出し

2359 ワード

eureka同士で呼び出すのは簡単ですが、多くの問題に直面しています.記録してください.まず言って、あれらのコードの不完全な文章を見に行かないでください、人を殺して、1つの書く比較的に完全なことを推薦しますhttps://blog.csdn.net/weixin_43928997/article/details/90668007
まず、各種のマイクロサービスとeurekaサービスを構築し、呼び出されたサービスにControllerを書きます.これらは通常の操作です.以上の記事にあります.
そして、サービス者を呼び出して、バッグも上記の文章を見ればいいです.必要な手順と注意事項を書きます.
1、起動クラスです(ここで注意@EnableFeignClients注記でfeignを開く)
package com.ymkj.property;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@EnableFeignClients//        ,      feigns
@EnableDiscoveryClient
@SpringBootApplication
public class PropertyApplication {

	public static void main(String[] args) {
		SpringApplication.run(PropertyApplication.class, args);
	}

}

2、インタフェースを書く(ここでは2つの注意点がある:FeignClientのvalue値、すなわちアクセスされたサービス名、この名前は下線を使うことができなくて、さもなくばどうしても呼び出すことができなくて、2つ目は必ずインタフェースで、FeignClient注釈はインタフェースに注釈するしかありません).
package com.ymkj.property.feign_client;

import com.ymkj.property.entity.response.ResponseBase;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author zhengyue
 * @data 2019-08-09 14:03
 */
@Component
@FeignClient(value="face-server", fallback=FaceConnectionFallBack.class)
public interface FaceManager {

    @RequestMapping(value = "/face/add", method = RequestMethod.POST)
    public ResponseBase addFace(@RequestParam(value = "serialNumbers") String serialNumbers,
                                @RequestParam(value = "name") String name,
                                @RequestParam(value = "sex") String sex,
                                @RequestParam(value = "cardId") String cardId,
                                @RequestParam(value = "start") String start,
                                @RequestParam(value = "end") String end,
                                @RequestParam(value = "imgUrl") String imgUrl);
}

3、必要な場所でクラスを呼び出せばいい