O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Declarative Clients in Spring

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Introduction to Testcontainers
Introduction to Testcontainers
Carregando em…3
×

Confira estes a seguir

1 de 61 Anúncio

Declarative Clients in Spring

Baixar para ler offline

What is a declarative HTTP client vs. an imperative one? Why are they useful and why should I care? We’ll talk about options that are available in the Spring portfolio and what’s coming on the horizon. In this session, we’ll look at the history of declarative clients in Spring via Spring Cloud OpenFeign. We’ll also dive into upcoming options that are coming to Spring and the advantages that these new technologies bring to the developer experience. Spring One Tour Tel-Aviv 2022.

What is a declarative HTTP client vs. an imperative one? Why are they useful and why should I care? We’ll talk about options that are available in the Spring portfolio and what’s coming on the horizon. In this session, we’ll look at the history of declarative clients in Spring via Spring Cloud OpenFeign. We’ll also dive into upcoming options that are coming to Spring and the advantages that these new technologies bring to the developer experience. Spring One Tour Tel-Aviv 2022.

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Mais de VMware Tanzu (20)

Mais recentes (20)

Anúncio

Declarative Clients in Spring

  1. 1. Olga Maciaszek-Sharma Declarative Clients in Spring Copyright © 2020 VMware, Inc. or its affiliates.
  2. 2. About Olga Software Engineer in Spring Cloud team Spring Cloud LoadBalancer, Spring Cloud OpenFeign, Spring Cloud Netflix, Spring Cloud Contract, Spring Cloud Square, RSocket HTTP Bridge TT/ Mastodon: @olga_maciaszek
  3. 3. What is a declarative client?
  4. 4. Sample applications Customer Service Verification Service HTTP POST /verify Customer Verification Result
  5. 5. Direct use of HTTP client
  6. 6. Client interface
  7. 7. Implementation
  8. 8. Implementation with helper methods
  9. 9. Client interface usage
  10. 10. What if we could just create an annotated interface and have a library/ framework translate it into actual HTTP client requests?
  11. 11. Declarative/ interface client Client interface method calls HTTP calls Proxy
  12. 12. Feign
  13. 13. OpenFeign/Feign
  14. 14. Feign Java to HTTP client binder ● Core part of a former Spring Cloud Netflix module, passed over to the community ● Supports various HTTP clients, including Apache HTTP, Apache HC5, Ok HTTP ● Contracts - support for custom annotations and argument resolution ● Support for a broad range of encoders/ decoders, including Jackson and GSON ● Metrics, including Micrometer support
  15. 15. Spring Cloud OpenFeign
  16. 16. Spring Cloud OpenFeign Spring MVC and Spring Cloud support for OpenFeign ● Spring MVC annotations support ● Auto-configurations for Feign-specific beans ● Spring Cloud LoadBalancer support ● Spring Cloud CircuitBreaker support ● Tracing support
  17. 17. A declarative/ interface client
  18. 18. A declarative/ interface client use
  19. 19. Spring Cloud OpenFeign Demo Applications communicating over HTTP Customer Service SC OpenFeign Client SC LoadBalancer SC Sleuth Verification Service POST /verify Customer Verification Result Eureka Service Registry
  20. 20. Spring Cloud OpenFeign - popularity Highly-readable interface clients with robust integrations ● 906 GitHub stars ● 8670549 Maven downloads in 2021 ● Nearly flat learning curve for Spring MVC users
  21. 21. Spring Cloud OpenFeign - issues ● Issues with reusing client interfaces as controllers ○ @RequestMapping at class level user issues (GH-547, GH-678) ○ CVE-2021-22044 ● Maintenance issues caused by dependence on third party upstream project ● Lack of non-blocking support
  22. 22. Spring Cloud Square Spring Boot and Spring Cloud support for Retrofit and OkHttp ● WebClient support for Retrofit interface clients ● Auto-configurations ● Load-balancing ● Tracing ● Only Retrofit annotations ● Incubator project
  23. 23. RetroSocket Interface client for RSocket ● Incubator project
  24. 24. HTTP & RSocket Interface Clients in Spring Framework 6.0
  25. 25. Interface clients are not new in the Spring Framework Same mechanism, different protocols
  26. 26. Why HTTP and RSocket now? Discussions with Spring Cloud around OpenFeign, Retrofit, and RSocket integrations
  27. 27. Spring Framework 6.0 already had plans for RSocket interface client
  28. 28. Old request for HTTP, deferred to… Spring Cloud OpenFeign
  29. 29. Old request for HTTP, deferred to… Spring Cloud OpenFeign
  30. 30. Opportunity to revisit Underlying mechanism is not specific to Spring Cloud Cloud features are extensions on top
  31. 31. Some issues can only be addressed in Spring Framework programming model vs reusing @RequestMapping
  32. 32. Decided to explore for Spring Framework 6.0
  33. 33. HTTP interface client programming model Relationship to server @RequestMapping?
  34. 34. Two goals Define a single request (no wildcards of any kind!) Avoid outright server-specific
  35. 35. @RequestMapping attributes For mapping of 1..N requests Any HTTP method Any URL path
  36. 36. @RequestMapping method parameters ServletRequest HttpMethod @RequestHeader @RequestParam @RequestBody @RequestAttribute @ModelAttribute …
  37. 37. @RequestMapping return values ResponseEntity HttpHeaders Body void Model View SseEmitter …
  38. 38. New method annotation to declare rather than map requests @RequestMapping @HttpExchange
  39. 39. @HttpExchange attributes url method contentType accept
  40. 40. @HttpExchange method parameters Subset of those for @RequestMapping i.e. reusing method parameter annotations
  41. 41. @HttpExchange method parameters URI HttpMethod @RequestHeader @PathVariable @RequestBody @RequestParam @CookieValue
  42. 42. @HttpExchange return values Subset of those for @RequestMapping i.e. also using return value types
  43. 43. Blocking
  44. 44. Reactive
  45. 45. status, headers, body
  46. 46. headers
  47. 47. execute only
  48. 48. Spring Interface Clients Demo Applications communicating over HTTP Customer Service Spring HTTP Interface Client SC LoadBalancer Verification Service POST /verify Customer Verification Result Eureka Service Registry
  49. 49. RSocket interface client @RSocketExchange
  50. 50. @RSocketExchange attributes value
  51. 51. @RSocketExchange method parameters @DestinationVariable @Payload Object, if followed by MimeType MimeType
  52. 52. @RSocketExchange return values concrete values producer of values
  53. 53. Blocking
  54. 54. Reactive
  55. 55. Demo
  56. 56. Resources ● Demo code - reactive HTTP client ● Demo code - non-reactive HTTP client with load-balancing ● Demo-code - RSocket client ● Spring Cloud OpenFeign ● Spring Framework documentation for HTTP interface client ● Spring Framework documentation for RSocket interface client ● Spring Cloud Square ● RetroSocket
  57. 57. Thank you Twitter: @olga_maciaszek © 2020 Spring. A VMware-backed project.

×