Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

Preview:

Citation preview

1 © 2016 Pivotal

Consumer Driven Contracts and Your Microservice Architecture

Marcin Grzejszczak, @mgrzejszczak

2

background image: 960x540 pixels - send to back of slide and set to 80% transparency

Spring Cloud developer at PivotalWorking mostly on

● Spring Cloud Sleuth ● Spring Cloud Contract● Spring Cloud Pipelines

About me

Twitter: @mgrzejszczakBlog: http://toomuchcoding.com

3

background image: 960x540 pixels - send to back of slide and set to 80% transparency

Introduction

Demo

Summary

Agenda

4

What we will NOT be talking about?

5

What we will NOT be talking about?

THE IDEA OF SPRING CLOUD CONTRACT IS NOT TO

INTRODUCE UNNECESSARY COUPLING OR REPLICATE OLD

MISTAKES

6

Introduction

7

Introduction

What problems are we trying to solve?

8

Introduction

Typical situation

HTTP

CONSUMER PRODUCER

9

Introduction

How to write a test for it?

HTTP

CONSUMER PRODUCER

10

Introduction

How to write a test for it?

HTTP

CONSUMER PRODUCER

11

Introduction

Stub validity & reusability

WE’RE ON THE CONSUMER SIDE!!

CONSUMER OWNS THE STUB DEFINITIONS

12

Introduction

Stub validity & reusability

13

Introduction

Let’s assume that we’re introducing a new endpoint...

14

Introduction

Stub validity & reusability

15

Introduction

So now what?

16

Introduction

Ooops...

17

Introduction

What went wrong?

HTTP

CONSUMER PRODUCER

TEST

OK

HTTP

CONSUMER PRODUCER

REALITY

WAT?!

18

Introduction

Another example with messaging

CONSUMERPRODUCER

TEST

PRODUCER CONSUMER

REALITY

topic: bar topic: foo

topic: bar

19

Introduction

Stub validity & reusability

20

Introduction

Nice API creation

21

Introduction

Nice API creation - no cooperation results

22

Introduction

Nice API creation - no cooperation results

23

Demo

Potential answer

Spring Cloud Contract

24

Demo

What are we going to code?

25

Demo

What are we going to code?

26

Introduction

What are we going to code?

I’m 22 give me a beer

CONSUMER PRODUCER

There you go!

Can he get the beer?

Yes!

27

Introduction

What are we going to code?

I’m 17 give me a beer

CONSUMER PRODUCER

Get lost!

Can he get the beer?

No!

28

Introduction

What are we going to code?

Someone’s 22. Check him out!

CONSUMERPRODUCER

Positive verification took place

Messaging

29

Introduction

What are we going to code?

Someone’s 17. Check him out!

CONSUMERPRODUCER

Negative verification took place

Messaging

30

Introduction

What are we going to code?

BLACK TERMINALBLACK IDE

CONSUMER

WHITE TERMINALWHITE IDE

PRODUCER

31

Demo

32

Summary

33

Summary

PRODUCER CONSUMER

34

Summary

PRODUCER

CONSUMER CLONES

PRODUCER

PRODUCERCLONE CONSUMER

35

Summary

PRODUCER CONSUMERCONSUMER

CLONES PRODUCER

PRODUCERCLONE

INTERACTION

36

Summary

PRODUCER CONSUMERPRODUCER

CLONE

INTERACTION

CONSUMER FILES A PR

37

Summary

38

Summary

PRODUCER

TAKES OVER THE PR

39

Summary

PRODUCER

TAKES OVER THE PR

WRITES THE MISSING IMPLEMENTATION

40

Summary

PRODUCER

TAKES OVER THE PR

WRITES THE MISSING IMPLEMENTATION

MERGES TO MASTERCI UPLOADS TO NEXUS /

ARTIFACTORY

41

Summary

42

Summary

CONSUMER

SWITCHES TO ONLINE MODE

DOWNLOADS STUBS OF COLLABORATORS DURING

BUILD PHASE

43

Summary

44

Summary

45

I don’t want to keep my contracts with the producer

46

Demo

47

Common repo with contracts - consumer

PRODUCER CONSUMER

48

Common repo with contracts - consumer

PRODUCER CONSUMER

REPO WITH CONTRACTS

49

Common repo with contracts - consumer

PRODUCER CONSUMER

REPO WITH CONTRACTS

GIT CLONE

CLONED REPO WITH

CONTRACTS

50

Common repo with contracts - consumer

PRODUCER CONSUMER

REPO WITH CONTRACTS

GIT CLONE

CLONED REPO WITH

CONTRACTS

INTERACTION

51

Common repo with contracts - consumer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CLONED REPO WITH

CONTRACTS

PR

52

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

53

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CLONED REPO WITH

CONTRACTS

PRODUCER

TAKES

OVER PR

54

WRITES THE MISSING IMPLEMENTATION

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CLONED REPO WITH

CONTRACTS

PRODUCER

TAKES

OVER PR

55

WRITES THE MISSING IMPLEMENTATION

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CLONED REPO WITH

CONTRACTS

MERGE PR

56

WRITES THE MISSING IMPLEMENTATION

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CI UPLOADS TO NEXUS

/ ARTIFACTORY

57

●●

●●●

I don’t want to keep my contracts with the producer

58

I don’t want to write any scripts!

59

Introduction

Don’t worry! You can use Spring Cloud Contract WireMock with Rest Docs!!

60

Demo

61

Summary

62

Summary

63

QUESTIONS

65

mgrzejszczak

Recommended