You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: daprdocs/content/en/java-sdk-docs/spring-boot/_index.md
+90Lines changed: 90 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,6 +40,47 @@ By adding these dependencies you can:
40
40
- Use the Spring Data and Messaging abstractions and programming model that uses the Dapr APIs under the hood
41
41
- Improve your inner-development loop by relying on [Testcontainers](https://testcontainers.com/) to bootstrap Dapr Control plane services and default components
42
42
43
+
___(Optional)___ And if you want to enable openfeign support, you will also need to add the dependencies to your project:
Check the [Dapr Workflow documentation](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-overview/) for more information about how to work with Dapr Workflows.
325
366
367
+
## Invoke Methods and Bindings registered in Dapr with Spring Cloud OpenFeign
368
+
369
+
First you should follow the official Spring Cloud OpenFeign steps to enable FeignClient features,
370
+
mainly by adding a `@UseFeignClient` annotation in your SpringBoot Application of Configurations.
371
+
372
+
Define a FeignClient using DaprClient is very easy, you can just define a regular FeignClient, and add a `@UseFeignClient` to the interface, just like that:
There you go! now when you call the ProducerClient methods, it will call the DaprClient to handle that.
391
+
392
+
>___Note: because of the design of DaprClient, you won't get any headers from Dapr.___
393
+
>
394
+
>___So you need to add `produces = "application/json"`
395
+
to your RequestMapping in order to parse the response body which return type is other than `String`.___
396
+
>
397
+
> ___The `produces` field will generate an `Accept` header to the request,
398
+
the client will read it and create a fake `Content-Type` header to the response,
399
+
and Spring Cloud Openfeign will read the `Content-Type` header of the response to parse values.___
400
+
401
+
You may have noticed that the `url` field of `@FeignClient` is strange, here is the schema of it:
402
+
403
+
The following content is from the Java Doc of DaprInvokeFeignClient.
404
+
405
+
> Dapr currently supports two methods of invocation: invokeBinding (output binding) and invokeMethod. This client supports two modes: http://binding.xxx or http://method.xxx. The http scheme at the beginning is just to make Spring Boot Openfeign work properly.
406
+
>
407
+
> For invokeMethod, the URL contains two types of information, similar to the format of an HTTP URL. The difference lies in the conversion of the host in the HTTP URL to appId, and the path (excluding “/”) to methodName. For example, if you have a method with the appId “myApp” and the methodName “getAll/demo”, then the URL for this request would be http://method.myApp/getAll/demo. You can also set HTTP headers if you wish, and the client will handle them. Currently, only HTTP calls are supported, but grpc calls may be supported in the future, with possible URLs like http://method_grpc.myApp/getAll or similar.
408
+
>
409
+
> For invokeBinding, the URL also contains two types of information: the host is the bindingName, and the path is the operation. Note that different bindings support different operations, so you must consult the Dapr documentation. For example, if you have a binding with the bindingName “myBinding” and the supported operation is “create”, then the URL for this request would be http://binding.myBinding/create. You can put some metadata in the headers of the Feign request, and the client will handle them.
410
+
>
411
+
> As for the response, the result code is always 200 OK. If the client encounters any errors, it will throw an IOException.
412
+
>
413
+
> Currently, we have no method to gain metadata from server as Dapr Client doesn’t have methods to do that, so headers will be blank. If Accept header has set in request, a fake Content-Type header will be created in response, and it will be the first value of Accept header.
414
+
415
+
___Note that not all bindings are recommended to use FeignClient to query directly, you can try `dapr-spring-data` for databases, or `dapr-spring-messaging` for pubsubs___
0 commit comments