Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 first (M.Atamel, R.Tsang)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
yes sorry yes let's do it let's do it all right I thank you all for being here and let's talk about gr PC so my name is Rey I'm a developer advocate for the Google cloud platform I'm facing New York and I'm Metta tamela I'm also a developer advocate same team as Ray but I'm based in London and we desire Twitter accounts so if you want to slice we'll post the slides after our talk so just follow us on Twitter and then we also have a talk feedback link so--but place flash my last name at Amell if you've finished the topic link we have some GFC t-shirts too so the first few people can get a t-shirt after the talk so if you fill it just come after our talk we also have some charity stickers that you can get after I'll talk as well okay awesome so we're going to talk a little bit about versus micro services because well how many people here are already implementing micro services in line yeah or looking into implementing some of those things yeah yeah so it seems to be a trend that film that's here to stick right it's it is a architecture that will be able to scale and many of us will probably have a monolith to start with already and what we're going to do is to be able to break it down right into individual services and now you have just more and more components you have to run and at the beginning what most people think about is well how do I manage so many services at the same time and for that we actually have really really good tools around continuous consumer relations and other platforms platforms and service that can help you manage these components in these applications however one of the biggest question though that we don't really think about is how do these services actually talk to each other how do they actually communicate with each other we use rest right right I mean we know HTTP we understand the gets and the puts and the posts and all that kind of stuff we understand the semantics so rest so that's what I use well what can we use rest for micro services yeah so I think that's probably the default choice today but there were default choices you know years ago for different technology that works really well for sometimes but but there are some issues potentially right well first of all if you're using rest right stocks with the rest semantics if you are like it's really hard line right right you're stuck with the HTTP verbs which are the guests that post you know to put then really map well to see are you the operations against a resource however as soon as you start to implement more complex this is logic or more complex operations then those verbs cannot break down to the imagine imagine if I want to get all the money from matrix account right from his bank account right what do I do with the rest of all let's do data around your icon I'm gonna say what do you get all his money from his account right do I do I do a restful service to do a patch first and then you know detox the money and then do another patch against my account right or do I simply have like the operation that says transfer and I just give it to account numbers right now that would probably be a lot easier so our PC in general or if you move away from rice if you move into our PC world right then you can implement some of these operations you can express them much much better and also that in rests sometimes you don't really get the schema like yes it's really good for a text-based protocol that you can just you know type whatever you want you can create this payload hopefully not with a mat right but in then you have to specify the attribute names over and over again or you have to write your own stuff and sometimes not exactly type say if you don't have those stuffs right so it actually some complexity also to consume these services and finally rest is tax base we went there before with soap based protocols right with XML and people say X knows too slow right but rest is also text-based and we do see repeating text that's being sent over and over again so it's also nice to create efficient as you can possibly be okay but I think we had rest RPC before I remember things like korva or am i I actually don't want to remember to be honest with you and you can remind us those days where we had to do korva do people want to be reminded of what about Cora anyone here at encore Bob before yeah I see yes with your hands up right but yes like our PC can so many of these issues and we have been there before we have been building distributed system with many of these technologies before but you know I was trying to remember remind myself about horrible so I actually just went and searched for a core ba Java tutorial right here and I found really really good to Tori I'm not gonna click on the first one when I click on this second one it's a really really great tutorial you know it went through all the details and how core power works and what type of things we need to get started for example we need to start with the IDL interface definition language so we can generate that the messages and the stops for other languages as well right and by the way this is just adding two numbers together right just add two numbers all right and it's a really good tutorial I ever need to learn core part this is a tutorial I will go and then from the server side they implemented the server implementation against the stub right adding two numbers together that's great and then I move down and I fell oh yeah look at all the quota right so if I need to make a client then I have to go through all of these things and like yeah that's probably why you know that didn't really work and that's for just adding two numbers not just for having two numbers right that's core box in Annecy common in this RMI in Java a lot of people you know have been using are in line arm is really great I love R&I it's really easy to use but if you stick with our in mind you're kind of stuck with the Java ecosystem right because if you ever move out of Java then you're kind of stuck there's nothing else you could actually use with our in line that would be very difficult to interoperate and then somebody had a brilliant idea of using XML as the exchange format so that becomes interoperable and that's turned into soap and so you know there are actually two styles of soap you have document style soap and you have RPC style soap in many of the server implementations I have seen are using RPC soap but like I said before they have issues because for the most part it's going to be slower to be processed to be processed it's because of XML and other text okay so what do we have today then I mean this Corbyn RMI are so bad it's like what do we have today yeah so I think that there's a place for RPC so communication especially for back in - back in communication behind the scenes right something that doesn't talk to a web server so the web browser right but it can only be great if it's actually simple to use and it's also interoperable and for that that's what we have today which is G RPC and that's what we're going to show a little bit and it is something that stands from Google so we actually use RPC extensively in our own vacuums right we actually make 10 to the 10 our PC codes per second I think about it that's how much RPC closer are making today so when we're doing this with an internal project called stubby that's the internal RPC stack that we use in C RPC is really just the open source version of stubby okay so it's Google RPC them know so the G into RPC does not stand for any company I know of the G&G RPC is actually recursive acronym it actually stands for a tree RPC remote procedure call framework right and it was designed to be simple to use and a Google we actually use multiple different languages right so it was also designed to be interoperable between different languages as well and like I said we make 10 to the 10 codes per second so it's also designed to be very performant just imagine if is like one byte less efficient so if every call it takes one extra byte to make well that would be 10 to the 10 more bytes for a second that we have to transfer everywhere right so it was really designed to be as efficient as possible ok so let's just talk about the basics now what it is and what it tries to do before we get into the GRDC basics first I want to point out some motivation and design principles we are behind GPC there's actually a website that you can go to Jerry CIOs watch blog book principles where you can read all of these in detail but I want to point out a few things first it's free and open I think it's very important that you rely on open source and free software and that's what GRDC is as ray mentioned it's very performant and you will see at different levels like the connection level or serialization everything Jesse tries to best-performing as possible and lastly in distributed systems people usually forget the fact that things are distributed and when things work they think that they're calling objects and they are calling like methods on those objects but then when things don't work they don't really write code to grind against those right so injera PC to avoid that problem we have what we call services and you exchange messages with services so this way you always are reminded of the fact that you're talking to services and you're passing messages to those services so these are some of the design principles and you can read more about them on the website I mentioned in terms of how G RPC works at the high level first you define a service definition file so this is basically a high-level description of what your services are that you're exposing and what the methods are on those services and I really like this because when you come into a project initially it's really hard to get a high-level overview or what the classes are and what the main services are what with Jerry PC we have this you have this service definition file written in protocol buffer and we said you get a really nice overview of what the services are and what they are exposing so from the service definition you generate code you generate client-side stubs and server-side stubs so this stuff they're generated for 10 more than 10 languages and they basically handle this low-level connectivity between the client and the server so all the connection details they're generated for you you don't have to worry about that so once you have the service definition and you're the clients lab and the service stub then you get the efficiency in serialization so G RPC uses protobufs and and it's really efficient I will talk about that shortly also if you are in net world there's bond as well on average RPC so you get serialization not just in Java but also in other languages like whatnot and you get connection efficiency with HTTP too and we'll talk about HTTP two in detail later and the other thing is connection options so depending on what kind of application you are building you can have generic connections where you make a request I'm going to get a reply you can do server-side streaming so for example your if you're building like a stock up location where the service stands also stock updates to your client you can use server-side streaming you can decline Sai streaming where the client streams to the server or you can do a bi-directional streaming where the client disturb where they send messages to each other all the time and will actually show you an example that bi-directional streaming chat application later and finally you have options with authentication so you can use this L and TLS you can do token-based authentication and you can plug in any kind of authentication that you want to do so we try to make it as expensive as possible at the very high level let's imagine that you have a java service so you generate the the G RPC service for that Java service from the service definition and then you might have clients talking to the service so you might have a mobile client and you might have a laptop client talking to your service they talk through the stubs that get generated so all that connection details is abstracted away from you that it's generated code that you have to worry about then your service might be talking to another service but this service can be a Python service and then your Java service again talks to the Python service using to stop and then maybe your pattern service talks to two more other micro services like go line service or C++ service again through the stubs so the beauty of this model is that the communication between the client and the server and the communication between my services they all happen through stuff that G RPC handles for you basically and the other thing is the the multi-language support so you can have services in Java you can have services in England so if you have different teams working on different languages it's not a problem all you have to agree on is the service definition and and then from there on everything is generated that you can rely on so now we will go through a simple hello world application and show us how this looks in code so let's take a look so ready can you tell us like what this app is about so so first of all I'm going to start simple right I'm going to go to a simple jar PC server and what this actually does is actually uses hello writes a greeting hello world of G RPC so first of all we need to define the service definition and that is written in the proto buffer language so the file is called a proto make sure you can see it clearly on the Green right and in this photo file we can actually define multiple things here right so first of all we need to make sure that we're using protocol for three and just like Java we can put everything under a namespace or a package right and then we can define the messages and these are the things that will ultimately get turned into like a class to hold these objects to hold these values and in the message we'll call we can define our attributes and these artistic fields in the message and they are strongly typed so you can use strong typing you can even have you know like a list of strings for example you can have a strongly typed map with the keys and value pair you can even have inaugurations like Inghams in this case tank right now you may be I feel pretty happy right so there's you known for happy and at the in 20mins you could be really sleepy Coquelin out here yeah and the end of this copy be you could be very angry right so that's why you have these nominations so what are those one twos and threes yeah so these numbers really defines the that uniquely defines the field or references to the field now remember in sloping XML or in rest you refer to each of the fields we have the text name of the Theo name right so for example age you have to send a to across the whole time input a buffer when we serialize this object rather than sending the field name with the actual name of it well as you use the number indication Joe so in this case over the wire which is still in the number two in just one bite and our directly reference to this particular field right so now we get a lot more efficiency without having to send the same text over and over again and finally we can define the service itself so once you defines that the payload for the request and the response you can then define the service and within the service you can define multiple RPC operations here I only define one and that's a greeting service so it's a screeching operation taking the request payload and returns the response payload and that's a very simple unary required teacher to request a response ok so what do we do after we have this service definition file yeah so once you have this right it's not in Java obviously right we have to use something to generate the Java and for that there is actually Java let me see here if you go to github and go to the gr PC github which is the G RPC Java if you help in this case okay so it's G RPC /er PC Java and in here we actually have a plugins you can use right so you see RPC in Java first of all you need the dependency and then you need to add in a plug-in to automatically generate from this from this proto file and generate the Java files for you now there are two plugins you can use there is a maven grader how many people here use maven maybe wow that's another than one yeah what about grater grater okay not many Gradle users here and assuming that people who didn't raise your hand you're using in in anyway now there's no way some people you can maybe there's don't let people who are out there people here yeah that's for those of you guys there is a new guest package that you can install and there's a protest Exe file and from there you can still generate code so we have something for that that's ooh yeah so I'm getting right with the end and you know with even if you make file you can always be able to generate these stops yeah so so all you need to do is copy and paste these into the problem in and you're tied in to the ghost write the the compiler will compile custom so whenever you try to package or compile your app it will just try to generate this stuff for you and I have this already generated and and we can actually implement the server so it's going to generate a server-side stub that you can extend right so that is the server side stuff that gets generated from so you do I guess you always expense from the generator stuff so I guess right yeah yep I'll put the server implementation you always have to expand the server-side stuff there are other ways to do it that's more advanced but it's probably the easiest way to get started and then they implement the method now here's the here's the thing about this operation you can see that I receive the request parameter in the method parameter right that makes a lot of sense but I thought we only return one thing so shouldn't return value to be on this side well actually in this case the return value is actually returned via a callback and the code is code a stream observer this is because on the server side in Java everything is implemented in synchronous servers by default okay so this cop is really there so that we can implement everything as synchronously and so when you're ready to return that the data to the clients you just call the callback and you can say you know here we can generate the stub right I'm going to say hello whatever my name and then we can say response observer on next and that will then send you know make the callback and send the data back and one thing I wanted to point out is that this observer interface really has three methods in there it has all net uncompleted and on arrow now if you think carefully this actually matched really really well to the reactive paradigm if you look at rxjava or any of the other reactive string related things they also have the similar three callbacks as I said we also realize that there's also builders everywhere right so I guess Jerrica in java relies on builders to set things and then you build it to get the actual thing that you want right yeah yeah so everything in key RPC that's been generated it's going to be immutable by default and that's why they're using the buter pattern extensively so every time you need to create a new payload you gotta use the pewters and the other nice thing is that everything strongly types so if you'll get requests for example you can get the name from that you can get the age of the person so you there strongly type objects which I really like as a teacher of developer yeah and a nice thing is that once you have implemented this stuff the server side code all you need to do is to guess what use the server puter use the buter everywhere you listen on the port 8080 and it gives you a civil reference and then you can add your service implementation into it right you don't have to specify the URLs or anything like what - listen up just give you the server's implementation and then you just go server start and I will start the server for you in the background and so in order for to prevent from the main threat from the main threat from exiting then you got out way for determination otherwise this program will just exit in like a second okay what about the Colette's take a look at the client now yeah let's go here so here we have the client enemies used to open up the client code briefly yeah so you want to tell us a little bit about the client yeah so I guess client is a little bit more involved so first you need to define your connection nature to the to the servers or the type of connection so first you create what calls a channel so a channel basically abstracts your connection to the server here we are saying that we are using a channel for this house and for this port and then we are using plain text which means that we are using HTTP or HTTPS because this is a demo and I don't want to deal with certificate and then once I do the build I get my channel then after that I need to create a stuff because I saw two servers via stubs so when you create sometimes you have two choices the blocking stuff and non blocking stuff so in blocking stuff you when you make a call it works until you get a response and that's what I want here because this is a hello world application so from the generated code we do jerky service new walking stub and then you pass in the channel your basically your connection to the stop and then once you have this stuff if strongly typed so you know what methods there are to call so from stub we called greeting and then we know that we had to pass in a hello request to the greeting method so we create our hello request with the premises that we want like Ray he he is trying to be funny by typing 18 for the age and he's very happy and I so we create that and then we build it so we got the request and that we send that and since this is a blocking call we'll get a response it will work and then once we have the responsible just print it out so that's all there is to it do you think this work should we uh let's try to try it out yeah yeah so I see here I got my oh I'm in the wrong direction something need to go into my server code let me zoom in a little bit so I'm going to just go ahead and do my Stratford server there we go server server started very good and I got my client so because I viewed the photo file into the stuff so everything just there in the package I just have to add a dependency to wait and hopefully with my client I can't just make this call I see there we go so I got the message back I says hello there right and on the server side I can also see whatever I pass thing that we implement the the print the output circuit of to string automatically as well okay so it's pretty simple thirty-six years so let me go back here so let's see what actually happens behind the scenes right so we see that it's really easy to you know choose to use the library but let's actually happen underneath the code what's happening through the connection zone now and first we need to understand HTTP 2 because G RPC is spewed on top of HDD - and what does that mean right so first of all HTTP has been around for a very long time things are nice and naughty right yeah it's been a long journey and in 1997 there was HTTP 1.0 and but I only lived very shortly before 1.1 came out and then we've been using HTTP 1.1 ever since it's been about 20 years now look at that how many technology you know that lasts this long right I mean I'm using a phone right now I changed my phone just every year or every two years but this protocol has been around for 20 years that's quite amazing but so it's working so well why why are we talking about HTTP - now listen what's next yeah I mean so hdc1 one third as well so far but actually there are a few problems HTTP 101 so when you look at the parallelism HTTP 1 0 and 1 1 whenever you need to create a new HTTP request you need to create a new TCP connection so that means that you are basically limited by the number of connections you have on your on your machine so that's not really that parallel you are limited by the number of the City connections and also initializing connection it's also expensive operation like it was the more the more times you have to initialize it is actually kind of and just to do that yeah and then if you look at it initially t10 you would make a request and then you will get a reply and then you make another request and you'll have to wait for that reply and then you'll make another request so it was really simple to understand but at the same time every time you make a request you had to wait for by before we can make more requests but I thought I thought we had work around it it's called pipelining right in HTTP one point something we can do pipelining yes yeah so you know your stuff great yeah so initially p11 means for this pipelining so in pipelining the idea is you basically send messages all at once you don't have to wait for the other one to finish but the problem in this case is you still need to reply send your responses in order so if one of the responses take a long time you're basically blocking all the responses or the others and this problem is known as hello whine walking and so pipelining helps for sending the request but it doesn't really help with getting the responses asynchronously their stuff still blocks so it doesn't really solve all the problems and the other problem that you have really see one point X is the headers so the HTTP headers they're quite work boss and even though when you look at the different requests a few things changed in the headers there most of the same or we still send those headers all the time and then we do that in plain text so not only we send them all the time but we send them in plain text so they're really inefficient if you ever opened up the HTTP payload and see the actual payload with the headers in the pillow itself sometimes your message could actually be a lot like fewer bytes in the actual header that you sent require yeah so we realized this problems at Google so around 2009 2010 we started working on something called speedy and then speedy basically turn into HTTP 2 so speedy kind of transformed into what we call a ship to today so what is HTTP to basically HTTP 2 tries to address all the problems that is typically one point one has it tries to improve the end-user latency so we want to make sure the user feels like things are fast we want to address the head of line blocking issue we want to get rid of these multiple connections because creating connections and tearing down connections it takes a lot of time so we want to get rid of that and it tries to minimize the protocol overhead so all the stuff that we talked about HTTP headers we try to minimize that and I have to point out that it doesn't try to replace HTTP one month we tries to make it better and so it tries to enhance directly to one month basically so in HTTP 2 there is this notion of frames and messages and streams so frames are the smallest chunks that you you basically send and they can be data frames they can be header frames that I'll talk about in the next slide then combination of frames are called messages and then messages are exchanged over what's called streams so if you look at in HTTP one one if you do a post request and the headers and the body will be sent together but then a should be - we basically break that into two frames they're binary based frames so you would have a headers frame and you would have have one or more data frames so that way you can send things as they're available you don't have to wait for the whole thing to come together to send it or receive it so if you have a very large object we have to send a pass the wire it will be chunked into different units right exactly and it will be sent as we can send them so it will do much faster so if you look at for example a client server where the key thing is you have a single TCP connection so you don't have this like multiple TCP connection issue anymore and then over this single TCP connection you have multiple streams so in this case we have stream one that's sending some headers and data and as you realize the headers and data is there they're separate so that they're chunk and then you have another stream stream - and then you have another stream stream tree with headers and data and the key thing here is that everything is scented everything is sent as they're available and nothing is blocked nothing is waiting for another stream or a data frame so that's the key so or single TCP connection where multiplexing multiple streams which makes a huge difference and I guess we can talk about HTTP headers now yeah it's actually one of my favorite part of it because like I said before the header takes a lot of space that's what in some cases for a small message right the header is going to take most of the space so this is how it works in HTTP 1 right whatever header you sent is going to be inclined text so first of all they're gonna take bytes in HTTP 2 well we're also going to send it over as well especially the first time but just remember HTTP 2 as a binary protocol Alpana means is that even the methods for the guest and the puts the all of those things are actually encoding binary in the first place so rather than sending the word yet the yes we just sent supplies over to indicate the get method right but but the header is itself that the key value pair would still be sent over for the very first time however we do apply some kind of compression it's called a stack right so in a should be - if you make another request right with the same headers you guys send everything the same again if you do change something like in this case I change path or whatever like that maybe one of the head has changed well in our case http/2 well you know we have to send everything anything it should be one you have to resend everything again buying HP - it only needs to stand the difference and for all of the previously sent headers and the values that's released sent before the server in decline and maintaining our index so they can actually just you know indicate that which index which previously sent values we need to use rather than resending the actual value so you get a lot more efficiency which is trying to you know resend the request with the same headers all over so you're not on this unless but you also compress what you sent so it's much more efficient than HTTP one really yeah so I'm see what does that mean for you right for for people who are using HTTP whether you're just using for the for the from the browser to browser or if you're using hb2 for your back-end services right so there's a really good demo code HP to demo dial and here we have let me see if I can refresh it okay so here we have that's real smart let me try that out at every code I see it so there is we have a HTTP one connection what is actually trying to do with the load image tiles right they're actually small tiles that we have to make connections to to load right so it's every time you trying to make a connection and load these image files and there's no caching there's some caching on these images now if I run the HTT to test you can see that it's actually a lot faster even though it has really fast internet here even with HTTP 2 is 2 times faster in this case so we can try the skin HTTP one and NCP - all right that's also because of all the benefits of HTTP to that we talk about okay so T RPC like I said is literally a total buffer with the serialization over HTTP - I suppose - what people typically use for rest which is Jason over HTTP so this way not only do you get the benefits of h-2b - with this efficiency but you also get the binary encoding of put a buffer that will definitely you know reduce the message sizes by quite a bit but it's also faster to process a binary data so just to show you a quick difference in terms of performance first of all I have to say of course of course binary data a binary our pcs are going to be faster than text right that's a given but how much faster we actually switch on a switch what we for for Google cloud pub/sub which is our messaging system that people can use today on Google cloud platform we added that the G RPC endpoints in addition to the restful endpoint and they did a little benchmark right so for example ologist for the soup food perspective by switching over to G RPC they realize three times again in terms of performance but what's even more important though is if you look at per CPU performance on using G RPC you can 11 times difference the Palestinian to me what that means is that is definitely utilizing the CPU much much better and that's important as we are moving into sales cloud native application you want to impact your applications you know on securing fewer servers if you really need to get a CPU in frequency in addition if you're running this in the mobile client right on the mobile devices you definitely want the users to have faster response times you have you won't have lower latency and of course you want to use less battery so being able to process more quickly to you it's definitely a great benefit yep and what I really like about Jeff is like all these efficiencies are nice but for me as a person who codes in Java and c-sharp I really like a framework that supports multiple languages and just PCs is really good in that so Jeff is supports Java C++ C sharp and many more and community I'm sure will add even more language is going forward and it's supported on different platforms like Mac Linux and Windows which is great for me because I have a Windows laptop I have a Mac laptop so I can run GRP see where I am and I really like that the other thing is connection options so I mentioned this before Jer PC supports multiple types of connections so you can have unary connections where it's just a simple request and reply you can have server-side streaming and you can have clients light streaming or you can have bi-directional streams where the client and the server they can send messages to each other at any time so what we're going to do in the in the last part of the talk is we're going to build an application that will use bi-directional streaming and it will and we will do Java and.net and see if it works so I would rate explained the application a little bit let's see if it works I know it works in Java I don't know about on that it doesn't work in the most even better during a Java conferences so you know I know I'm just going to take people to the right level alright so I'm going to pull up let me see here move this over a little bit ok so here we have a stop that were really created so it so can you tell us the app for what it is yeah so I'm going to talk about user profile yep so the app is that a chat application right so we're going to do spy directional streaming I'm going to buta a chat server that will take a string from different clients right and then we'll just use streaming mechanisms to broadcast the message yourself to oh of the kinetic client so for example the payload looks like this we have a chat message right we'll have the phone in the who sent this message and the message itself and the service itself is going to be like that I'm not assuming a little bit so it's got a chat operation but you make is streaming if you want server-side streaming you just add string to the return value if you want client-side streaming at stream to the request value does request ID if you want slider rational streaming it just add string to both sides so now if somebody if a client established this chat operation with the server now it's a bi-directional streaming connection what that means is the client can continuously send the chat messages to a server and the server can continuously use the same string to return messages to the client okay and the way I'm going to infinite implement it is that I see here I implemented I have the stop generator already so it generates this chat service imple and it's it gives me this this operation this method I need to override Wisco chat now look here it is very interesting method is really interesting signature okay first of all to return anything to the client because there is a stream and synchronous we have to use a stream observer so this is a callback that I need to use to send data back to the client but how does that client send data to the server in a stream well from the client-side they will also have a callback that's also a streaming server that will listen on so the server actually have to return a new stream observer that it will be literally being used by the client to send data right in conceptually that's the case but we're not passing references in this case but conceptually that's how I think about it so in this new extreme observer whatever the client sends me a message is going through CODIS on next method and I'm going to receive this message right and when I do receive this message holder I do I want to broadcasted it to all of those existing kinetic client so every time a new client connects I add this observer that the callback observer into a list so if I want to broadcast everything back to the client well all I need to do is to say observer I can get it right over them like VI stream I can say for each of the observer I'm going to call our next right that's how we send data back to the client and when we do this I need to give it a message from server right value and to construct this we can of course use the boobers so we can say something like chat message from server I'm going to use a new pewter and contribute and in this payload I'm just going to sending the message that I receive which is the value okay and I can assign this to a variable a local variable and not all I need to do and I really like that how everything is so strong the type you don't have to be guests like this HTTP root because I need to make you just get the Builder and set things you need and build it and you have it yeah yeah so nicely that's all I need to do but then we also have these two other methods we need to implement on arrow that's whenever you have a connection error we got or client error of something you know you should catch it and I'm going to you what oh good job at developers to which is to do nothing now it's getting in this case we actually want to say for example remove the reference and you do want to error handle the arrow somehow it's not clean the statue is just in case something goes wrong okay and same thing here with the connection was disconnected successfully or the client says I'm not Lee then uncompleted will be called right so that's a successful disconnection and for that I'm also going to remove myself from the list okay and that's all we need to do to implement a server that I see if it works in a second but just so you know like how do I start the server well like I said before you create a new server beuter you create a server and then you co start and I say so exactly the same as HelloWorld the only difference is your service implementation basically that's the difference right yeah yeah pretty much so I'll do that I'm going to maybe install and yeah yeah let me do that so just so the consumer will get this package okay and then I'm going to run this some gone oh oh yeah so I have this jumbo jar not har sorry juwatch our target and I got this chat server app I can run oh oh oh I see okay I see I think I know what's going on here all right so let me do a Java exact and then I'm going to define the main class is that the way I do it yeah and I'm going to run this with what is the class name just going to find this out real quickly there we go College our PC da server dot chat server right is that it's how I started a new project yeah there we go okay whoo I started pretty well it's listening on port 8080 alright wait don't for the server yes so I have to show like this actually works right so for that we're going to do something pretty crazy it's going to be the first time not meeting I do this together so on his screen he's actually coding this in non visual studio the best ID features video I'm using IntelliJ right here okay so you can see the color right and so he's got a windows form application yep I hear I have a Java FX application I'm assuming I show very quickly what the java application looks like just so you know what we're going to expect if if it works huh it works alright so here's the client I'm going to say GFX run for example see that I shouldn't shows up yeah there we go recall the name and so supposedly if I say hello or whatever issue sent to the server and it should just you know be able to get the data back as well so hopefully by the end of this right we'll have a client that's written Java client that's written down there and we should actually be able to talk to each other okay hopefully all right so let's get started so first of all we have the channel I also have the channel here you also have the channel yeah so it's very similar it's like a rate how many people think the Java code will work nobody Wow how many people think that a network coworker Wow there's people moving down okay that's right it's nice right it's okay I also have this table right so I mean shooting this table do you have a stop well you know we don't deal with stubs we have what call is that client you know so we have a chat service client so that's what it's doing on that yeah I see but you do passing the channel to that client yeah basically I create a client with the channel and then I have my chat service from there okay that's my stuff okay cool so how do I I'm going to make a connection when I start this operation so I'm gonna use this stuff I have and run coach at okay yeah for this I have to caching a stream observer okay so mater is doing yeah so I I do my chess service top chat and with that I got a I got a call and I'm just gonna wrap that into using because we have this nice thing in not confusing that basically makes sure that my call is cleaned when it's done so I had that you know what I do like my auto completion I'm saying okay good all right so how do we get paid how from this server right so so this remote server will receive data when the server you know broadcast the data to all of the clients right so every time a new message arrives it's gonna call next so in Java FX I'm guy need to you know put this in my UI so I'm going through your wrong later good because in Java like UI threats and backgrounds right don't mix well so I said when I say run later and I'm going to receive the message I'm going to say message you start act so I have a list here I can just add things into it and I can say well what am I going to add to my message I'm gonna say it necessary to target from okay in plus a so that's full send a message and then I'm going to get an actual message itself okay okay what I'm doing here is I'm putting everything in a wire loop so I get I get my call I get my response which stream so that's what we have in net and then I do move next so that basically gives me the next one and then there we have this nice thing in there called a singer weight so I'm more weighting that so basically waits for the next message without blocking so that that's kind of like the Beatle net so with that I'll get my next message and I guess I need to say like server message and then I can say call response training current so this will give me the message from the server and then now I need to get the message from the other client as a server message but I think it's message yep yeah so I have the message basically from the other client now is that where we are yes okay cool so the nice thing I need to do is to basically format the message and display it so that's what I'm going to work on now so I'm already done with that oh yeah you're too fast man I can't type like you auto-completion or something yeah well I don't I didn't do this before I'll do string format and then I'll say is u 1 and u is server working maybe to make sure that server is working I will find out together no do it I don't want to stress I'm not done yet we're not done yet yeah and I can't be so cool if it works how many people think this which is work almost box Wow still nobody actually stopped asking questions here I know don't ask the tough you're adding the pressure all right have you displayed the message yeah yes this is chat text box text up and then I died just to display a message yeah so that's what I do yep how do you handle arrows because I'm gonna do nothing so what I'm going to do is I'm just going to put try and then wrap this in a try-catch yeah and do not drive or see exception yeah and do nothing and do nothing yes well now I need to set the call it I all set the call to now so I know that my clothes didn't and then I'll probably throw it as well why not all right all right all right so so it's great I will doing this at the end of the talk because it doesn't work would you say oh thank you very much and disappear right now all right so now we are receiving messages now how do we send messages so let's do this together so for me oh sorry sorry the address I have this window manager that the resize is everything all the time so that gets a little tough so let me see here and make sure oh my gosh stop resizing all right here we go there you go yeah you can see everyone all right so for me when I have this send button I have this in and I can say set on action so whenever somebody click on the Sena action send button I'm going to send message to the server well how do I actually do that in Java well remember the server returns me a stream observer in concept right but in context I can also get this observer from the the client stub right so now this reference whenever you say on observer down our necks why should we send the data to the server instead right so I can say observer that I'll next I can construct my message I'm going to say new buter and Bute okay and I'm going to set the message which is my message to target text okay I'm going to set the front which is the name dog attacks and that's it so every time I click on the send button it will send or string this data to the server and the server is going to receive it it's going to broadcast it to all of the kinetic client and the client will receive this message back and then I'm going to display this into the JavaFX client so yeah in the don't know part we basically create a chat message just like Java and then from then on I have this call object that I can use to send messages so from kolodziejczak I get a request stream and then I just say write async and passing a message and this is an async call so it doesn't work so I just I wait on it and I just send a message that's it okay and you must realize that here we don't have any memory requests observers and stuff like that because we are relying on a singer weight or net so it the call to me at least it looks much cleaner than Java but maybe that's just me okay well I see if it work because nobody here believe it will work all right correct yeah what is my IP address on a second before we connect I need to make sure it works on my local machine as well but let me see here with my IP address nobody leaves off me please this is a live demo Northy tossing against my IP all right there you go so that's my IP address 192 what is 1031 yeah all right so it's like 10 to the 1 to 1 I do yeah so what you do then we just kind of compile my thing and connect first because I want to make sure everything worked and I said okay I'm ready you're ready I'm not never ready some when I say hello mate eh all right what that's great that's good let me try another connection hang on a second a second you want to connect as well doesn't work no is it port 8080 88 it yeah did you plan on how to get to one late - is that right hang on a second you know here we go can 31 - 192 yeah we have some issue with the networking here it seems to be blocking us a little bit we work on the oh you know what doesn't work wait are you going casino 2003 Wi-Fi oh I know you're on the other one give me a vodka no mm okay okay okay so I was on a different access point it's my fault ah yeah there we go okay all right whoo whoo whoo so whoever if you didn't raise your hand you're absolutely right so let me try this again so here's my new IP address 1032 0dr money hey what's on my hand I'm just saying 0 70 all right the moment of truth the moment of truth all right let's do it come on we got two minutes left so people came out you know if it doesn't work that's fine with you so I cannot disappear nice thank you oh oh that was close I was close you always give me a harder that great well I mean let me connect another one and it's gonna be this one I love to do so our manager his name is Greg that's it Greg okay good job people and now that were working like me like why thanks I can do this all day do I get a race right like I can do this all day but right no sorry right whatever so anyway so that's it yeah so that was pretty easy to do I mean with literally donating about you know ten minutes or ten minutes or so so hopefully you'll see how easy it is to use a gr PC right hopefully you can use it in your own applications and we love to get your contribution as well there are really open community so I won't really looking forward to everybody's participation if you're using it please send us feedback as well yeah so if you want to slice just follow us if you fill the talk back to feed that link come and get your t-shirt and we have stickers thanks for your time okay thank you so much I'm not sure if they have time for questions do we have time for questions like one minute no really yeah okay bye we're around so stop by and we'll build that today
Info
Channel: Voxxed Days Luxembourg
Views: 42,963
Rating: undefined out of 5
Keywords: VoxxedDays, Luxembourg
Id: hNFM2pDGwKI
Channel Id: undefined
Length: 49min 32sec (2972 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.