Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-Dapr endpoints invocation supported? #1311

Open
ZenwalkerD opened this issue Jun 20, 2024 · 6 comments
Open

Non-Dapr endpoints invocation supported? #1311

ZenwalkerD opened this issue Jun 20, 2024 · 6 comments
Labels
question Further information is requested

Comments

@ZenwalkerD
Copy link

Ask your question here

Dear All,

In the Dapr documentation i noticed that a service can invoke a Non-Dapr endpoints like https://reqres.in/api/users?page=2 (external APIs).

But when i checked the Dotnet Dapr documentation; i could not find any code related to that.

I tried below code and it does not work..

 var client = DaprClient.CreateInvokeHttpClient("https://reqres.in");
 var response = client.GetAsync(client.BaseAddress + "api/users?page=1").Result;
 var result = response.Content.ReadAsStringAsync().Result;

Please let me know if the support is planned or where can i find a documentation?

@WhitWaldo
Copy link
Contributor

Using Dapr for service invocation against Dapr endpoints gives you service discoverability. If you don't need the discoverability and know the port of what you're trying to access, it gives you a mechanism to attempt invoking a REST endpoint using an HTTP-based invocation.

In your example, you're going a step further and accessing a completely external API - might I ask why you're bothering with the DaprClient and not just using an HttpClient to invoke it like you would any other REST endpoint?

@philliphoff
Copy link
Collaborator

I tried below code and it does not work..

@ZenwalkerD Can you be more specific about what didn't work? Did the call fail, and in what way? Could you provide a repro code/project that demonstrates the issue?

@ZenwalkerD
Copy link
Author

In your example, you're going a step further and accessing a completely external API - might I ask why you're bothering with the DaprClient and not just using an HttpClient to invoke it like you would any other REST endpoint?

Because of Daprs feature of resiliency. Dapr provides retries and other policies. So i was hoping to make use of all those features in invoking external network calls. Otherwise i have to rely on some libraries like Polly.net.

@ZenwalkerD
Copy link
Author

I tried below code and it does not work..

@ZenwalkerD Can you be more specific about what didn't work? Did the call fail, and in what way? Could you provide a repro code/project that demonstrates the issue?
This is what i am getting when i deploy my app on Azure ACA:

{"errorCode":"ERR_DIRECT_INVOKE","message":"failed to invoke, id: https, err: rpc error: code = Unimplemented desc = "}

Code is very simple. Plain ASP NET CORE WEB API project with a GET controller having above provided code. Assuming that all dependencies are added for Dapr and others.

@philliphoff philliphoff added the question Further information is requested label Jul 1, 2024
@philliphoff
Copy link
Collaborator

@ZenwalkerD You'll need to provide more context; for example, how was the application and Dapr sidecar started, what do the Dapr sidecar logs show (with --log-level debug), what is the full address of the GET call being made, etc.

@ZenwalkerD
Copy link
Author

@ZenwalkerD You'll need to provide more context; for example, how was the application and Dapr sidecar started, what do the Dapr sidecar logs show (with --log-level debug), what is the full address of the GET call being made, etc.

Sorry for the delay in response.

I am now running on local via Dapr CLI tool.

I have below yaml config:

version: 1
common: # optional section for variables shared across apps
  env: # any environment variable shared across apps
    ASPNETCORE_ENVIRONMENT: Development
apps:
  - appID: webapp # optional
    appDirPath: ./FrontEndApi/ # REQUIRED
    appProtocol: http
    appPort: 8080
    command: ["dotnet", "run", "--project", "WebApi-Dapr.csproj", "--urls", "http://localhost:5000"]
    daprdLogDestination: console
    logLevel: debug
  - appID: backendapi # optional
    appDirPath: ./BackendAPI/ # REQUIRED
    appProtocol: http
    appPort: 8080
    command: ["dotnet", "run", "--project", "BackendAPI.csproj","--urls", "http://localhost:5001"]

when i run command: dapr run -f . (dir where yaml exist)

everything runs normal. I am able to access my app and execute the API.
I do not see any errors being logged into file nor console.

Btw i tried changing the API invocation code as shown:

 HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://reqres.in/api/users?page=1");
 var response = await m_DaprClient.InvokeMethodWithResponseAsync(httpRequestMessage);
 var result = await response.Content.ReadAsStringAsync();

With above code; no error logs were thrown by dapr.

However; when i changed back to original code in my first post here; then i got this error:

time="2024-08-06T23:22:57.9957978+05:30" level=debug msg="HTTP service invocation failed to complete with error: invokeError (statusCode='500') msg='{\"errorCode\":\"ERR_DIRECT_INVOKE\",\"message\":\"failed to invoke, id: https, err: couldn't find service: https\"}'" app_id=webapp instance=md3kgf9c scope=dapr.runtime.http type=log ver=1.13.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants