Slide 1

Slide 1 text

Olga Maciaszek-Sharma Improve developer experience with Spring Interface Clients Copyright © 2022 VMware, Inc. or its affiliates.

Slide 2

Slide 2 text

About Olga Staff Software Engineer in Spring Cloud team Spring Cloud LoadBalancer, Spring Cloud OpenFeign, Spring Cloud Netflix, AOT and native image support in Spring Cloud projects, Spring Interface Clients

Slide 3

Slide 3 text

What is a declarative client?

Slide 4

Slide 4 text

Sample applications Customer Service Verification Service HTTP POST /verify Customer Verification Result

Slide 5

Slide 5 text

Direct use of HTTP client

Slide 6

Slide 6 text

Client interface

Slide 7

Slide 7 text

Implementation

Slide 8

Slide 8 text

Implementation with helper methods

Slide 9

Slide 9 text

Client interface usage

Slide 10

Slide 10 text

Annotated interface ⭆ HTTP calls Libraries/ frameworks already do it for us!

Slide 11

Slide 11 text

Declarative/ interface client Client interface method calls HTTP calls Proxy

Slide 12

Slide 12 text

Other implementations and support in Spring

Slide 13

Slide 13 text

Feign & Spring Cloud OpenFeign https://github.com/OpenFeign/feign https://github.com/spring-cloud/spring-cloud-openfeign

Slide 14

Slide 14 text

OpenFeign/Feign

Slide 15

Slide 15 text

A declarative/ interface client

Slide 16

Slide 16 text

Retrofit & Spring Cloud Square https://github.com/spring-projects-experimental/spring-cloud-square

Slide 17

Slide 17 text

Retrosocket https://github.com/spring-projects-experimental/spring-retrosocket

Slide 18

Slide 18 text

Spring Interface Clients HTTP

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

@HttpExchange

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

@HttpExchange attributes url method contentType accept

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

@HttpExchange @GetExchange @PostExchange @PatchExchange @PutExchange @DeleteExchange

Slide 29

Slide 29 text

Parameters

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Overriding URI

Slide 33

Slide 33 text

“/”

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Overriding base URL

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Object Map/ MultiValueMap Collection

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Object Map/ MultiValueMap Collection

Slide 42

Slide 42 text

Object Map/ MultiValueMap Collection

Slide 43

Slide 43 text

WebClient - working with request attributes

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Return values

Slide 48

Slide 48 text

Blocking

Slide 49

Slide 49 text

Reactive

Slide 50

Slide 50 text

Status, headers, body

Slide 51

Slide 51 text

Headers

Slide 52

Slide 52 text

Execute only

Slide 53

Slide 53 text

Instantiating HTTP clients ● Create HttpServiceProxyFactory bean ● Create service instance bean

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Error handling

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Load-balancing Use instrumented WebClient/ RestClient/ RestTemplate

Slide 63

Slide 63 text

DiscoveryClient Eureka Consul Zookeeper Kubernetes SimpleDiscoveryClient

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Load-balanced client builder bean You can use @LoadBalanced as qualifier serviceId in place of host:port

Slide 66

Slide 66 text

Load-balanced client builder bean You can use @LoadBalanced as qualifier serviceId in place of host:port

Slide 67

Slide 67 text

Load-balanced client bean You can use @LoadBalanced as qualifier serviceId in place of host:port

Slide 68

Slide 68 text

Tracing Provided by instrumented WebClient/ RestClient/ RestTemplate

Slide 69

Slide 69 text

@HtttpExchange on server side

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

Spring Interface Clients RSocket

Slide 72

Slide 72 text

RSocket Reactive Streams semantics on protocol level ● Message-driven, asynchronous ● No client/ server distinction once connection is made ● 4 modes ○ Fire and Forget ○ Request/ Response ○ Request/ Stream ○ Channel

Slide 73

Slide 73 text

RSocket Reactive Streams semantics on protocol level ● Binary ● Flow control ○ Backpressure ○ Leasing ● Protocol support: ○ TCP ○ WebSockets ○ Aeron ○ QUIC?

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

@RSocketExchange

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Destination

Slide 78

Slide 78 text

Parameters

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Handle added metadata in responder

Slide 83

Slide 83 text

Return values

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

Instantiating RSocket clients ● Create RSocketServiceProxyFactory bean ● Create service instance bean

Slide 87

Slide 87 text

Set up RSocket strategies, including encoders and decoders

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

@RSocketExchange annotated responders

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

AutoConfigurations

Slide 92

Slide 92 text

Enable AutoConfiguration A separate switch annotation/ a property/ looking for per-client annotation

Slide 93

Slide 93 text

Find annotated interfaces Any interface with @...Exchange/ Dedicated annotation per client

Slide 94

Slide 94 text

Match HTTP clients with infrastructure ● Find/ create WebClient/ RestClient/ RestTemplate/ RSocketRequester ● Find/ create HTTP/ RSocket ServiceProxyFactory ● Qualifier/ dedicated annotation/ naming convention ● Default and per client implementations

Slide 95

Slide 95 text

Registering bean definitions ImportBeanDefinitionRegistrar/ BeanDefinitionRegistryPostProcessor/ FactoryBean

Slide 96

Slide 96 text

Existing implementations https://github.com/joshlong/declarative-client-registration https://github.com/maciejwalkowiak/spring-boot-http-clients

Slide 97

Slide 97 text

GitHub issue https://github.com/spring-projects/spring-boot/issues/31337

Slide 98

Slide 98 text

SAMPLE

Slide 99

Slide 99 text

https://github.com/OlgaMaciaszek/interface- clients-spring-io-2024-demo

Slide 100

Slide 100 text

100 Broadcom Proprietary and Confidential. Copyright © 2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. Check out what’s happening at the VMware Tanzu Booth! And beyond Meet & Greet Josh Long | May 30 16:00-16:30 Customer appreciation party | May 30 21:00- 23:00 | Camping Mar Spring Office Hours Live with DaShaun Carter and Dan Vega | May 31 11:00 - 12:30 Grand Raffle | May 31 16:30

Slide 101

Slide 101 text

Thank you [email protected] @olga_maciaszek © 2020 Spring. A VMware-backed project.