Comments (5)
我使用了SteeltoeServiceDiscovery3.0.1
//Steeltoe
services.AddDiscoveryClient(Configuration);
//Feign
services.AddFeignClients().AddSteeltoe();第一个是可以访问服务,第二个不行,请问还需要配置什么吗?
[HttpGet("Get1")]
public async Task Get1()
{
var client = new HttpClient(_handler, false);
return await client.GetStringAsync("http://agent-service/weatherforecast");
}
[HttpGet("Get")]
public async Task Get2()
{
return await this.AngleSharpTestService.GetHtmlAsync();
}
请问报什么错呢?
SteeltoeServiceDiscovery 3.0 版本需要引入 Steeltoe.Discovery.Consul 3.0 或者 Steeltoe.Discovery.Eureka 3.0 才行
from feign.net.
Feign.Proxy.FeignProxyHttpClientHandler.SendInternalAsync(FeignHttpRequestMessage request, CancellationToken cancellationToken) in FeignProxyHttpClientHandler.cs
_logger?.LogError(e, "Exception during SendAsync()");
}
if (e is HttpRequestException)
{
FeignHttpRequestException feignHttpRequestException = new FeignHttpRequestException(_feignClient, request, (HttpRequestException)e);
ExceptionDispatchInfo exceptionDispatchInfo = ExceptionDispatchInfo.Capture(feignHttpRequestException);
exceptionDispatchInfo.Throw();
}
throw;
}
finally
{
request.RequestUri = current;
System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task sendTask, HttpRequestMessage request, CancellationTokenSource cts, bool disposeCts)
Feign.Proxy.FeignClientHttpProxy.SendAsyncInternal(FeignClientHttpRequest request) in FeignClientHttpProxy.Request.cs
HttpContent httpContent = request.GetHttpContent();
if (httpContent != null)
{
httpRequestMessage.Content = httpContent;
}
}
return await HttpClient.SendAsync(httpRequestMessage, request.CompletionOption)
#if CONFIGUREAWAIT_FALSE
.ConfigureAwait(false)
#endif
;
}
}
Feign.Proxy.FeignClientHttpProxy.GetResponseMessageAsync(FeignClientHttpRequest request) in FeignClientHttpProxy.Request.cs
}
private async Task<HttpResponseMessage> GetResponseMessageAsync(FeignClientHttpRequest request)
{
try
{
return await SendAsyncInternal(request)
#if CONFIGUREAWAIT_FALSE
.ConfigureAwait(false)
#endif
;
}
catch (TerminatedRequestException)
Feign.Proxy.FeignClientHttpProxy.SendAsync(FeignClientHttpRequest request) in FeignClientHttpProxy.Request.cs
;
}
}
protected virtual async Task<TResult> SendAsync<TResult>(FeignClientHttpRequest request)
{
HttpResponseMessage response = await GetResponseMessageAsync(request)
#if CONFIGUREAWAIT_FALSE
.ConfigureAwait(false)
#endif
;
using (response)
Feign.TestWeb.NETCORE31.Controllers.WeatherForecastController.Get2() in WeatherForecastController.cs
return await client.GetStringAsync("http://agent-service/weatherforecast");
}
[HttpGet("Get")]
public async Task<IEnumerable<WeatherForecast>> Get2()
{
return await this.AngleSharpTestService.GetHtmlAsync();
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
lambda_method(Closure , object )
Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable+Awaiter.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask.get_Result()
System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask actionResultValueTask)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
from feign.net.
使用Steeltoe官方的方法是可以拿到值的,
private readonly ILogger _logger;
IAngleSharpTestService AngleSharpTestService;
DiscoveryHttpClientHandler _handler;
public WeatherForecastController(ILogger<WeatherForecastController> logger, IDiscoveryClient client, IAngleSharpTestService angleSharpTestService)
{
_logger = logger;
_handler = new DiscoveryHttpClientHandler(client);
this.AngleSharpTestService = angleSharpTestService;
}
[HttpGet("Get1")]
public async Task<String> Get1()
{
var client = new HttpClient(_handler, false);
return await client.GetStringAsync("http://agent-service/weatherforecast");
}
from feign.net.
使用Steeltoe官方的方法是可以拿到值的,
private readonly ILogger _logger;IAngleSharpTestService AngleSharpTestService; DiscoveryHttpClientHandler _handler; public WeatherForecastController(ILogger<WeatherForecastController> logger, IDiscoveryClient client, IAngleSharpTestService angleSharpTestService) { _logger = logger; _handler = new DiscoveryHttpClientHandler(client); this.AngleSharpTestService = angleSharpTestService; } [HttpGet("Get1")] public async Task<String> Get1() { var client = new HttpClient(_handler, false); return await client.GetStringAsync("http://agent-service/weatherforecast"); }
看不出啥问题,方便把 "IAngleSharpTestService" 这个接口定义发来看看吗? 还有 Steeltoe 的配置文件
from feign.net.
使用Steeltoe官方的方法是可以拿到值的,
private readonly ILogger _logger;IAngleSharpTestService AngleSharpTestService; DiscoveryHttpClientHandler _handler; public WeatherForecastController(ILogger<WeatherForecastController> logger, IDiscoveryClient client, IAngleSharpTestService angleSharpTestService) { _logger = logger; _handler = new DiscoveryHttpClientHandler(client); this.AngleSharpTestService = angleSharpTestService; } [HttpGet("Get1")] public async Task<String> Get1() { var client = new HttpClient(_handler, false); return await client.GetStringAsync("http://agent-service/weatherforecast"); }
看不出啥问题,方便把 "IAngleSharpTestService" 这个接口定义发来看看吗? 还有 Steeltoe 的配置文件
[知道问题出在什么地方了,如下,感谢@daixinkai
//Steeltoe错误的写方法 不需要Url 与java一样的调用,画蛇添足了
//[FeignClient("agent-service", Url = "http://agent-service")]
//Steeltoe正确的写方法 agent-service 是服务名称
[FeignClient("agent-service")]
from feign.net.
Related Issues (9)
- 补充文档 HOT 2
- SteeltoeServiceDiscovery 服务发现的时候没有过滤不健康节点 HOT 4
- url 配置 HOT 1
- httpclient在core 2.1以后推荐用factory 初始化 HOT 2
- IDiscoveryClient 已经迁移 HOT 1
- 怎么才能适配JsonRpc的请求 HOT 1
- 可不可以在不修改源码的情况下集成nacos HOT 2
- 降级回调方法里面能获取到异常吗?我看接口里面没有定义 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feign.net.