Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Spring Boot Based Collaboration

Spring Boot Based Collaboration

Developing software based on micro services architecture is extremely easy when you use spring boot and spring cloud. Just throw in a few lines of code and you can have a micro service up and running. But when you have many micro services it’s not easy to run and maintain all of them locally, so you use a central deployment. But if all developers do it, how can they work simultaneously on the same central spring cloud environment and still not interrupt each other? In this talk, I will you show you how and boost your productivity along the way.

dragon74

June 07, 2022
Tweet

Other Decks in Programming

Transcript

  1. 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
  2. • Background for the story • Spring Boot/Cloud and our

    environment • Problem in collaboration • Our solution • Demo • Q&A&Sharing Agenda 3 SpringIO 2022
  3. • 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 19 SpringIO 2022 • How much memory do you have?

    • Chasing the latest versions • What about configuration/parameters? • Oh, and the databases… Run Local 19
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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; }
  17. 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<ServiceInstance> 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()); }
  18. 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