日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

微服务feignclient_微服务-(声明式调用feign)

發布時間:2024/1/23 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 微服务feignclient_微服务-(声明式调用feign) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

聲明式調用 Fegin

一.初步認知fegin

相比ribbon更方便,簡化了代碼了,代理了請求。整合了hystrix。

二.寫一個feign

三.fegin的應用

pom

org.springframework.cloud

spring-cloud-starter-netflix-eureka-client

yml

server:

port: 8083

spring:

application:

name: feign-consumer

eureka:

client:

service-url:

defaultZone : http://127.0.0.1:10000/eureka/

feign:

hystrix:

enabled: true

hystrix:

command:

default:

execution:

isolation:

thread :

timeoutInMilliseconds: 100

客戶端注解

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication

@EnableFeignClients //啟用feign,如果說需要啟動默認配置,就這么寫,如果需要覆蓋就寫成(@EnableFeignClients(defaultConfiguration = "FooConfiguartion.class"))

public class FeignDemoApplication {

public static void main(String[] args) {

SpringApplication.run(FeignDemoApplication.class, args);

}

}

import com.dn.feigndemo.fallback.HelloDemoFallback;

import com.dn.feigndemo.model.Teacher;

import feign.Body;

import feign.Param;

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;

@Component

@FeignClient(name="HELLOCLIENT",fallback = HelloDemoFallback.class)

public interface HelloDemoService {

@RequestMapping(value = "",method = RequestMethod.GET)

public Object getTeacher();

@RequestMapping(value = "/user",method = RequestMethod.GET)

public Teacher getByTeacher(@RequestParam("id")String id);

@Body("%7B\"orderNo\": \"{orderNo}\"%7D")

@RequestMapping(value = "/user",method = RequestMethod.POST)

public int addOrder(@Param("orderNo")String orderNo);

@RequestMapping(value = "/user",method = RequestMethod.POST)

public int addTeacher(@Param("orderNo")String orderNo);

}

1.模板 2.設置請求頭

package com.dn.feigndemo.service;

import com.dn.feigndemo.model.Teacher;

import feign.Headers;

import feign.Param;

import org.springframework.web.bind.annotation.RequestMapping;

@Headers("Accept:appliaction/json") //當前接口下,所有的feign請求都會被設置這個頭

public interface FeginHeaderDemo {

@Headers("Content-Type:appliaction/json")

@RequestMapping("")

int addOrder(Teacher teacher);

@Headers("Token:{token}")//設置動態值

@RequestMapping("")

Teacher getOrder(@Param("token")String token);

}

四.fegin的工作流程

五.fegin與hystrix的集成

六.fegin和ribbon的集成

文章來源: www.oschina.net,作者:這很耳東先生,版權歸原作者所有,如需轉載,請聯系作者。

原文鏈接:https://my.oschina.net/u/3728166/blog/3170798

總結

以上是生活随笔為你收集整理的微服务feignclient_微服务-(声明式调用feign)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。