Slide 1

Slide 1 text

Micro Services Development 1 2022 Dan Erez With better collaboration…

Slide 2

Slide 2 text

2 SpringIO 2022 Who am I? • Lead Architect @AT&T • +20 years of software development • Native language: Java • Enterprise Architecture • Cloud Architecture • Serverless • Speaker • Trying to innovate…See in medium (dan.erez) 2

Slide 3

Slide 3 text

• Background for the story • Spring Boot/Cloud and our environment • Problem in collaboration • Our solution • Demo • Q&A&Sharing Agenda 3 SpringIO 2022

Slide 4

Slide 4 text

• Innovation in government?! • New application, written from scratch, agile • Multiple programming languages • Faster, smaller, independent deployments • Easier to test • Independent scaling Who were we and why did we choose MSA? 4 SpringIO 2022

Slide 5

Slide 5 text

5 SpringIO 2022 • Many code bases to maintain, CI/CD them • Multiple programming languages isn’t always good • Getting complex fast, Services # rises • Many (different) databases • Debugging/Tracing Downsides of MSA 5

Slide 6

Slide 6 text

6 SpringIO 2022 What it looks like 6

Slide 7

Slide 7 text

7 SpringIO 2022 • Tools/Frameworks for distributed apps (not just cloud!) • Introduced in 2014! • 33 items in the spring cloud docs! • Examples: distributed locks, configuration, circuit breakers, load balancing, and many more… Spring Cloud – A Quick Intro 7

Slide 8

Slide 8 text

8 SpringIO 2022 • How do you find a service? • Servers shall rise and fall • Maybe we have several instances • How to separate environments? • Eureka! How does it work? Spring Cloud - Discovery 8

Slide 9

Slide 9 text

9 SpringIO 2022 Spring Cloud - Discovery 9

Slide 10

Slide 10 text

10 SpringIO 2022 • The Gatekeeper / Gateway • Routes by URL to a service • Find services using Eureka • Load Balance using Ribbon • Can check or add headers • Can be extended (e.g., to log requests) Spring Cloud - Zuul 10

Slide 11

Slide 11 text

11 SpringIO 2022 • Global configuration • Can be stored in a file or DB or in… • The best option: git! • Configuration load priorities Spring Cloud - Configuration 11

Slide 12

Slide 12 text

12 SpringIO 2022 • Shows running services (Eureka) and their health (Actuator) • Shows properties • Shows logs and control log levels • And a lot more… Spring Cloud - Admin 12

Slide 13

Slide 13 text

13 SpringIO 2022 Spring Cloud - Admin 13

Slide 14

Slide 14 text

14 SpringIO 2022 Spring Cloud - Admin 14

Slide 15

Slide 15 text

15 SpringIO 2022 Spring Cloud - Admin 15

Slide 16

Slide 16 text

16 SpringIO 2022 MSA & Spring Cloud 16

Slide 17

Slide 17 text

17 SpringIO 2022 • The number of micro services went up • For developers to develop and test (integration), should they: • Run everything locally ? OR • Run only one service locally and the rest on a central environment? The problem… 17

Slide 18

Slide 18 text

18 SpringIO 2022 Local and Central 18

Slide 19

Slide 19 text

19 SpringIO 2022 • How much memory do you have? • Chasing the latest versions • What about configuration/parameters? • Oh, and the databases… Run Local 19

Slide 20

Slide 20 text

20 SpringIO 2022 • Who maintains it? • Duplicated services (local and central) causes issues (one Eureka service for everyone…) • What if I break something, or even debug… Run Central 20

Slide 21

Slide 21 text

21 SpringIO 2022 • Another option: Full environment for everyone! • Again, Who’s maintaining? • It’s going to cost you… • Could K8S help here? Go to cloud? 21

Slide 22

Slide 22 text

Our Solution – The ‘What’ • Hybrid approach: • Run only what you need locally • Use central environment for the rest • Somehow, route only relevant requests locally • Sounds great, but how? 22 SpringIO 2022

Slide 23

Slide 23 text

23 SpringIO 2022 Our Solution - how • Work with the global discovery (to find central services) • Local services would register under a different and unique name, in the global discovery: • E.g., Payment -> my-machine.Payment • Smarter Gateway (Extend Zuul): • If the request to service X comes from my- machine, and there’s my-machine.X -> Route to my machine 23

Slide 24

Slide 24 text

24 SpringIO 2022 Our Solution - how 24

Slide 25

Slide 25 text

25 SpringIO 2022 Some Code - registering 25 @Value("${dev.discovery:false}") private Boolean devDiscovery; @Bean @Autowired public EurekaInstanceConfigBean eurekaInstanceConfigBean(final InetUtils inetUtils) { String newAppName = getHostname() + "." + appName; config = new EurekaInstanceConfigBean(inetUtils) { @Override public void setEnvironment(Environment environment) { super.setEnvironment(environment); if (devDiscovery != null && devDiscovery == true) { setAppname(newAppName); setVirtualHostName(newAppName); setSecureVirtualHostName(newAppName); } } }; … config.getMetadataMap().put("instanceId", config.getHostname() + ":" + config.getAppname() + ":" + port); return config; }

Slide 26

Slide 26 text

26 SpringIO 2022 Some Code – Zuul Filter 26 String machineName = getRemoteHostName(request); String serviceName = getServiceName(request.getRequestURL().toString()); String newName = machineName + "." + serviceName; // If the request came from someone who registered the desired service as running locally - redirect List localServices = discovery.getInstances(newName.toLowerCase()); if (localServices != null && !localServices.isEmpty()) { // We assume only one local instance ServiceInstance si = localServices.get(0); // Change this request context – go to the local service ctx.put(FilterConstants.SERVICE_ID_KEY, si.getServiceId()); }

Slide 27

Slide 27 text

27 SpringIO 2022 Demo Time 27

Slide 28

Slide 28 text

Too shy to ask here? • Dan Erez in LinkedIn • [email protected] • Feel free to consult (Micro Services, Serverless, Clouds, Whatever…) Q&A & Thank you! 28 SpringIO 2022