 OK. I'm Stephen Carsey. I work with Pivotal as does David here, based in London. Today's session. How many of you have used Spring Boot before? Excellent. Session over. So the session, as you said, is going to be a two-hour walkthrough of building a fairly complex application composed of many microservices. Dyna sy'n gwasanaeth, mynd i'n ddweud y ddweud yn y ddweud yn y ddweud a'n ddweud hynny fel hynny'n gwybod yw'r cyfrifio lluniau i'r ffurdd hynny yn ei ddweud. Dw i'n gweithio'r gweithwch o'r Ffryd Mwy. Ychyn ni'n gweithio i Labs now, dwi'n gofyn, rwy'n ei gweithio'r url yn ystod o bwysig ysgol yma, dwi'n gweithio'r Labs Ffryd Mwy. Mae'n gweithio i ffryd mewn y ddweud, yn y cynfiguretio o'r apl wedi bod yn gynnwys ar gyfer maen nhw. Yn gyffredinol gyda ar gyfer eich hwant yw Cloud Foundry, ymweld yw'r eich hyn sy'n gwneud, mae'n ffordd yn gwneud, yn ymweld yw'r ysgol. Felly, rydych chi'n gweithio i ymddangos am y gyrdd y mae'n gwneud y lab ar y llan. Mae'r rhai oedd â'r cyfrif yn gwneud y website i ymddangos, mae'r cyfrif yn ymddangos, mae'n hyn mewn i'w rhaid i'r URL, mae'n hyn yn unrhyw ymddiol. Dyna cae bydd David ychydig. Rydyn ni fydd gweld yn digwydd. Rwy'n meddwl addysg. Felly, rydych chi'n meddwl hynny yw Y Sprig Ynwyshgyddor i'wlluminat Tawn gael yw Josh? Mae'n meddwl, rwyf yn dechrau. Rwyf yn dechrau, hi. Mae rwyf yn dechrau a eu gwirionedd, byddai dynean. Mae'r tîm pan fyddwch chi'n ei wneud cyflyt yw yn i ddifael peon, felly mae'n meddwl hon yn ychwaneg mi o'r ddechrau. I'm going to just accept the defaults for my package, my application name, and I want to use a certain dependency so I can just type in a dependency here and say I want to use, I want to create a spring web app, I want to create a very basic web app which exposes a restful end point, I click on web, I click generate project, and that little fancy animation means I've got a zip somewhere. Firefox sticks it in downloads, I think, okay. Oh, okay, even better. Now I've just got to find STS, okay. So I'm going to import that into SpringTool Suite. I chose Gradle, so where are we? Over here. Yes, so, yeah. Deepinto downloads demo 2. And with a bit of luck, this should work. So, for those of you who have done Spring Boot, it does get a bit more advanced than this, don't worry. I'm just going to watch my application downloads and loads of libraries. So just out of curiosity, people who are using Spring Boot, you're using Spring Web, Spring Data, how many people are using very complicated Spring apps? I've got people staring at me. Who's using Spring Cloud? How many people are using deploying Spring apps to Cloud Foundry? Okay, cool. We didn't really need to be here at all. Okay, so it's obviously, here we go, it's kicking off. This is just downloading a bunch of libraries which is needed, I'm just going to say, hey, except I would like to import this project. It gives me an empty application over here in a minute, I guess it will. It's just downloading stuff. Hasn't appeared, does it? It's in other projects. That's not the one. Demo 2, I guess. There we go. So, here's my amazingly complicated application. I know it's a Spring Boot app because it's got an annotation in the beginning saying, hey, I'm a Spring Boot app. I'd like to make this a simple app which exposes a restaurant endpoint. I'm just going to create a new class here just to make life a bit easier for me. I'm going to call it my controller if I could spell. And Spring Boot makes life easy for me. I used to work for a company. They've got three letters in their name. Some people say it stands for I've been married. And in those days, we never had Spring or any kind of clever stuff. We used to do a lot of big, heavy monoliths. So the idea that I could come along and just say, hey, I'd like to create an app and just write an annotation at the beginning was really revolutionary for me. It's not completing because I guess it hasn't got its libraries and we're live. There we go. Best controller. Zoom it in. Okay. Sorry, I forget that you guys want us. Right. Yeah. Right. So all of it is created a new class and I've added a simple annotation at the beginning. And this is going to be a little hint for Spring Boot when it's running my app to say this is a class which is going to expose to restaurant endpoints. And I'm going to create the best method in the world, something that just says hello world. That's about the sort of level of my knowledge that I can get to. And I'm going to say return hello. And I like to execute this method every time someone hits my web app with a specific URL. Let's make that string. I'm just checking how many people are awake. So again, Spring Boot makes it really easy for me. I can just say map this to the path. Hello. Okay. Now, in the old days, when I used to work for that big company, this would have taken me about half a day of configuring and kind of playing around with XML files and opening up the web.xml and putting port mappings and stuff. But now, in theory, I should just be able to run as Spring Boot app. That's going to run the last configuration, I believe. Which is this one. And it's running another application. Right click on the demo too. Yeah, sorry. Let's close that. That one, I guess. Spring Boot application. So, for those of you who've never used Spring Boot before, Spring Boot has looked at the configuration of my application. It's realized that it's got a Spring web dependency. So it's automatically enabled Tomcat for me as a container that was run time for my application. It started it up on a default port of 8080. If I now just went to localhost 8080. I don't think you've got enough windows open. Could you open a few more, David? I'll try next time. I didn't map anything to that specific URL. What I did was I mapped it to hello. I should say hello. Cool. Awesome. Thank you very much. I'm available all three days for the summit. Now, let's get back to something more important. Which was our... Some more. There we go. Now, the labs that are in this URL are far more sophisticated. They walk through things like actuator. They walk through changing to use jetty instead of Tomcat. They walk through putting your own error handlers, putting metrics. Fairly comprehensive bunch of stuff. If you don't think that's enough, you could go to spring.io. There's loads more guides and doing consuming data from Facebook, Twitter, et cetera. Really useful. These slide decks will be made available so you can grab the URL after that. Now, we chose Spring Boot because we just think it makes life really easy. The speed of building an application is just really quick. It's great for building microservices. As you use Spring Boot to build several other microservices, you're going to reach some of the problems that people have had when they go down this route where, hey, now there's loads of complexity where one microservice talks to another microservice, I need some way of mitigating if one microservice was down, discovering other microservices. I need patterns to help us overcome some of these issues, specifically storing configuration, load balancing, monitoring, et cetera. The purpose of today's talk, Greenie, was, if we were doing a hands-on session, was to get you guys to build some of this. We're going to just rush through and show you a pre-built application and give you some links to where you can find out more about this. So, what am I talking about? Consider this application made up of three microservices. You've got a web front-end, you've got two sort of back-ends in two different domains. One for customer data, one for stores data. There's clearly some sort of dependencies that are loosely coupled to each other, but they need to know about each other's service to provide the functionality that they exhibit. How does customers know where stores is running? How does the web front end know where customers and stores is running? What happens if stores goes down? Does the whole application die? It's not a good practice. Now, if we could have some other supporting technology, like some sort of service discovery component alongside this, they could say, hey, every time a microservice comes up, register with me and I'll make a note of where you're running and what your URL is. Then other clients could then consume that at runtime. We could have a configuration server that's separate to this that stores vital information needed at runtime, that isn't hard-coded in the application, makes life a lot simpler. What we're going to talk about today is how some of these components, which if you follow Netflix, OSS and some of these other things, you might be familiar with this, how some of these technologies packed in to pivotal implementation of Cloud Foundry. So, we have a component called Spring Cloud Services Suite, that we've had on for our enterprise version of Cloud Foundry. It gives you a lot of these features out of the box and makes it really easy for you to build your applications using those capabilities. To show this, we've got an application called Springbit Trader, written by my colleague David Pinto, and he's going to walk you through some of the architecture and show you some of the benefits and show you how he's implemented and may take advantage of these features. Thank you. So, the good news is I'm not going to write any code, because I've did that before, and I'm just going to show you how easy or hard or difficult it is to implement some of these patterns that help you live in a Cloud-native world. So, the first one is configuration server, or configuration management. When you've got tens, hundreds, thousands of microservices, you might want to share some properties for the instance running that are running in Cloud Foundry. There could be multiple instances with different properties for different purposes. So, what is the best way, or what is one way of dealing with configuration? You want those properties to be auditable. So, when someone changes that, you know that that change was made, and you want to propagate that change to all of your instances. Within Python Cloud Foundry, we've got a Spring Cloud config server that connects to a Git repository to grab all of the properties that you need for your applications. And then each application goes to this configuration server to pick the properties that it needs in order to run. How do we set this up? Well, it's really complicated. If I find the right window, there we go. Let me just pick one of my services, like the user service, aptly name because it deals with users. And I go to my build.gradle file, or my POM file, and I just select one dependency, which is... There we go. So, by adding this dependency, it tells Spring Boot to go and grab the properties from this configuration server. By default, it will go to a specific local host and port number, but if you're running Pythclaw Foundry, you will pick up where this service is running automatically for you. So, that's it. No more to do to get the configuration management apart from setting your own properties. Next one is service discovery. If you call tens, hundreds, thousands of microservices running in the cloud, they can move about. They can be in one place today, and they can move to another place tomorrow. How do you figure out where they're running at runtime? Well, one technique to do this, and that's what Netflix uses, is for each application to register itself and say, this is my name, and this is where I live, so that other applications can go to these yellow pages and ask for particular services. It's like a directory. Again, this is very difficult to implement in Spring Boot, and I'm sure I've got one open here. Soph showed you how to build a Spring Boot application with this annotation. To add the service discovery capability, all you need is this other annotation. This means that the application will register itself and gives you the capability to look for other services that you've got access to. Again, no other configuration needed. In Python Cloud Foundry, where the registry is living is plumbed into your application automatically. The next one is, if you're dependent on other microservices, when you call them, you don't want to fail if those microservices aren't there. There is one rule in the cloud world, which is bad things do happen. Things fail. Hardware goes away, memory goes away, applications go away. How from your application can you ensure that you stay alive, even though other applications that you depend on fail? The circuit breaker pattern is how to sustain failure, how to be tolerant to failures. You've got a primary path where that's your dependent service that you're calling all the time. If that dependent service goes down, this circuit will open and it will stop contacting that primary service and it will go to a fallback service, or a method. Or you can just deal with that problem right there and then. Overtime, the circuit will try to close again and go to that primary service. And it will try it to see if it's come back to life. And if it is, it will open up the floodgates and will start contacting it again. How do we do this in the codes? Well, it's extremely difficult, as you can imagine. All we need to do is annotate a method with Histrix commands and you give it the fallback method. You can have as many fallback methods as you want and you can cascade down. So you don't just have to have a primary and a secondary service. You can have a third, fourth and fifth service if you're that paranoid. Pyptocall Foundry gives you visibility on what is happening with your circuit breakers. You can have as many as you want in your application and they'll show up in a nice little dashboard on how many calls you're getting a second, whether the circuit is open or closed and what the platform is doing for you. So the next thing that is really important in microservices world, in the cloud-native world, is how to trace a user request throughout your microservices. This is good to find out where the latency is within that call and also to figure out where the problem may exist. Spring Cloud gives you this flexibility. It gives you this ability with Spring Cloud Sleuth and it injects traceability through all of those requests and it gives you an ID that follows that request across all of your microservices. Again, as you can imagine, this is super complicated to do and if I show you the build.gradle again, this is another dependency, which is this one, Spring Cloud Sleuth. Spring Boot will take care of everything that it needs to do to give you that traceability across multiple applications that are developed by different teams and you get that traceability in a nice little UI which I don't have running here to show you, but you can trace your calls, your user requests from application to application. How are we doing for time? So Zipkin is the UI that shows you that traceability going from one microservice to the other of your user request. It gives you a nice little traceability how long that request is spending in each application as well which is very important when you're trying to performance test your overall system. So to summarize, what have we shown you over here? Well, A, you need a platform to run your microservices and to link them all together. You need a framework that allows you the velocity of development to spin up these microservices, test them, give them to your users and get the feedback. Spring Cloud gives you the framework to fix some of the challenges you see in the cloud world, whether that's configuration management or service discovery. And then you need Pyftal Cloud Foundry to run all of these applications of microservices for you and it will benefit from the data operations and self-feeling and so on. So your application, David, is it in GitHub? It is in GitHub. There was a link over there. These slides will be made available so you can just click on the link and it will take you to this page where you can find out more about the Spring Boot Trader application which is a set of four microservices. Very soon it will be five and it uses all of these cloud capabilities to register themselves, discover themselves. All the configuration is shared amongst all of the microservices so they all have the same properties. OK. Jonah. We have to obligratory mention dimensions and we are hiring at Pyftal when it was interested in working at us. There's a guy in our office called Harry Kang. He will be very pleased to see this slide. Any questions? Yes. Don't worry, it's fine. Yes, I do. That's a good question. How do you protect your sensitive data in the Git repository? There's a couple of different levels that you can go to. One is protect your Git repository itself so it's not public, especially in github.com. The other one is you can encrypt properties. So when you put into your Git repository that password is already encrypted and only the config server will be able to decrypt it. Does that answer your question? Good. What if I want to make changes to my properties while the application is running? Make the changes. It's absolutely fine. You can make the changes in your github repository and you can tell your applications to refresh their properties. So the question is, do you need to have different repositories for production, development, testing, the different environments? There's different ways of dealing with that. Git provides you with a lot of capabilities in terms of branches, different commits, different so on, and you can make use of that from the configuration server. So you can point your configuration server to the production branch or to the development branch. You can also use different repositories if you want. It's really done to the structure of your organization on the best way to deal with that. So the question is, if you want to use other registry services like console, is there a way to do that? Spring Cloud gives you that capability, but you need to deploy your own console cluster in order to provide that infrastructure. As part of Pivotal Cloud Foundry, currently we're using Eureka as that service implementation. The questions are getting trickier by the time. No, we're running out of time, don't worry. Time's over. I do have an answer for that. So the question is, it's great if you're using Spring to use all of these patterns. What about if you're using other languages like Go or Python or these funky languages? There are libraries for these languages to work with the Spring Cloud patterns. They are emerging, so there's already one for Go, one for Python, I believe, and there'll be more coming along the lines. I'm sure that .NET, if you're that way inclined, they've got a project called Steeltoe, which is to kind of capture the Spring Boot and Spring Cloud functionality within the .NET environments. I think we've got time for one more question. As long as there's an easy one. Oh, it's not an easy one. So the question is, does sleuth that traceability capability have any performance impact on the running application? That's a tricky one. It will have some impact, obviously, but it's minimal because it's done asynchronously on the calls. Most of it is done asynchronously on the calls. If you're just logging the correlation ID to the logs, the performance penalty is minimal. If you're actually streaming those calls for the traces into Zipkin, for example, that's done asynchronously either through a bus or through HTTP requests. So it shouldn't have much of an impact on the latency of the application. On that note, ladies and gentlemen, thank you very much. We are going to be at a pivotal booth if you've got any more questions. I think we're there for half one today. But if you don't find us to other pivotal colleagues around, you can answer your questions. Thank you very much.