65
1 © 2016 Pivotal Consumer Driven Contracts and Your Microservice Architecture Marcin Grzejszczak, @mgrzejszczak

Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

Embed Size (px)

Citation preview

Page 1: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

1 © 2016 Pivotal

Consumer Driven Contracts and Your Microservice Architecture

Marcin Grzejszczak, @mgrzejszczak

Page 2: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

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

Page 3: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

3

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

Introduction

Demo

Summary

Agenda

Page 4: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

4

What we will NOT be talking about?

Page 5: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

5

What we will NOT be talking about?

THE IDEA OF SPRING CLOUD CONTRACT IS NOT TO

INTRODUCE UNNECESSARY COUPLING OR REPLICATE OLD

MISTAKES

Page 6: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

6

Introduction

Page 7: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

7

Introduction

What problems are we trying to solve?

Page 8: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

8

Introduction

Typical situation

HTTP

CONSUMER PRODUCER

Page 9: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

9

Introduction

How to write a test for it?

HTTP

CONSUMER PRODUCER

Page 10: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

10

Introduction

How to write a test for it?

HTTP

CONSUMER PRODUCER

Page 11: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

11

Introduction

Stub validity & reusability

WE’RE ON THE CONSUMER SIDE!!

CONSUMER OWNS THE STUB DEFINITIONS

Page 12: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

12

Introduction

Stub validity & reusability

Page 13: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

13

Introduction

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

Page 14: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

14

Introduction

Stub validity & reusability

Page 15: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

15

Introduction

So now what?

Page 16: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

16

Introduction

Ooops...

Page 17: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

17

Introduction

What went wrong?

HTTP

CONSUMER PRODUCER

TEST

OK

HTTP

CONSUMER PRODUCER

REALITY

WAT?!

Page 18: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

18

Introduction

Another example with messaging

CONSUMERPRODUCER

TEST

PRODUCER CONSUMER

REALITY

topic: bar topic: foo

topic: bar

Page 19: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

19

Introduction

Stub validity & reusability

Page 20: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

20

Introduction

Nice API creation

Page 21: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

21

Introduction

Nice API creation - no cooperation results

Page 22: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

22

Introduction

Nice API creation - no cooperation results

Page 23: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

23

Demo

Potential answer

Spring Cloud Contract

Page 24: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

24

Demo

What are we going to code?

Page 25: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

25

Demo

What are we going to code?

Page 26: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

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!

Page 27: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

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!

Page 28: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

28

Introduction

What are we going to code?

Someone’s 22. Check him out!

CONSUMERPRODUCER

Positive verification took place

Messaging

Page 29: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

29

Introduction

What are we going to code?

Someone’s 17. Check him out!

CONSUMERPRODUCER

Negative verification took place

Messaging

Page 30: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

30

Introduction

What are we going to code?

BLACK TERMINALBLACK IDE

CONSUMER

WHITE TERMINALWHITE IDE

PRODUCER

Page 31: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

31

Demo

Page 32: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

32

Summary

Page 33: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

33

Summary

PRODUCER CONSUMER

Page 34: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

34

Summary

PRODUCER

CONSUMER CLONES

PRODUCER

PRODUCERCLONE CONSUMER

Page 35: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

35

Summary

PRODUCER CONSUMERCONSUMER

CLONES PRODUCER

PRODUCERCLONE

INTERACTION

Page 36: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

36

Summary

PRODUCER CONSUMERPRODUCER

CLONE

INTERACTION

CONSUMER FILES A PR

Page 37: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

37

Summary

Page 38: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

38

Summary

PRODUCER

TAKES OVER THE PR

Page 39: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

39

Summary

PRODUCER

TAKES OVER THE PR

WRITES THE MISSING IMPLEMENTATION

Page 40: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

40

Summary

PRODUCER

TAKES OVER THE PR

WRITES THE MISSING IMPLEMENTATION

MERGES TO MASTERCI UPLOADS TO NEXUS /

ARTIFACTORY

Page 41: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

41

Summary

Page 42: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

42

Summary

CONSUMER

SWITCHES TO ONLINE MODE

DOWNLOADS STUBS OF COLLABORATORS DURING

BUILD PHASE

Page 43: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

43

Summary

Page 44: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

44

Summary

Page 45: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

45

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

Page 46: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

46

Demo

Page 47: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

47

Common repo with contracts - consumer

PRODUCER CONSUMER

Page 48: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

48

Common repo with contracts - consumer

PRODUCER CONSUMER

REPO WITH CONTRACTS

Page 49: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

49

Common repo with contracts - consumer

PRODUCER CONSUMER

REPO WITH CONTRACTS

GIT CLONE

CLONED REPO WITH

CONTRACTS

Page 50: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

50

Common repo with contracts - consumer

PRODUCER CONSUMER

REPO WITH CONTRACTS

GIT CLONE

CLONED REPO WITH

CONTRACTS

INTERACTION

Page 51: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

51

Common repo with contracts - consumer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CLONED REPO WITH

CONTRACTS

PR

Page 52: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

52

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

Page 53: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

53

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CLONED REPO WITH

CONTRACTS

PRODUCER

TAKES

OVER PR

Page 54: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

54

WRITES THE MISSING IMPLEMENTATION

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CLONED REPO WITH

CONTRACTS

PRODUCER

TAKES

OVER PR

Page 55: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

55

WRITES THE MISSING IMPLEMENTATION

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CLONED REPO WITH

CONTRACTS

MERGE PR

Page 56: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

56

WRITES THE MISSING IMPLEMENTATION

Common repo with contracts - producer

PRODUCER CONSUMER

REPO WITH CONTRACTS

CI UPLOADS TO NEXUS

/ ARTIFACTORY

Page 57: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

57

●●

●●●

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

Page 58: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

58

I don’t want to write any scripts!

Page 59: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

59

Introduction

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

Page 60: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

60

Demo

Page 61: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

61

Summary

Page 62: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

62

Summary

Page 63: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

63

QUESTIONS

Page 65: Consumer Driven Contracts and Your Microservice Architecture @ Warsaw JUG

65

mgrzejszczak