Effective Spring Boot on Google Cloud Platform

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
thank you so much for having me here it's a difficult times these days and um you know it is 1:35 a.m. in my time zone which is New York and that's why I'm speaking a little softer so I don't wake up my neighbors and I'm a developer advocate for Google Google cloud and I love to bring some of the latest and greatest technology that we have to Java developers especially to screen good developers and I myself and other engineers have worked with the pivotal in past with a spring engineers to create this project called sprinkle TCP and off to show you some of the new things that we have in the store so if you have any questions you can find me on twitter which is saturn ism or you can find one of the content materials workshops my website which is saturdays I'm Tommy so about two years ago I started off with a proof of concept to make Google cloud really really easy to use with spring boot and the proof of concept focus on just making our database spin are really easy to use and then they grow into this awesome project called sprinkle GCP which has a number of really idiomatic easy to use spring both starters that can help you to create your new services or migrate existing services you know adopt UCP services very very easily and the engineering team here at Google really work together with the spring engineers as well to make sure that the integration is automatic and it's something that's really useful for you as well and we have today about oh I don't know like about 14 integrations spanning across all of the different cross-cutting concerns from configuration with our secret manager to store your secrets credentials and configuration to messaging what pops up to multiple database options here including a reactive data store and our 2d BC driver and also hibernate if you want to use that there's just a lot of these integrations that we just made for sprinkle developers to use so that you can write applique the way that you are accustomed to while being able to leverage many of these capabilities for the operation perspective we have starters for you to hook in to start driver trays to get centralized logging to get metrics into your monitoring and also security as well so I'm gonna try to go through some of these things with only demos so it is 1:35 a.m. in the morning I hope you're awake I'm awake and we can get through this in about 30 minutes or so now that I show everything here but hopefully just enough for you to get a good sense of what we're dealing with okay so of course I'm gonna start off with the spring initializer and here you can pick and choose the capabilities that you want the really really important part of it is that we do have GCP support that you can pick and choose we do have a few other ones even though we have about 14 different integrations we can only show three here so just remember there is more than what you see in the drop-down but the easiest way for you to get started is to generate a new application with GCP support for this demo what I'm going to use is maven because that's the only beauty tool I know how to use and I'm going to use Kotlin just because it's a it's gonna be a little faster for me to type and concise and it's a great language which I want developers to learn and here we go so I actually bootstrap my application already this is all just generated directly from initializer just a few minutes ago as you can see this is using automatically importing the spring cloud version here with Hoxton that's the version that works with spring PO 2.2 and the spring cloud GCP project here is actually part of the release train so if you're using Hoxton release or a green witch release you can actually use spring cloud GCP services and adopters immediately okay and what we're going to do is to just sell write a simple app that we'll be able to use you know our database behind the same something that's really amazing that goes beyond a regular sequel database and then we're going to add capabilities with messaging we're going to add trains we're going to have centralized logging and if we're lucky we will have time to also deploy this into our environment and maybe even a little bit more well see if we can get this done in about 30 minutes or so okay so in this app I actually already just added a few lines of code here right usually when we start a sprinkler application we want to talk with the database you will create a POJO that will be used for or M or the object relational Makani and because I'm using calling here I'm creating the data class now of course we can use the regular sequel databases like my sequel cloud post quest sequel or even an MS sequel on Google Cloud it's really simple and straightforward to create one of the instances right we can actually go here to the console and create a new sequel instance and if you want to create a new instance you can just pick and choose the type of database that you want to create and then we can automatically configure highly available configurations for you with a master and worker affair overs across multiple zones or region okay but today on Google cloud we also have a number of other choices for example we have to know sequel databases that you can use that's fully managed so that you don't actually have to manage anything yourself and for that it's called fire store and it's data store so these are document oriented dynamics and sometimes they're your data is still relational and just to use a no secret data store for scalability is not the best option because you do have relational data in that case you still want to use a relational database but wouldn't it be nice to have a relational database that is horizontally scalable as you need to and strongly consistent in relational those three things don't usually work together and that's why we have ideas of no sequel right there's the cap theorem and stuff like that usually you only get two capabilities out of the three on Google cloud we have another database here called cloud spanner and this is a really amazing database which you can just create a new instance and that can span across the globe if you want to across three continents and it will still be strongly consistent and you can still scale them out horizontally okay so if you ever need new capacity you can just add another note so today rather than showing you know the regular secret database stuff I'm just going to show you how to do this very easily in this fully managed database called spanner so the first thing I'm going to do is to create a new instance so I'm gonna called out instance demo for example it's my demo instance and here I can pick and choose the availability that I want I can have it within a single region that will be you know spread across multiple availability zones or I can create our instance that's spread across multiple regions and so for example I can use this multimeric on Europe and Asia region it's right so we have a global you should be the database or I can pick one that's specifically only within North America for example and can pick and choose the number of notes that I want and with this type of configuration we can get 99.99% of the ability which is amazing for something that you can just create in a few seconds and that is it we just created a new spanner database and that we can go ahead and create a new schema in my code you see here I have a person object here we have the ID and the name now for spanner what we really want to do is to avoid any auto increment I piece because it is horizontally scalable so we will shard the data for you we will organize the data for you behind the scenes but if the ID is strictly increasing in incrementing other things will be really difficult too short to stay down and for that reason we want to use something that's moving them like UUID okay so I'm going to go ahead and create a new table here just called the person and then I'm gonna add a new ID here but rather than using a number I'm going to use a string to each store UUID and that's typically about 36 characters long I'm gonna set it to not normal and I'm gonna set a name here to your string as well because I do have a field called name and I'm gonna continue and I can add the ID as to my primary key now of course if you don't want to go through this vwi you can always use the DDL so you can document your table creations and you can run this to a script as you provision with database go ahead and create this so I just created at the brand-new multi-regional database that's strongly consistent and relational in a few seconds and now it's ready to be used that's pretty pretty cool so what do I do here in my code with the sprinkle GCP integration is that first I can go ahead and add the spanner starter so everything that we have we created really easy to adapt starters so here we have the spring swing data adapter for spinner and remember we have the same thing for datastore and fire store and this is just as this you use this Tim white thang so for the POJO I'm going to go ahead and annotate this with table okay so rather than using in the GPA entity I'm just gonna use table for that ID I will mark it as a primary key and that is really it and for the repository I can continue to use the paging and sorting repository that everyone's familiar with but I can also just you know annotate this with the repository or we went so far to also integrate with the repository rest resource so that we can expose this directly as the restful interface using string data rest and we also integrate it with all the finder methods so we can for example infer the find methods for you automatically or we can also annotate to the method with a curry method as well and many other things with things explained data like all of the team and the Senegal events with somebody in search of the new piece of information using spinner through this repository you can receive the event and you can act accordingly I swallow okay and just like that we will be able to access my spinner database with crowd operation now just to make things a little bit more interesting I'm going to go ahead and just create a little rest controller here which is hollow controller I'm going to get a configuration here for greeting so that in the end I can just return a greeting message right so if you say hello to this endpoint I'm gonna say hello back okay and I'm going to just go ahead in this current case I'm going to go ahead and ooh what happened to my keyboard oh I know what happened caps lock that's a dangerous thing to have in your life demo and especially with the VI binding with the cock-block you don't know what the ID is doing anymore okay into AJ you're drunk alright anyways from here on what I'm going to do is go ahead and automatic inject my person repository okay and then I can just do some responsibility to save a new person so I'm gonna say person repository not safe and I can go in and create person not because I'm using cotton I can use this really nice constructive ear parameters so our function parameters here so I can say ID is equal to e UI d dot random UID dot two string and the name is the name I received and that's pretty much it so right now I have a hollow endpoint that can receive the name and I can save you two months span a database but also using the rest interface as well so let me go ahead and give it a try but before I do it I also need to make sure that I have configured my sprinkler application to point to this newly created spinner instance so from the application type properties I can go ahead and find my configuration as you can see we have all the properties Auto populated here reading into OJ with Auto completion that is super useful for me as well because I cannot possibly remember all the possible things that we can configure here there's a lot but the auto completion is really awesome so I can do is call in and create configure my instance and my database which I just created and let's go ahead and run this now is going to start one thing I'm going to note is that it will automatically discover the credentials that's currently on my machine okay so what that means is that when this the kitchen starts you automatically discover the credential that I can actually use to connect to Google cloud in this case to spanner and this credential is actually stored using the command line here at Kochi cough this is the COI the command line interface that allows you to access all of Google cloud just from the command and there's a little come in here you can do which is alt and you can do application default blogging and what this will do is to use OAuth 2 to authenticate you and then we'll pull down the credential and store that in a well-known location in your home directory and when the application starts is going to discover this credential automatically and then you will use that credential to connect but that's only for development purposes if you're running in a Google cloud environment typically you are able to discover the credit issue from a metadata server so that you can get this credential directly from the runtime environment if you want to be super safe you can also create a service account which is a private key that's embedding in a JSON file and you can use a service account as a credentialing can configure the application to use that instead okay so if you're running on premise you can use the service account you have a running in Google cloud environment we can use our pro discovery and if you're running locally use g-cloud to authenticate and everything will be connected so let's go ahead and give this application a try I'm going to go ahead and create a new file here called test of HTTP this is a really easy and simple way in IntelliJ for me to send out a web request so hopefully this work come and say hello name is Joshua sunrise when I say hello Josh and Ron Davis and hopefully ooh what is that table not found oh ha ha I think I must have missed configured my instance a little bit yeah of course that I made a mistake here my instance name is called demo but my database name is called person and my table in the end is also called person so let me go ahead and fix this ok so I'm going to go ahead and fix this my database name is called person that's a really bad mistake because my database name is missing less a table name who does that so hopefully young we can get this up and running a second I do want to say hi to Josh since he's here also and I see a lot of many other familiar faces - so I'm gonna say hi to everyone in a second okay so let me try this again when I say test HBP see how it's Josh and oh this one actually works and when we say hello back right that's pretty straightforward and I can also see this data directly from the rest repository - so if I go to the root I should be able to see that how the persons rest repository if I go to prisons then I will be able to see that this piece of information this I should be there and of course if I want to I can also dig in into this sub URL that's unique to this to this record okay of course you might be saying wait a second what if that's just embedded no you know embedded database that you see memory it is not it's actually in the Spenard database if I go back to my newly created instance here if I go to data I should be able to see this information right here but now you might be saying wait a second that could be there this whole time so this could still can be faked so I'm gonna say is I think Adrienne code is online so I'm gonna say hello Adrienne and store say hello store this piece of information come back here and I need to do a little refresh and it's gonna do that and go to data and there he is it's pretty cool if you are going to write a micro service that requires in synchronous operation sometimes you may want to offload the processing of the data to another process then maybe you want to consider using a messaging key right and I being in consulting and in the Java space for 15 years and I'm also in a previous company I also had to set up a highly available messaging system and that is not fun it can be very difficult to do especially if you're on premise in the cloud while we can is to simply create a messaging topic with a few clicks and without any backing infrastructure that you have to maintain you get a globally available highly available messaging system that you can send information and receive the data from the message queue so let's see how this work so what I'm going to do is to create a topic that will that we will send the person's name to as soon as somebody says hello and then we're going to create a little subscriber that will quickly receive this information and then you can do with the processing that you need to so to do that what we're going to do is use something called pops up okay and pops up G stands for publish and subscribe and pops up system on Google count is global by nature it's a service seeing the way that you don't actually have to maintain any back-end infrastructure this is highly available out of the box so I'm going to create a new topic here called people which I'm going to send the names to and that is it in half a second I have a new messaging system ready to go and now I can go ahead and create a subscription so here I can call this people subscription so I can subscribe subscribe to I'm gonna create a - we can do a one-to-many and we can you know publish the message to multiple subscriptions if you if you want to okay and just like that we have the pops up configured and if I want to use pops up here I can just go ahead and use a starter of course I'm gonna add the pops up starter this actually integrates with spring integration spring cloud string and spring cloud bus okay so despite ending this starter if you have any of those things you can use spring integration and or spring cloud spring with pops up very cool however if you don't want to use spring spring integration or any of those things if you just wanna do this very quickly with a template we have that too so just by adding this starter then we can get access to now puppet self template and the we can get access to the pups top publisher template I think that's the name yep release some NOK just code is the publisher template not so a little bit too long often eaten with us a publisher complete there's the pops up publisher template okay and hopefully this will allow me to import this yeah and then what I can do is to just go ahead and use the pop stop publish rip template I can publish my message like that I'm gonna publish it into the people topic and we're gonna publish them and that I just VC okay and that's C I'm gonna go ahead and restart this application right now and they're stuck and wrong in the meantime what I'm going to do is to just go ahead and create a new project now I'm going to do is now in IntelliJ because IntelliJ we also have a way to create a new service using the spring initializer and you can create a new subscriber for example and call subscriber and it's using the initializer so you can pick and choose again you can use reactive for example and here you can use GCP messaging and just add that and this will generate a project for you to save some time I have the project generated here well again we have the pom VAX ml and in this case we have pops-up added to my dependencies automatically in this application of what I can do is you just use the application runner to create a communal application that would you start and we have two different options here we can actually use the pub sub template which is the subscriber template to receive this message or if you like the reactive stuff we can also use pops-up reactive Factory this is new and we are integrating pretty well in the reactive world with the reactive data store integrations and also our two DBC and four pops up we have sprinkle stream but also this reactive Factory and what this allows you to do is to say reactive Factory nopal the people substitute subscription and very maybe a hundred million sentence and then I can go ahead and subscribe and this will give me the message okay and once I receive the message of course I can do everything that's intermediate as well like I can do a filter if I want to and anything else that's in the Fox this actually creates a fox okay and I'm going to go ahead and acknowledge is the message so that I can acknowledge that I have processed it I'm going to go ahead and print this out so I'm gonna say print mine and SH get pop some message data to string okay and that is pretty much it that's all it takes to write a little subscriber okay so I'm gonna go ahead and start both of these application so just make sure everything work by the way this one I'm gonna run this on random port and that this will start and they should be listening for messages now again the authentications don't automatically behind the scenes using the G cloud credentials and here we go so let's see if this works I'm gonna go ahead and run this here I'm gonna open up the HTTP I see who else is here I think Tommy's here and Tasha is here too right Tasha is here sometimes say hello to Tasha and Holmes run this and I'm going to save the message into spanner but also I'm going to publish the message and hopefully wanna come back to this view oh I got a little arrow here but what they're like see that yeah so there was some connection issue here with my internet but that's okay but this is definitely trying to pour this message right now and if yeah maybe I'll try this out later but this should be continuing to pool if the connection here recovers that should be okay as well okay now if you're writing a micro service usually you will have a synchronous processing that you can use with pops up but more likely you also have these synchronous calls so for example you may have one Co one server is calling another via a rest interface and when you have microservices what you also want is the opposite the ability so you want to be able to see who's making a call so you need something like this should be traced and in spring of course there's spring cloud smooth and it can automatically instrument and trace the application for you and what we have done is to just hook into that and all you need to do to do a trace and then propagating this trace to our services in spite running us by adding the traced honor what this will do is to pour in spring cloud sleuth but then we'll also automatically configure the sender so that all the trace information can be sent to start driver trace or cloud trace now okay so that also means is that you can use the same facility that you are accustomed to but then you don't have to run and host your own trace server yourself and that we have a hosted managed service for you to do just that so you can see all the traces in our console - now what you have also notice is here is that I have a login right so actually see the logs here and the logs I also want to store them somewhere right so if you're running in Google Cloud criminales engine that we will automatically ingest these logs for you as soon as you're putting into xdv out but since i'm doing this demo on my own machine imagine if you are on premise then what you need to do is to add our logging starter instead and then you can configure log back to send the log messages to to us as well so I'm going to create a lot back configuration here and it's gonna be API compound not that one let me see here log API and console okay so who we give you is some pre-configured appendage so you can add and you can then configure your log back to use these offenders so for example for this thing I'm going to use the console appender and I'm also going to send a to start driver as well okay so I'm gonna go ahead and restart this app again oh and before I do that let me also simulate the micro surface code a little bit so what I'm going to do is to base oh let me see here at the time yeah ten minutes good so what I'm going to do is to basically make use of rest and plate and make another endpoint that will use the rest template to call my own application a couple of times okay so let me just do that right now so here we have the demo application I'm going to go ahead and create the rest template beam and that means you scold anything portbou selfies okay and then I'm going to automatically inject the rest template here private Val rest template okay and then what I'm going to do is to make a little Oh endpoint so slash oh this is going to either rate across a few names here and myself Mandy who I work with I first joined Google Cloud and the G shop will also work on this project in the past they're both really really awesome so I'm gonna iterate through these names I'm going to make the call to myself with the name right so I'm gonna call myself a couple of times but in the meantime I'm also going to say a long time info and see here a lot longer da info for example before oh and then I'm gonna say after all okay just to see what this looks like and I'm going to copán and restart and hopefully all these things are still connected properly so that we can get to see the trace in the log all showing up in a single console I see here so we started the application everything started fine we still offended Katie we're still connecting and let me go ahead and go to the test hvp and rather than hitting the prisons in point I'm just gonna hit the O in point okay and Lombard is gonna say hello a couple of times and it's done but if I come back here to the application I can see now we have the trace ID in my log message we have the spin ID and also luckily this request was actually assembled so that is what this last field is now the sampling is not guaranteed because currently by default is simply rate is about 10% so if you want to up this to 100% you can to and can just configure a spring cloud sleuth probability and we will honor all of these because behind the scenes is really just Auto configuring the sender okay so now what does this mean hopefully what this means is that all the traces are propagated to our system so in Google Cloud console we have the trace view and here we should be able to go to the trace list now I'm really nervous because I haven't test this earlier and here we have here we have two endpoints and we can see clearly we have slash all very good and then we can see these calls so we can see the call from all - ready - Mandy and to G show now you can also see that we have these async calls behind the scenes - that's because spring Klaus rule is automatically instrument Li the stuff that's happening in the executor service as well you can of course turn on/off if you want to but here's the magical point here's the magic because we're also propagating the log to our centralized longer and we're putting the trace ID and the span ID in the right place so what we can also do is to just click on Sherlock and what this will do is to within the context of the trace we can see these log messages or arrows as they occur within the context of the trace right so we can see all the log messages aligned in the right places it's super super awesome and then we can also open the lock Masek if you were to see a particular log message in detail and if you actually happens to have some exceptions that you have never seen before we will automatically detect these exceptions and we will tell you what these arrows are we will give you an histogram of how often these exceptions are happening and you can click into this and can do for their analysis just by having your error logs directly stored in our centralized logger this is super useful because who wakes up morning and ask hmm I wonder what new exceptions I have well you can check this council or you can even email you and and now you can discover new issues before your users or customers experience them at mass ok so let me go back to the side a little bit there's a lot of things that we want to and for a spanner to remember we also have hibernate adapters that can work with springdale GPA but we also have our two PBC adapter as well so if you ever wanna try cause spanner with your reactive application you can use the our 2d BCT Ivor one thing I'd be lucky to show just because of the time is the screen cloud config with secret manager ok so actually you know what we do have about five minutes left I believe so I'm gonna just go ahead and show what this looks like so let me go ahead and go to secret this is something securely secretly and this is brand-new by the way secret manager just came out gh is very very recently and can go up and and keyless secret and I do have a variable that I'm using my app called greeting some conscious goal and they use that and I'm gonna use some I'm gonna change the tweaking to holla instead of hello go to create this secret okay now if I go back to my app you get the drill all we have to do is to add this configuration secret manager for the starter and then because this is actually pulling in spring cloud config behind the scenes so what we do need to add is that bootstrap top properties we're gonna add bootstrap properties and then we need to turn secret manager on because it is not owned by P folks I'm gonna turn it on and this is actually on there bootstrap that enabled is equal to true and just like that that's all it takes for your application to be able to get that property in and we're referencing it here using the SPL for greeting and as soon as I you start my app we should be connected to secret manager putting down that piece of information and I wanna say hello again hopefully I will see Cola instead of hello so not keep out we do try actually really just leave it to be honest but I have to go for it yeah I have to I have to show it I have to prove that it works and luckily it does right here so you can see how easy it was to integrate this entire system with the our services and now you can also store your credentials in secret manager okay remember for pops up we have spring integration support and you can create something that takes inbound messages and pushing it into our data warehouse and for long-term storage very very easily we got spring cloud stream and screen Club us and we have to support for pops up forsooth we have scroll trays and you get the centralized logging and one thing that's really cool is that for micrometer micrometer also has sty driver support as well so that you can actually push your metrics your application matrix directly into our monitoring system and using micrometer pretty easily as well and I think Tommy is also online and he's been helping me out quite a bit there and this is the whole view of everything that we actually have now within the last three minutes what I'm going to do is to quickly just quickly deploy this assuming you have time I want to make sure unmindful of the time yeah I think so I got about just about three minutes life okay so how am I gonna do is to create the container from here now I know in spring boat 2.3 you can create a container directly using the spring boot plugin however I'm using 2.2 so to create this container I'm gonna use Jib so this is just a plugin that's created by Google and we can create the container very easily even without docker from me on your machine you do not need to write the docker file and with you what I can do is I can go ahead and do a compile I'm going to do a chip build and what this will do is to analyze your boot file will automatically create the best image with the best practices for this particular application we will layer this in the proper way and we'll push this directly to the remote registry without you to even have Tucker running locally okay and that this is pushing out the my app via my very slow home network and once this is done what I can do is to deploy into our surveillance environment we have something called App Engine with platforms and service which we can just do cheek I'll add deploy the target and the jaw that's one way to deploy this into App Engine but if you want to use containers we have another thing called cloud run so I can say G cloud run decoy spring live and mah name is the one I just created and I can say the CPU count is two and memory that I want is to gigabyte to GI right hopefully oh sorry I'll recognize arguments so maybe two and two so let's see if this works I can say publisher two o'clock fully managed and I want to deploy this into US central wine region I want to be able to about everyone here to be able to access it and what this will do is to speed up your container you know completely service environment and then we'll set up the load balancing for you the HTTPS certificates as well for this shared environment and very quickly our containers will be spun up directly on the Google infrastructure with the right sandboxing around your app and you know we should be able to know I need to listen on the port but we should be able to you all to see your app up and running fairly easily so unfortunately this did not go but my time is up that's why I keep this to the very last minute and I believe we are going to have maybe some question time for questions so thank you so much for your time if you want to check this out you can try all the collapse and everything I shall show in our collapse URL Josh also had happened to write written eight part series on how to use all of these things and we also have many recorded videos in content around this as well so thank you much for your time and thanks for having me here
Info
Channel: SpringDeveloper
Views: 4,599
Rating: 5 out of 5
Keywords: Web Development (Interest), spring, pivotal, Web Application (Industry) Web Application Framework (Software Genre), Java (Programming Language), Spring Framework, Software Developer (Project Role), Java (Software), Weblogic, IBM WebSphere Application Server (Software), IBM WebSphere (Software), WildFly (Software), JBoss (Venture Funded Company), cloud foundry, spring boot, spring cloud, vmware, vmware tanzu
Id: JqxMTQ2-VIE
Channel Id: undefined
Length: 37min 50sec (2270 seconds)
Published: Mon Apr 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.