Git Product home page Git Product logo

Comments (5)

daixinkai avatar daixinkai commented on August 15, 2024

我使用了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.

spacestime avatar spacestime commented on August 15, 2024

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.

spacestime avatar spacestime commented on August 15, 2024

使用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.

daixinkai avatar daixinkai commented on August 15, 2024

使用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.

spacestime avatar spacestime commented on August 15, 2024

使用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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.