Skip to content

An OpenFeign Client for Dapr Invokes #1294

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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

lony2003
Copy link

@lony2003 lony2003 commented Apr 2, 2025

Description

A OpenFeign Client and it's AutoConfiguration using Dapr Invoke APIs.

Splited into two librarys, dapr-openfeign-client is the pure client of OpenFeign, and dapr-spring-openfeign is the plugin of Spring Cloud OpenFeign.

Currently only HTTP Invoke Method and Invoke Binding supported, and Invoke Binding is not always recommend to use this client, depends on what binding component is.

Issue reference

this PR will close: #1181

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

lony2003 added 6 commits April 1, 2025 21:58
A OpenFeign Client and it's AutoConfiguration using Dapr Invoke APIs.

Splited into two librarys, dapr-openfeign-client is the pure client of OpenFeign, and dapr-spring-openfeign is the plugin of Spring Cloud OpenFeign.

Currently only HTTP Invoke Method and Invoke Binding supported, and Invoke Binding is not always recommend to use this client, depends on what binding component is.

Signed-off-by: lony2003 <[email protected]>
A OpenFeign Client and it's AutoConfiguration using Dapr Invoke APIs.

Splited into two librarys, dapr-openfeign-client is the pure client of OpenFeign, and dapr-spring-openfeign is the plugin of Spring Cloud OpenFeign.

Currently only HTTP Invoke Method and Invoke Binding supported, and Invoke Binding is not always recommend to use this client, depends on what binding component is.

Signed-off-by: lony2003 <[email protected]>
A OpenFeign Client and it's AutoConfiguration using Dapr Invoke APIs.

Splited into two librarys, dapr-openfeign-client is the pure client of OpenFeign, and dapr-spring-openfeign is the plugin of Spring Cloud OpenFeign.

Currently only HTTP Invoke Method and Invoke Binding supported, and Invoke Binding is not always recommend to use this client, depends on what binding component is.

Signed-off-by: lony2003 <[email protected]>
this example can redirect order request to producer-app. It needs producer-app to run properly.

Signed-off-by: lony2003 <[email protected]>
this test tests the PostgreSQL binding of dapr.

Signed-off-by: lony2003 <[email protected]>
@lony2003 lony2003 requested review from a team as code owners April 2, 2025 12:53
@salaboy
Copy link
Collaborator

salaboy commented Apr 2, 2025

I haven't reviewed this yet @lony2003 , but I am more convinced that we need this .. @artur-ciocanu @mcruzdev can you help me to check this PR ?

Fix the example doc to make openfeign app works in mm.py

Signed-off-by: lony2003 <[email protected]>
@salaboy
Copy link
Collaborator

salaboy commented Apr 7, 2025

@lony2003 I've just reviewed this PR and it is looking awesome..
I am currently working on testing multiple sidecars using Testcontainers (for service to service invocation) scenarios, so I will probably tag you in those examples when I have them running. I think this PR is ok (as soon as there are no bean conflicts), then we can create some examples in spring-boot-examples showing the feign clients when we can test service to service invocations with multiple sidecars.

…riginal Targeter beans instead of override them.

Signed-off-by: lony2003 <[email protected]>
@lony2003
Copy link
Author

lony2003 commented Apr 7, 2025

@salaboy I have changed the Targeter part to using BeanPostProcesser to handle them, so now no confliects will happen.

@lony2003 lony2003 requested a review from cicoyle April 8, 2025 05:53
@lony2003
Copy link
Author

lony2003 commented Apr 8, 2025

@cicoyle I have checked all files and add headers for them, and I have solved the problem that makes IT failed. Please re-trigger the CI.

@cicoyle
Copy link
Contributor

cicoyle commented Apr 22, 2025

Hey @lony2003 - thanks, before I can retrigger CI it says there are conflicts needing to be resolved. Mind resolving them locally and pushing? Then we'll be able to proceed 🙏🏻

@lony2003 lony2003 force-pushed the development-openfeign branch from 8580167 to a330ef2 Compare April 23, 2025 01:29
@lony2003 lony2003 force-pushed the development-openfeign branch 5 times, most recently from 6d1e70a to 1767276 Compare April 23, 2025 04:40
@lony2003 lony2003 force-pushed the development-openfeign branch from 3eaa83e to c381e44 Compare April 23, 2025 05:10
… client bean autowired

Job SDK ITs have a daprPreviewClient bean defined, as SpringBoot bean search will first get beans that impl the interface and get all beans that matches the bean's class, when openfeign autowire DaprClient, there is a conflict between daprClient and daprPreviewClient.

Change the AutoConfiguration behavior to make a more strict rule for making AutoConfiguration run

Signed-off-by: lony2003 <[email protected]>
@lony2003 lony2003 force-pushed the development-openfeign branch 4 times, most recently from 00fae6b to bc6d98c Compare April 23, 2025 06:10
… client bean autowired

Job SDK ITs have a daprPreviewClient bean defined, as SpringBoot bean search will first get beans that impl the interface and get all beans that matches the bean's class, when openfeign autowire DaprClient, there is a conflict between daprClient and daprPreviewClient.

Change the AutoConfiguration behavior to make a more strict rule for making AutoConfiguration run

Signed-off-by: lony2003 <[email protected]>
@lony2003
Copy link
Author

@cicoyle conflict solved.

@salaboy
Copy link
Collaborator

salaboy commented May 7, 2025

@lony2003 I am happy to see the CI happy for this PR, can you check the codecov?

salaboy
salaboy previously approved these changes May 7, 2025
Copy link
Collaborator

@salaboy salaboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@salaboy
Copy link
Collaborator

salaboy commented May 11, 2025

@dapr/maintainers-java-sdk I believe that we can merge this PR, we will incrementally improve the quality of this PR, but I want this module to be present in the SDK. Please approve, we can fix any findings in smaller PRs.

@Ds2994
Copy link

Ds2994 commented May 26, 2025

Hi @salaboy @cicoyle Can we get this enhancement merged. This will significantly enhace the code readability and usability for DaprClients.

@salaboy
Copy link
Collaborator

salaboy commented May 26, 2025

I really want this merged too, but I am not a maintainer

@salaboy
Copy link
Collaborator

salaboy commented May 26, 2025

@Ds2994 are you using this integration already in your project ?

@Ds2994
Copy link

Ds2994 commented May 26, 2025

Yes @salaboy I am currently using this in an internal project and having a lot of readability trouble with the overloaded methods in DaprClient. If this declarative approach gets merged will make a lot of my development cleaner.

@salaboy
Copy link
Collaborator

salaboy commented May 26, 2025

@artur-ciocanu @cicoyle do you have any more concerns on this one ? I think this still need to be rebased by @lony2003

@lony2003 lony2003 force-pushed the development-openfeign branch from 6addcf4 to 3b9b9d4 Compare June 11, 2025 13:11
@lony2003
Copy link
Author

@salaboy @artur-ciocanu @cicoyle I have merged the latest base for this PR.

@salaboy
Copy link
Collaborator

salaboy commented Jun 11, 2025

@dapr/maintainers-java-sdk please lets merge this when you can.

Copy link

codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 65.58140% with 74 lines in your changes missing coverage. Please review.

Project coverage is 77.86%. Comparing base (d759c53) to head (3b9b9d4).
Report is 166 commits behind head on master.

Files with missing lines Patch % Lines
...main/java/io/dapr/feign/DaprInvokeFeignClient.java 74.49% 28 Missing and 10 partials ⚠️
.../spring/openfeign/targeter/DaprClientTargeter.java 0.00% 20 Missing ⚠️
.../targeter/DaprClientTargeterBeanPostProcessor.java 0.00% 6 Missing ⚠️
...feign/autoconfigure/DaprFeignClientProperties.java 55.55% 4 Missing ⚠️
...onfigure/FeignClientAnnoationEnabledCondition.java 50.00% 2 Missing and 1 partial ⚠️
...gboot/examples/openfeign/OpenFeignApplication.java 33.33% 2 Missing ⚠️
...a/io/dapr/springboot/examples/openfeign/Order.java 91.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1294      +/-   ##
============================================
+ Coverage     76.91%   77.86%   +0.95%     
- Complexity     1592     1888     +296     
============================================
  Files           145      235      +90     
  Lines          4843     5933    +1090     
  Branches        562      622      +60     
============================================
+ Hits           3725     4620     +895     
- Misses          821      982     +161     
- Partials        297      331      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cicoyle
Copy link
Contributor

cicoyle commented Jun 11, 2025

waiting on CI to ensure a 🟢 run 👍🏻

@lony2003
Copy link
Author

@cicoyle CI have passed. Could you please merge it?

@lony2003
Copy link
Author

@salaboy @cicoyle @artur-ciocanu is there any problem remains? It'a simple patch, so I think it's easier to review than cloud config. Could you please merge it before a breaking change happened?

Copy link
Contributor

@artur-ciocanu artur-ciocanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lony2003 thanks a lot for your contribution. I see the value of this PR and will be a great addition to Dapr Spring portfolio.

I have left quite a few comments. Please take a look and let me know your thoughts.

A few thing that I want to highlight:

  • I don't think OpenFeign makes a lot of sense outside Spring ecosystem, so having a dedicated module named "dapr-openfeign-client" is not really required and I would move it to "dapr-spring-openfeign"
  • Using "UseDaprClient" annotation I would argue that a more ergonomic approach is to have a single annotation named "DaprFeignClient" that looks like "FeignClient" but leverages DaprClient behind the scenes.
  • In the PR we have Feign and OpenFeign in classes, properties file and artifacts. We should have a single naming approach. Since this is part of Spring Cloud we should probably have names like:
    • dapr.spring.cloud.openfeign.client.... - for properties
    • io.dapr.spring.cloud.openfeign... - for package names
    • DaprOpenFeign... - for class names
      This way we can have a more consistent naming scheme.

<dependencies>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move version to parent POM, so we can control all the upgrades from a single place.

</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jaxrs</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move version to parent POM. This is a test dependency, so it should be moved closer to other test dependencies.

We try to keep prod dependencies first, followed by test dependencies.

</dependency>
</dependencies>

</project>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new line.

@@ -0,0 +1,11 @@
<FindBugsFilter>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide more details, why we need these exclusions and why we can't fix the code so we don't need these exclusions.

* See the License for the specific language governing permissions and
limitations under the License.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package is artifact is named dapr-openfeign-client, I think it is a good idea to be consistent and name the package: io.dapr.openfeign

"description": "retries for invoke fails."
}
]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line

@@ -0,0 +1 @@
io.dapr.spring.openfeign.autoconfigure.DaprFeignClientAutoConfiguration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a design perspective wouldn't it be better to have a composite annotation like:

@DaprFeignClient(name = "invoke-binding", url = "http://binding.democlient/")

Instead of always using two annotations like:

FeignClient(name = "invoke-binding", url = "http://binding.democlient/")
@UseDaprClient

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, FeignClient annotation is from Spring Cloud Openfeign, and I think this two annotation means that this interface is a FeignClient and it uses DaprClient to send RPC requests. So I would say it's not a good idea to have a composite annotation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I should say that we use Spring Cloud Openfeign is for it's automatic features in application and IDE, and a composite annotation will definitely break these features, at least in IDE, features provided by Spring Boot plugin would not available while using a DaprFeignClient

@@ -0,0 +1 @@
dapr.feign.enabled=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned let's use dapr.openfeign.client

@@ -8,4 +8,9 @@
<Package name="~io\.dapr\.spring.*"/>
<Bug pattern="EI_EXPOSE_REP2"/>
</Match>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make sure to fix the code and remove this exclusion

@lony2003
Copy link
Author

@artur-ciocanu about dapr-openfeign-client, I think since Openfeign is developed by OpenFeign Community, and is actively developing while Spring Cloud Openfeign is inactived, there should be other usage besides Spring Cloud Openfeign. So I think it's a good idea to have separate library as there should be some users who don't use SpringBoot but uses OpenFeign.

@salaboy
Copy link
Collaborator

salaboy commented Jun 13, 2025

I agree with @lony2003 , this would feel like using spring cloud open feign, it doesn't need to expose any Dapr specific interface or annotation

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

Successfully merging this pull request may close these issues.

Use With Feign
5 participants