Go Reactive with RxJava and Vert.x (Burr Sutter)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the about ready to get started I did bring a bunch of stickers with me for the project so I'll talk about there I just put them on the edge of the stage there you grab those on the way out that's assuming you like what I say maybe you won't but could sew and grab the door for us go and close up that'll tell everyone else they should be in here alright let's get started I'm going to actually start with a demonstration alright to kind of give you guys a perspective on what I'm going to talk about for the rest of the session because the key thing to take away from the session is that to get into the reactive programming model you have to rewire your wetware you have to rewire your brain because you can't think in terms of create read update delete there's still crud in this world and I appreciate we love our crud as developers write Java developers enterprise developers we love crud we've been doing create read update delete for years we call that crud and that's the way we live you know get put post delete write we love our get and post we do some put every now and then rarely and we may do some delete every now and then but this is different ok you can still do those same things those old school 20 year old things or this is the new school and so to react a programming world there one thing you got to keep mine is you can no longer know and bind a thread to every single request there's no thread per request in this world there's a thread a single thread to handle everybody ok you're probably thinking how is that even possible well we're going to talk about that this particular presentation this demonstration is to make that point I have simply two sensors right now running you can see they just started running right before you know right before you guys got here already one has produced a thousand 37 messages another one has produced 998 messages they're producing a message about every half second or so they're producing messages with two sensors streaming it in from this little sensor over here on my right and this one here on the left and here I'll just show it to you real quick and actually let's see if we can have to be a little cautious of it because I took the casing off of it and you can see just by my touching it it already has changed the temperature reading of this one okay so this is the actual msys ation to the sensor here grabbing the sensor data it's streaming in through MQTT here into vertex the vertex project and it's been sending that out to a graph on the browser and now if i cover it up a little bit more see there goes the temperature spikes way up and if I let it go we spike it up okay so the nice thing about that is this just super-sensitive is easy to see this is a TI sensor tag it cost $29 that has 10 different sensors built into it so this is I'm using the IR temperature there's also ambient temperature barometer accelerometer gyroscope Lux ammeter light reading so it's just a real nice way to drive high-volume transactions into the into the system it's actually a Bluetooth based sensor and a little has little tiny watch battery on the back and then I'm using this guy alright this is the thing I'm sshd into right here this is an Intel Edison the Intel Edison is this green part and that so it's kind of hard to describe and you guys probably thinking can you see what I'm holding up so think postage stamp and you've got the right mindset okay the thing on the back the thing that makes it so thick is the battery this CPU the Wi-Fi radio the root and Bluetooth radio are really postage-stamp okay until Edison and so basically what I'm doing is I've ssh into that little linux machine this is a full linux server by the way all right I'm running Linux I'm running an OGS process that connects via bluetooth to my sensor and then I it's driving temperature you can see there it goes shooting up again and then it's pulling that into over my Wi-Fi router I bring my own Wi-Fi router to this laptop and then I graph it okay and so here's my other sensor the bottom sensor there when you spike it up there it goes alright so that's this one right here so I can make its temperature shoot way up maragon so just based on the heat of my hand alright so it's nice and sensitive but the whole point of this if you're thinking in a thread per request world if you're thinking in crud create you know create read update delete if you think and get put post elite you can't quite get there from here this is a message driven says system an event-driven system and I'm drive I've now over 2200 messages into the system in a few minutes we've been together so you can't keep up with the volume and one specific case I saw an organization had 100 sorry a million smart meters so a million of these things therefore you're getting over a million transactions per second into your system so you have to start thinking of that kind of scale so this is not an IOT session the point of that was just talk about reactive programming the code to this is super simple you can kind of see that basically it receives messages and then it turns around it publishes the message as a JSON object in this case you can see it's basically incrementing a counter the majority of the logic here is incrementing a counter the counter you see down here is 1,200 1,100 something and then it actually does I publish that publish is percy is on the browser side alright and we're going to talk more about this but basically the browser is a peer of the server-side architecture which is connected to this architecture via this router okay I know that's kind of hard to describe but there's not a lot of code here but it is a new way of thinking as this pairs is kind of helped set the context correctly okay I appreciate you might not be in sensors but this is how if you're doing industrial monitoring temperature and vibration of accelerometer the two key indicators to system failure right if you have a big industrial fan the size of the screen over here that keeps your plant from having poisonous gases inside it right if that fan goes down or better yet if it gets wobbly and it's about to go down and you don't maintain it properly you have to send everyone home for the day they can't work in a in a in a place where they might have poisonous gases as an example so it's important that you monitor your fan okay it's super critical actually so simple things like that now again to give you a little more context here before we really get to the presentation using the same bluetooths idea and in my case we use raspberry pies instead of this Intel Edison they all work the same way it's all Linux but basically I can actually triangulate the location of things too now in case of an industrial setting your fan doesn't move too often and a hospital setting the hospital equipment moves up and down the hospital floors beds roomed all over the place often you know the ultrasound just got lost it's somewhere in some patients room we can't remember where the emergency was so simple things like tool tracking is super critical also super critical use case same kind of architecture and so to prove that point a couple years ago we gave away 300 Bluetooth beacons we handed them to conference attendees just like yourselves and we said okay go just run around our conference do whatever you want to do and we want to see what they did so this is a single day activity you can see it starts about 8 o'clock in the morning with people showing up on this this little room here was actually on a different floor entirely and that's breakfast right so all coming to breakfast and they're hanging out with each other and networking and then at some point you seem all blast down here because that's our breakouts just like you guys just came in here right now from the keynote room right you're now in the breakout session and we watch you go through the breakout sessions back and forth throughout the day and by the way I sped this up but this is all done in real time you could actually watch yourself walking on the map okay and then later in the afternoon we basically have a keynote specifically and you'll see everyone kind of shooting over here about 1600 there they go all right and here's the part that kind of I'll just pause that for a second we then got a chance to tell everybody as they saw this thing up on the big screen we just walked you walked into this room every ball was uniquely identifiable you could click on it but I have the person's name and we could track all your whereabouts throughout the day with a handful of raspberry PI's and a Bluetooth sensor like this one the full kit cost us three thousand dollars because I had to buy a lot of it so seven million transactions into our system right and then of course we processed it through patchy spark to do the triangulation are you closer to here closer to there then we basically finished our keynote and then you'll notice as the day goes on you know we're down six o'clock seven o'clock people are leaving the building by 10 o'clock at night when I got back to my hotel room to take this video after this presentation you know you can see most people have left the building at that point okay so again different mindset you guys cool with that different way of thinking now you guys probably did this already like after I went to Sweden they're like we do all this already you know maybe I don't know if you guys do all the stuff here in Luxembourg anyone do this sort of roti kind of thing in Luxembourg no one brave enough to wear a Jersey and that's okay all right let's jump back in I'm going to switch now back to the main Wi-Fi and there is no password but there wasn't a moment ago oh wait I clicked on that I have to click on the free one sorry alright let's see if it'll connect now let's dive into this we don't we've already spent way too much time on that one topic the presentation for those you guys paying attention is that bitly reactive MSA so that's where all the slides are that you get access to the source code to the slides you then can run away with it and do with it as you will it's all a Google Docs just as you see here also there's a lot of links inside this document that you'll want to follow up on for all the different demos including that demo if that's the one you want alright so let's get into it there's a document that you can have to download to get your head wrapped around vertex super easily it's a developer's our ENCOM it's a free ebook we wrote with O'Reilly download it get started on a microservices architecture and a reactive microservices architecture which is kind of what we're focused on now I always like putting things in perspective from a developer perspective in the 70s if you're a programmer in the 70s you really didn't have to know a whole lot of technologies you had to know COBOL pretty much there are other tank technologies but COBOL is a traditional enterprise developer and either JCL or whistle so two of the three you had to know JCL if you're an IBM er right IBM mainframe ER or whistle if you were specifically a unisys Sperry person which I was more a wiffle person so and you probably thinking what the hell's a unisys or Sperry I appreciate that at least IBM still around now in the 80s it got really complicated we might have picked up C C++ we might have picked up all the different for GL technologies of the day we may have learned case computer-aided software engineering that's where we drew pictures to generate COBOL code anybody remember those errors that day no ok net where I was a network administrator and some of your thinking what tells a net where exactly you remember net where banyan vines I appreciate that you might not anymore but this was the error in which relational databases were born and they're still with us so sequel relational databases are still around unfortunately UNIX is kind of gone at this point - so what's funny is a lot of these things have either stayed are gone and the 90s it got a little more complicated we had to learn HTTP we had to learn HTML we had to learn CGI there was actually a great book by the way you could learn HTML in three days by Loren LeMay now it takes a lot longer than three days to learn that if you think about it you know there was no CSS spec then there was no JavaScript back then but we ever learned get in post we would react she had to talk to people out what a cookie was because at the time 1996 people were super afraid of cookies they actually thought they were going to steal your credit cards and so programmers would not use cookies in their applications because it would steal their credit cards it was kind of a strange moment in time okay but this also was when Java was born servlets were born Windows NT and I know I'm in the empty room so we're in the Windows NT room excellent but it was really this is probably more the error you guys were involved with right so in the O's we learned things like MVC and struts reload struts dependency injection spring RM with hibernate this is the error which JBoss really came into its full full form as an example we also picked up HTML and web services my point with this is the learning curve you have to go through just continues to grow okay reactive is just yet one more new thing I'm asking you to learn and I'm hoping you guys after the session go okay I'm willing to learn that I'm willing to invest my time and that's their category and if you do all these things off so you're the your unicorn like the github unicorn all right let's keep going so reactive react there's two types of reactive it's highly it's with as many types of reactive if you will there's it's an overloaded term a lot of people focus on just a reactive programming side so reactive programming using something like rx Java or using something like project reactor it's all about the programming model okay focus on the code there's also reactive systems reactive systems can be done with or without reactive programming that might blow your mind but reactive system has its own definition and we want to focus more on reactive systems and reactive infrastructure because that is where you actually get the more bang for the buck if you will from an enterprise standpoint from a mission critical system standpoint so you can use vertex which is the Eclipse vertex project in each of these cases this is the reactive manifesto there's the URL at the bottom you can go look at it yourself but the whole it has some basic core tenets it has to be message driven a reactive system should be message driven not request response driven not get put post driven write not crud if you will but message driven which is why I showed you that first presentation of streaming sensor data okay that also it has to be responsive I'll show you a demonstration of responsive it has to be responsive what does the user do to your application when it's not responsive you know you most you guys probably build web application so how many people do web applications on some sort there's an HTML client ok only about half of you the other half do green screen right batch probably some batch folks here or 50 to 50 30 to 70 folks that's cool but in the case of web applications what happens if the user does not get a response what do you do as a user when you use the web and the response is too slow you hit refresh because that helps the programmer right it makes the program run faster refresh refresh refresh every refresh as a brand net new transaction with all the previous ones no longer having a person to respond to so five users all hit refresh five times you know you have 20 different requests that don't need responses okay so being responsive is super important if the user does not like waiting and you have to be responsive in the face of overwhelming load elasticity I need to be responsive in the face of overwhelming failure resiliency so responsiveness is the key and right and so how do you do that in a bread blocking world it's much harder in a thread blocking world and a non-blocking async world it's much easier the question has always been how hard is that code to write and it's been relatively difficult until we have something like you know akka or vertex as an example so let's actually show you that this is a demonstration again I mentioned I have links all throughout the presentation you see several people have joined me these are you guys probably here ok let's go look at this real quickly okay so there's my client what I'm going to do is I have a couple services that I'm going to run okay just simple localhost services and actually let me go shut this guy down over here because he's sitting on my port let me bring up spring boot so just this is Brit spring Bhutan tomcat traditional you know Enterprise Java style application with spring MVC controller and it basically has a nice little URL on it let's just go hit it there localhost 80 and there we go okay so there's my there's my hitting of the URL speak it a little bit smaller move it over here we got a lot of things to show you this is one problem with screen resizes not that one we don't care about that one any longer all right all right here there okay here's what's happening I've already lost my screen again come back and there we go okay so here we go I'm basically just I'm hitting refresh refresh refresh I'm getting a response pretty straightforward stuff it's just a get request give me that response okay tell it from spring boot now what happens is I'm going to jam in two hundred concurrent requests into the system you can see they're getting queued up there and now look what happens my responsiveness is died I'm now locked up entirely my user is stuck because if you have two hundred requests and only 100 threads somebody has to wait okay this is just a very nature of this architecture has always been this way and it continues to be this way if you have two hundred requests and at 100 threads a hundred people are going to wait and so this case the browser is waiting you see it does eventually respond based on a thread becoming available to service my requests pretty standard stuff and now that basically I've gone through all 200 requests I'm back to good again now you might be singing I'm picking on poor Tomcat right I'm not I must run this on JBoss okay the ball fly application server st. works the same way because this is the very nature of Java EE right with the thread per request so if I go in there and now run this guy let's see there we go now he's running and I throw 200 requests at him and we come in here and here we go there all right you can see it's stuck again I am no longer getting response because all hundred threads are now you know being hit the 200 requests this thing doesn't do anything more than actually calculate pi it just has a bit of business logic that does a lot of computation and it takes time okay to calculate pi and and there we go alright so now we're back to good again now the difference in this new this world the way I closed before all the connections were out all right let's difference in this world if I run vertex now vertex is a single threaded model okay so it's up it notice how fast it starts it's also way smaller than the rest it's a single thread and the cool thing about that is if you throw 200 requests at a single thread it's always responsive now you probably saying in hat what a single thread always responsive a 200 concurrent request yes because it's always done async okay so yes I have a single thread now running 200 concurrent requests and the user still sees a response completely different way of thinking about the problem okay and the programming model let me show you the programming model because this is what normally people worry about they're like well I can't write that code I appreciate that the code might look a little strange to you but let's look at it real quick alright let's go look at our list of error spring food application so right here it is just a request method get' right it's the server controller it says goodbye this is the one that actually has the computation so this is the business logic right here this is all like business logic and this and this is the URL maps to this is the get request so pretty standard for you're familiar with spring here's the Java EE version looks almost identical right but jax-rs has a different set of annotations that has a get in a path and produces and okay and there's the goodbye and there's the nap okay but identical business logic here's the vertex version of this here is the business logic looks identical pronounced the same is same business logic the difference is how you set up the routes to it and if you're familiar with nodejs at all I'll make a little bit bigger all right you can see you're basically binding a handler to a specific URL because that handler binding is do it a sync do it asynchronously do not block the user thread basically push it off to a background thread one you don't care about and then get the response back to that user asynchronously it so the point of this is you do set it up differently but the business logic is still the same at that cool okay so if you can get your head around the basic concepts I've shown you so far you kind of have the reactive principles starting to map into your brain a little bit and then we'll keep diving in here though we got a lot more cool things to show you and we only have 32 minutes left where is that window now well this window okay let's go back here don't leave that guy running let's go and turn him off all right not that one and here all right okay just jump back in here all right we're going to rock and roll to these slides because there's bunch of other cool demos I want to show you have a ton of code but that's just the one that kind of sets the point of a threaded model thread per request model versus thread per core model right async versus sync world now if you want to do micro services which everybody wants to do it seems like everybody's right we're all talking about we're doing it I'm doing it I'm doing it okay this is a part by Martin Fowler if you're going to do it for real you need to kind of be this tall you guys might not appreciate the expression but I'm not very big and when I was a little kid I was definitely not very big and I was the kid who could not get on the ride okay because you would go to the roller coaster ride and have a sign and says you must be this tall to get on the roller coaster and I was the kid wasn't that tall okay so I appreciate that you must be this tall the point is you've got to have certain capabilities certain abilities certain innate characteristics before you're ready for microservices you need to think about self service on demand elastic infrastructure in other words if it takes you three weeks to get a VM provisioned you have a problem okay keep that in mind and your prize taken three weeks and my bank it takes five weeks I've had a lot of customers or audience members are like tell me oh it's five weeks six weeks one I was actually in a federal government thing recently and when I said that to the audience they started laughing out loud it was a room the size what all these people they said it's six months in our organization so if it takes a programmer an expensive resource many you folks here are not free to your organization imagine you get good paychecks right as programmers we deserve good paychecks but if it takes three weeks to wait on an inexpensive really cheap virtual machine that actually sends a signal to the rest of us doesn't it you're going to make it's like waiting for a pencil so I can write okay same kind of concept so self-service and on demand is critical if you can't get a new virtual machine provision for your needs exactly as you need it within two to five minutes your organization has a problem at this point because this is very doable in this day and age from a technical standpoint it's an organizational problem it's not a technical problem now you also have to think in terms of Devon ops all right it's no longer developers versus operators it's no longer throw it over the wall to the operators to heck figure it out where the developer checks it in at 4:45 p.m. on Friday they go to the bar drink in and the operations team figures out how to make your crappy code run all weekend by themselves no the developer stays all weekend if two codes that crappy and the developers on the pager that's the new attitude if the software goes down or acts up anyway you basically are now on the pager is my point if you can do that you're kind of getting in the right mindset when it comes to micro services if you have no automation for instance your operations team your developers whoever might be sets up a server by plugging it into the rack right one you recommended server power ping network cable at pixie boots loads the operating system and then someone SSH is in and updates the system D settings or in it D whatever you guys use for setting that server up tweak some stuff start some processes and then make sure they background those guys because they step away from the terminal and they think they set up the server properly you have a major problem that's called a snowflake they made a one-off what you want is an automated baked script the basically produces that server in its pristine form every time all the time and that script is always checked into source control and it really ought at this point we should be puppet chef or ansible you know ansible playbook will bake out that server identically every time and actually it should be done with your software on board the custom software on board so we can keep going on and on here but these are the kind of things you should be thinking about long before you say oh I'm going to take my one little application and break it into 55 applications because I want to do micro services if you can't deploy one thing easily and well on one server how you gonna do 55 or 2,000 okay so just think about as you get ready from a micro services architecture I would recommend these books very highly if you've not read them we really should okay I know it says ops on there you think I'm a developer I don't like those Linux admins that's the wrong attitude you got to get kind of psyched up about your Linux admin and more importantly need to learn to love your DBA so go to your DBA give him or her a big hug and make sure you take them to lunch they deserve it because you're probably thinking well it's not just the system admins operators that bug me so stupid DBAs won't change the schema because your gherkin okay that's also what the problem is got to love them some more and they'll change the schema when you need it too just keep that in mind alright here's the old way of doing things with an operating system Java Virtual Machine you stuck your app server on there we put our ears we put our wars in our ears we stuck our roars in our ears in door jars etc we went nuts with it now here's the reason why this architecture is called monolithic this is reason why Enterprise Java is a monolithic architecture it is because everyone has to agree every person on the team has to agree to the right version of the operating system the right version of the java virtual machine the right patch level of each because there might be bugs that are fixed the right app server the right patch level of that to the right configuration of that app server and of course all our maven dependencies had to be the same now actually many projects that said oh I got three versions of spring not a good idea I got three versions of hibernate really bad idea okay you don't do that sort of thing if you really want to have some control and quality about the product that you're producing but this is why monolithic architecture is considered bad because everyone has to agree and I don't know if you guys have ever tried to organize like a camping trip for little kids like you know you got ten little kids and you got like all the parents and you're going to organize something right at your local church or you know synagogue or community event trying to get everyone to agree is insanely hard and so if you have a team that looks like this there's forty something people here that make up that application then how do you get them to agree it's tough so this is where micro services comes in it's about breaking up the teams so they can focus on the product their produce at what the right quality and right skill set that they need okay they do what they have to do but this does mean if they build it they own it they are dev and ops right and also they have to produce it at a great deal of automation but we don't want to spend too much time on this because we got to keep going now these are the key market services principles if you want to do micro services do think in these terms you know deployment independence is number one I should better deploy my component at any time I wanted to play it without disruption to any other component system if I want to play my component five times a day all its consumer clients have no problem with that and you better think it how is that even possible it's actually very possible in this new architecture but you have to think in those kinds of terms what if I want to play every day it's in fact this decentralized data management bugs you everybody gets their own database DBA won't allow for that again you got to take them to lunch think about that for a second because there is a book that we have that helps you address septic Reploids nee-naw go who's here today we'll be talking about this later I believe on the schedule and he also has a book we published let's kind of move along all right from Microsoft's patent standpoint you can start with the browser the browser invoking the different servers on the server side this is actually very common and retailed that's why I use this retail analogy here each of these components on your mobile page makes a different back-end service call in many cases and so the good news is you don't have to wait you don't block for all of the response you asynchronously get the pieces that you need and you get data as the data becomes available and it's actually okay if one of them fails is a good example here you can see in-store pickup says there's 15 available in my local store what if that fails in the case of the organization I talked to when I drew the screen with them they actually have that it could fail it's a mainframe call in that case the mainframe holds the actual inventory in the local store if it fails watch what happens right it just what it just simply shows that just simply shows your store so we don't know that 15 are available but we do know where you're at based on your GPS location the whole point of this you should have fall backs in your architecture you have default business logic that executes in the event the network invocation fails and you're very responsive to that you also have the concept of the server-side gateway you can see here we aggregate the content on the business logic on the server side and we publish it to the client-side again if something fails you catch it at the right point you also have the ability to change all these events together so this is just kind of a quick introduction of microservices architecture but again think in terms of failure because it will happen if you have a distributed system and any form of network in between those components something will fail something will be too slow and this is where you put in like a circuit breaker or something like hystrix so you can avoid a cascading failure so that's where the circuit breaker comes in again we have a lot of time to spend on it here today now I have a lot of demos around that specific set of topics blue/green deployment circuit breakers canary deployment see ICD all that there's a bunch of things you can go look at there I don't wanna spend a lot of time on it because we got more interesting things to look at now I know I'm moving fast I appreciate that but I really want to get to this area right which is the area about vertex the stuff you saw earlier with the streaming data from sensors or the stuff you saw earlier with the you know running all those 200 requests on a single thread this is where vertex comes in it is a tool kit it is a jar file you add it to your pom.xml and you now have this new magical superpower okay it doesn't have to take over your whole environment but it good you can run it as a full application stack just like you would have run a traditional Tomcat or jetty or Nettie or JBoss or WebSphere WebLogic this could replace that whole stack but doesn't have to okay just keep that in mind it is a fairly uh opinionated toolkit you do with it as you will think of it it's like the Swiss Army knife of Awesomeness that you can do whatever you like with you can build a house you can you know build a furniture out of it if you want to do now at the very base level we have this concept of the vertex cord it speaks HTTP 8 1 & 2 by default and actually that what you saw earlier with the router that's just HTTP right it's didn't get put post too late standard stuff it also speaks UDP it speaks TCP that means you can map anything you want to over it including sensor data anything you can that can speak to a network can talk to this thing and you are responsible in some cases for the protocol there's lots of protocols out the box AMQP HTTP UDP right HTTP right there's just love them just keep that in mind that you can do what you will with it people use all this in very creative ways because it's just a network listener an async Network listener there's two key components to the cord the eventbus we're going to spend a lot of time on today or a little bit time when we get into it and share data the eventbus is simply nothing more than all JVMs can see each other in a peer-to-peer network each JVM on the cluster will basically see each other from a TCP standpoint people was asked well how does it how does it talk a to be TCP you know that whole networking thing we've been doing for so long you know transport control protocol the invented when we invented the internet that stuff it works really well okay you guys have been using the internet a while you probably comfortable with it so we use TCP for in a in between JVM connectivity and then we can also do shared data mapped to something like a hazel caste or in a span of something like that you can do web-based templating so if you want any kind of traditional web app you've got templating mechanisms here you can also do o auth and things of that nature there's the router you saw earlier you can have any form of cluster management maybe you want zookeeper or hazel caste we also have infinite span you can integrate with things like stomp nqp you know RabbitMQ you can also do use multiple programming languages groovy JavaScript Java groovy all right now Ruby go crazy there there's a synchronous database driver micro services architecture and form of service discovery and circuit breakers and bridges will show you the bridge because that's super awesome and of course metric capture so it is it does give you everything you need to build full apps right like you would have done with web logic or WebSphere the difference is it does everything a sink and a reactive way so let's keep marching along here okay this is the vertical this is the program right you write a program we call it a vertical you can think of as your class your class file write your dot Java file or dot to refile your dot J's file is just a program and then you would basically run that inside a java virtual machine and you can have many programs running in a single JVM and all of them speak the eventbus to each other okay so keep mine is a single threaded architecture it is based on the concept of the event loop the event loop basically says as a request comes in I will find an appropriate handler to pass it off to and I'll go to handle the next request and the next request and next request so that's it's never blocked okay if you do block it if you do do something that causes a block and you'll get stack traces showing up on our console we'll say sorry you're blocking the event loop stop because it is easy to block the event loop by accident you're like oh I'll just connect to the database and run a big query that takes two minutes to respond about one second into that it'll start storing exceptions back to you you're blocking you're blocking stop if you must do a two minute query against the database there's actually a super easy way to handle that okay just if you want to know you can pass it off to a worker pool but we don't worry about that right now so it's super easy to background anything you need to that just takes too long okay now we do set up an event loop per core so in this case it's you know if you have four cores visible to the JVM but does set up for event loop so you might have four threads and technically there is one background thread to so is eight but just think in terms of a single thread that's you're never going to block you're always going to dispatch events to some farms handler okay like here's a simple super simple example of that right here's hello world I'm going to create an HTP server I'm going to have a request handler that request is a lambda right it's going to bend map here and I'm going to say request give me your response and then I'm going to end the response you can also chunk which is create you go crazy with stream based chunking end it with hello vertex and then the last thing I do is listen on 8080 so this is the kind of expressive API you'll start to deal with and this is a super simple no URL distinction any traffic coming over 8080 goes to this one endpoint and actually responds okay now if you need to get started you can use you know there's the getting started technique here there's even a maven plug-in to actually produce a template project for you and then you can do maven compile vertex run this would allow you to actually do interactive development I'll show you a quick example of that okay and then of course you can set up your routes you can see the router here root on get router get this is the method we'll call with a method reference here also if I have parameters it works this way you can see here's our two methods our method with the parameter okay Web Apps handled accordingly if you want to do Web Apps but it's all done async no blocking and we've seen an example of that here's a more complicated example you can see I have get put our get post and delete input so you full crud operations traditional rest programming model but you know it's just set up differently and then the event bus does goes from JVM JBM let's kind of show you this now and you guys brought your phones right smart phones we're going to need those please get those ready alright so let me jump in here and I'll show you something you can actually go to web dot berta read right now I'm messaging into an image and if our network holds up all right we should be good if you go to right here let's just run this real quick sudo Java no no no vertex type birth this is where I have not had enough sleep all right I'm gonna bring out I'm bringing up the web server now there we go the web servers up ok let's go to our browser and we're gonna go to web burnout red and there's this response it's a simple little pizza just a chunk of text okay so webbed up bird our bread is the URL I promise you this is going to get more interesting you're going to want to get out your phone so just keep that in mind alright so I can go to the end point it says hello to okay so that's my application it's really simple hello and your name you can see hello and your name right there alright webbed up Burnet red let's go change our code VI man here and we'll go to it says hello to right let's find that there it is let's actually make this Bonjour how about that alright let's run it again you notice I didn't compile anything I just reran it and actually it'll dynamically pick that up I chose to and there we go so I just in production edited the code and redeployed it for you guys on your phone right now now this is the kind of mental model you should be in the development cycle is super fast and some of you are writing in ways second all those cool kids at the office who didn't know Jess this is how they work exactly okay that was the point of all this basically Tim Fox when he invented this technology he saw what was happening in the nodejs universe and the architecture and the style of development they were using which was edit refresh edit refresh edit refresh and he and and of course this Java people were like oh build in our clips or IDE and let's go get coffee it's building ok and you come back and like oh crap I didn't have the logic right fix the code build go eat another cup of coffee now this point you've had four cups of coffee in the same 5-minute window right so you're talking to your friends you know the build takes minutes if not weeks depending on where you come from so this is a different model and you can kind of see it works like the note G s universe does but again let's gets more interesting let's actually show you something more interesting here I'm going to go into this vertex event bus example so that was a simple web server let's show you a more advanced web server okay yeah all right I'm bringing up another web server right now let's go to back to web that burnt out red and there we go there it is this is what it does now so in this case I'm pushing messages to you from the server all right so if you guys get connected there you'll get server messages also and I'm going to bring up another window now because so go to web that burger at red and I'm going to basically add in let's add in Java messages to that mix so you're going to see server messages and Java messages and let's add end-to-end attendant down let's go let's add Ruby messages that mix okay I can even go back to the server oh oh this is a different server which should close this one Sh web burn our Red Tent down okay you guys should get Ruby Java message is now streaming into your phone effective way right now and so I can actually add another consumer on a server side so let's actually add a JavaScript consumer just I'm picking random ones here so basically I have three producers on the server side one consumer on the server side and then of course everyone here in the room who's using their phone right now is also consuming on the client side now you're probably I could do this with Java EE yes you can all right but just kind of show you what the code looks like all right so that's cruising away there the let's look at could real quick word I'd leave it I have tons of examples we could spend a lot of time on what arcs job and things like that but okay here we go here's the web server it's like the web server you saw earlier right create HTTP server the difference is we have this thing called the bridge options and we have an outbound permitted channel we call my feed that basically means outbound kind like a firewall this particular set of network messages are allowed out the firewall to whomever is on that bridge bridge can go directly to the browser as it does in this case or maybe a node.js application or some other system and it's just a direct in memory feed there's no guaranteed delivery meaning guarantee delivery by the way if someone always ask that means you write it to disk that's how you guarantee that someone will actually see that message right you write as it is going to ventually take it off the disk kind of thing in this case is purely in memory we're streaming the data out and you can see it's all that amount of code that's it you can see right here we have the set periodic so this is a server message event bus stop publish right there that's what's going on if I come over here and look at my Java publisher event bus stop publish right there if I look at my consumer it's a handler against that same feed my feed right there if I look at the groovy version the groovy version again consumer event bus consumer if I look at the Ruby publisher over here here's what the Ruby one looks like okay you can see event bus published so it's published handler published hammered that's all it is right that's how you set it up so that right there means you guys are getting message for me okay but let's go ahead and kill that we got even more interesting things to show you is that interesting at all yet okay you can say nah that's boring fine we're going to take it up a notch alright I got to shut these server services down real quick and as I drop them you're going to see your messages are changing too okay server server server I just killed those processes and actually is going to take the server down so I am you can see also the socket connect those are all the people who connected for me so what 20 of you guys connected let's even get all you guys to connect on your phone all right so PS - here let's see what I have running here I won't see if I have these other Java processors are running and see then Zen down that's such a slow server so at this point now that the service provider opted just that did beers right this is actually live ok good Robecca good again ok let's go here let's show you this example so I showed you how to just run things just at source and we done end couldn't pilot and run it just like you would if you're a ruby person groovy person or java person the net treated like a dynamic language however you can build a fat jar you can do it the traditional maven way if you want and that's what I did with this sticker jar file right here you can see this jar file this is a fat jar there's the size of it right there and that includes everything I need in a self-contained jar and I can say sudo sudo Java dash jar and then let's name it the jar file now this one is a slightly more interesting one you guys can connect to web that Burnet red now okay already someone connected alright now your bar thing and what is that just do some little finger painting for me okay it's a finger painting game let me bring up the dashboard alright try not try to keep clean now there we go alright let's see I can draw Big B there and each stroke that you lay down okay shows up in our dashboard here so if I add some colors and I can make it black you know whatever you want to draw each stroke that you identify right each stroke you put in actually shows up here in real time so that it's a super simple little application I'll here I'll show you the code with it I like the face but if I send a good job there or they just erased it so if you clear right your your thing goes away now so let's go look at this code real quickly because I think this is a super important concept here and that is let's look at the server side so the server side is just slightly more complicating what you saw earlier I do inbound and outbound I come in from you and out to my dashboard I'm literally taking the serialized canvas object that you're producing and pushing it out to the dashboard I'll just write to the event bus from your phone or your 3G connection or 4G connection out to my ec2 server which is actually running a Virginia in this case is a Virginia base server you know to the over this conference Wi-Fi to this laptop right now and so just think about what that what you have to do to make stuff like that work in a traditional get put post crud world you're probably thinking I can't even do that that's kind of point and it takes almost no code okay the real code here it's in the area the client if I look at my ugly HTML Javascript I specifically have something called the end stroke so when you pick your finger up that's the in stroke event it says send the canvas this canvas does nothing more than serialize write to data right there it C realizes that canvas and publishes it so the client browser side of this does consumer and publisher on the event bus just like all the server-side stuff does - it's that hard so this is actually where all the logic is is actually in this client you can see it's just really ugly here because I'm not a particular JavaScript programmer but the result of something of this nature okay so keep that in mind all right well you guys can feel free to keep painting we'll leave that alone for a moment but let's jump back in to slide where mode for just a second and I have a couple more things to show you we mentioned rx Java look there it here I want to I mentioned our extravagance arcs Java is one of the server-side programming models you can take advantage of let me see if I can show you that well let's show you a base level rx Java example just kind of get a feel for it here's a good example okay so rx Java is the concept of data is always streaming that's why I showed you the sensor demo earlier the data is always streaming it's not a simple standalone event nor is it thread based right it's there's data coming in all the time and I'm going to receive data on stream 1 stream 2 stream 3 and in this case we're going to aggregate the data we're basically going to see that 10 plus 100 plus 20 is 130 and we're going to return that as an aggregate response now this is an rx Java programming model based on the observable it takes a while to get your head around it but it's incredibly powerful because you don't have to block now all this is lazy evaluation until you hit the subscribe method the SUBSCRIBE method has three main methods that are callbacks one is did data here's the data here's the data here's the data the other is oh there was an error there's a throwable and the other is we're done we're completed you get three main messages coming back to the API as I come over here and to do let's actually do this this is to go and run it okay you can see right there it comes back with 130 150 170 and completed it just rips through the stream now to make this point a little bit more interesting let's show you one that's actually does something that you might have to do in an enterprise setting and again all these are available to you online we showed you to paint one example let's show you this one right this is where it gets interesting because this is a common enterprise kind of problem I have an API that I'm providing to my mobile client my business a business partner my whatever is some API I have to produce and I need to produce that API but I have to consume three four or five other api's and this is where this technology came from this rx job was built by the folks at Netflix because they have front-end edge services where your device connects to and they have didn't call five ten twenty other services to fulfill the request and so you want to do all that async non-blocking and you also want to do it in a nice programming model in this case rx Java programming model so here's the enriched this is my original client-side request so that there's a there's a server request or a browser request comes in to the server it didn't goes to github and says get up give me all your users then based on each user get the users details and also get all the users followers so based on stream one grab the data as an event go get more data right based on string to get the data as an event go get more data all this is done asynchronously non-blocking way so this means I can now have the composite zipped up answer for my user and a nice clean set of JSON based on what I want to program so this is a very common use case if you produce services at the edge and actually let's go let's go here to the tendon I lost this terminal window okay and this is the composite one this if I make it run real fast to produce a fat jar I did okay Denton gent that tend to target and Oh 8 okay well it bring it up all right there it is it's up and then let me go to my browser okay I just go to localhost 8080 and if the network is fast enough for me there it goes it's tryin there it went out and grabbed all that data and aggregated into one single response for me again it doesn't take a lot of code to do something pretty interesting and all of this is async I'm blocking because if you're doing an edge service which has a million mobile devices hitting it we don't want to be a synchronous blocking right you want to be async non-blocking so that's a really good use case and we're rx Java really really shines so at this kind of programming model you can see it's fairly readable do this do this do this and it all handles that accordingly okay I say that and make that point because if you typically do a sink reactor programming it doesn't look like this okay it actually winds itself way down a crazy list of callback right callbacks which means callback hell is what you get yourself into in this case it nicely stacks up example what while we're here let's make sure recovered the key things in the slides you guys are doing a good job with this okay good stuff there let's go back here nope different thing here we're running out of time well okay let's just show you this then all right go to a different URL for me go to game deber dot read game dot byrd out read okay hopefully you all have your phone up because it's gonna be interesting Darin contingent uh ganged up Berta read is to get connected might you might have to refresh because binding on the network performance sometimes you have to refresh okay go oh this thing is running slow right here let me refresh here I go there we go okay so that one had timed out on me this is what you're going to get on your phone the balloons okay the reason this is important is everything that you're doing is a transaction through my back in architecture so from your phone 60 frames per second we're animating these little balloons you pop a balloon it goes back in through a transaction in this case to a Frankfurt server running in Germany and then through a series of steps and then it comes out on my dashboard so your partner if you're popping balloons let's see what you guys are doing there so gamed up further read here's my leaderboard alright look wow you guys are already jamming in someone's already got 60 points okay now let's go here let's bring this other one up so it's literally going to from your phone to a Frankfurt server on ec2 and then it's driving my dashboards now wow you what you already have 1600 transactions in the system seven 1700 transactions in system every pop is a transaction there are 51 people playing right now on their phones so this is actually is a real time someone just get disconnected so some you know depending on your 3G connection right you might get connected disconnected see that kind of thing now we need to explain this architectural space oh hold on a second okay I paused you alright it's important we talk about this for a second because I don't want you guys thinking oh that's awesome but you got to understand all right let's go back over here is this the web page no I got AB let me find the right page scoreboard will go steady all right so I can't even find my slides but I have the URL okay well is it going to load I'm going to just show you one thing real quick how let's play some more what hold on right here this is what that why this is important every pop you make okay it's going through a single JVM single threaded JVM on the server side every pop you make all those transactions are flying in it then in turn calls yet another micro service to basically do a calculation of what what are the achievement levels again then it calls your traditional Java EE application this is running on traditional JBoss in this case traditional java application asynchronously implicated to run a spreadsheet called rules has a concept of the decision table so where the business analyst can lay out a spreadsheet for business rules it's running the spreadsheet on a traditional java application this is fully synchronous in the traditional Java way but it doesn't matter right it's all done asynchronously at this level this is the front end edie service that's actually hitting all those guys when he gets the data back asynchronously he updates his scoreboards so all the traffic is going through a single JB I'm running a framework right now okay but it gets more interesting alright we're not done yet let's go back into it you guys are playing again okay there we go let's bring up our leaderboard one more time scoreboard all right there 50 of you can get connected right now three thousand three thousand pops all right but let's make this game a little bit harder all right all right let's make a little bit harder make the balloons new invisible and make them a little faster is that cool we got a little faster makes it harder all right I'll make it easier on you let's make them a little fatter and slower more visible make a nice and bright and actually we'll make the red balloons ten points and I'll change the background color to green and make it a little bit more interesting for you okay so keep in mind I am literally making pushes to your phone by changing everything is interacting with that single instance on my Frankfurt server right now and you guys are all Pam bring the heck out of it okay already we're at 8,000 9,000 transactions into the system just a few minutes we've playing together but it gets a little more interesting the team actually went to help me build this they're like okay let's add some more sizzle to this all right right there okay and then actually I can change the point totals to to really make it interesting let's make extra red balloons 100 points okay and update there we go all right and I if I want to I can pause you again okay so I know we got to wrap it up one more second and then you're ready three two one game over all right but we got we got 55 people of the high end we got ones out one thousand sixteen thousand transactions to the system and again you can see who here ended up on the top tier right we generate your name sign it dynamically because we learned that people put in the real name there's a lot of people with some really bad names I can't believe their parents named them that if you don't I mean alright so we generate the names but so you can see all these updates in real time now hopefully this helps you understand that you can do a lot with a single JVM on a single thread okay kids if it's all done asynchronously and the programming model makes sense you can kind of fundamentally change the way you build applications going forward now I'm not saying the average business application needs this kind of interactivity but what if you did have this for your users for whatever application you were creating this kind of designed this kind of aesthetic this kind of responsiveness I think it changes the game for everybody all right let's talk back here because we're at a time during but just in mind the balloon someone always asked can I get all the balloon game absolutely it's all open source there's the repos if you want it and keep in mind this whole slide deck is available to you at bitly reactive MSA do we have any time for questions or Rio we have about five minutes for any questions at all any thoughts random was this cool okay any question your guys think I don't know I want to pop balloons I know yeah any random thought about this so yes sir yet you could use UDP also TCP is a little easier to deal with especially in a cloud-based architecture where UDP is blocked all right so UDP by default is blocked on off most infrastructure service clouds so TCP is often a better choice that's all and with TCP by the way you can also introduce back pressure we just and we didn't talk about back pressure but you often think about that in reactive system that's the ability for the producer to get a signal from the subscriber to say hey could you slow up a little bit you're jamming too many messages my way that's a more advanced topic but it is something very very doable in a TCP world ok any other questions all right yes sir yes yeah the game doesn't really have much but it's all exposed through via JMX and if we look back over here you have you have JMX available to you and then you can use drop wizard and popular to also do like bit on higher level metric capture and program you know look at that so yes just like any standard enterprise Java thing it has to have some form of metric capture logging all those traditional things so people are running this in production already for all sorts of interesting use cases again you get to think in terms of edge services right services closer to that million mobile phone user or business a business API or something like that and I need to have a sync aggregation of the other server side API s and you want to run at high volume ok there's people who really run millions of transactions to this thing all right well I think we're out of time but if you have questions for me I'm available for the remaining you know several hours here today please do come up and talk to me I did bring stickers for vertex and fabricate I didn't show you too much fabricate stuff fabric they also gives you some nice GI CD capabilities and a nice maven plugin to help you work it early on these kinds of projects but that hopefully gives you guys a little bit of a taste of what we're doing here with vertex and please go check it out and don't forget the free book on our website and don't forget the web you know again the slides all available to you here all right thank you very much [Applause]
Info
Channel: Voxxed Days Luxembourg
Views: 6,171
Rating: 4.8344827 out of 5
Keywords: VoxxedDays, Luxembourg
Id: IN9nXAQQwJM
Channel Id: undefined
Length: 55min 16sec (3316 seconds)
Published: Mon Jun 26 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.