Reactive Quarkus–A Java Mutiny | DevNation Tech Talk

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to our new definition Java tech talks on Fridays and today I'm super excited because we have gonna have like to chew all my favorite subjects first we're going to talking about Quercus ago and we're also going to be talking about reactive and the special guest today is my dear friend clemens Kofi a which is a French guy you can tell by the name is Ellen love one wine lover and he's also on the word stop reactive experts so let me share the stage with you come on please go ahead thank you it's son so again my name is clay - Kofi I'm working at where that I'm doing a lot of right you start with that and today I'm already really excited to have the ability to present makini a project that I've been cooking for a few months and it's a novel reactive programming libraries that we have integrated in Quercus this is a result almost five years of walk around were active and analyze all the practice or the pitfalls we have seen one developers and many enterprise developers try to use we're active so we would see how it looks like that the first question is why does Reiki matters because we have a lot of things about working these days but most of them does not really explain why it's actually ensue the root of the issue is distributed systems today most of the systems you are building are distributed systems why because as soon as your code is doing an interaction with something outside of its own process like sending an email like interacting with database like cooling an HTTP service it becomes a distributed system missing about distributed systems and we know that for a long time that they are very very challenging to build and to maintain so it was hard and now it become even harder why oh it's not a question of technologies Cobra was fine a few years back it's a question of use aid everything as terms on how your system is going to be used the first thing is a user's a few days ago I had a call the customers that I visited two three years ago and two two years ago they say yeah we don't care about Frankie who I'm not at this scale we don't need this user experience and they call me back to say okay so it's escalated quickly we really need to find a solution the trick is what they realize is that most of the people know I've been used to what I call to Google expressions something that is blasting fast and never frame and now you need two approaches can effect France so we as close as possible of providing this user experience these are sub P keys I want to data to come to them and not fetch it anymore so I want something fast I want something reliable so it's pretty hard to build so don't thing is that IOT and mobiles are changing the game this scene is are never sleeping so they are always sending advanced missile requests to your system so your system is really really struggling to buy the lot so you need to find some things some way to do this and then finally the event-driven things these days there is a lot a lot of events you probably heard a lot about cap causes sin so one or two years Casca is becoming the cornerstone of any modern systems and Kefka is what it's just a way to take event from A to B so every time you use Casca it's a lot to do with even driven architectures and events so how does right kliff helps to build such kind of systems what's the first thing that reactive is going to embrace non-working i/o by doing this you are going to use the resources more efficiently instead of using one thread per request one thread pair advanced you are going to use one thread to under multiple concurrent requests as soon as one request need to do an outbound call like cooling a database or calling a remote service it's going to release the thread and sew the thread can be can be used to under another advance of requests thanks to this you cannot learn more load on on the current set of infrastructure you are and so you will reduce a cloud bill or optimize the deployment of city URL yeah it also improves the responsiveness so step closer to the Google experience in the sense that you get way more concurrent users at the same time the second part of writing which is really important today is these event driven flavors what I mean by event driven is the ability to write code like this on even hdy that Timmy when you have a lot of data intensive systems where you need to process data that are coming from IOT devices or mobile phone and you need to react quickly to that so all those reactive walks under the hood well in the Java world it's probably an 80 layer on top on which you have a right if Emma Nettie is an amazing tool tip not working I will tilt it it's really low level and it's all revolves that a lot of variety frameworks have been built on top of that to make it a little bit more easier to use so all the network part is going to be under by DT and then you have this for active frameworks that will take those primitives provided by nitty and make them usable Nietzsche is going to use an event loop what we will call an idle threat and the Reiki framework will be called on this is red and this and the new code is also going to be called on this is red so you see coming right if it's gone on the IO thread or do I do to under to write code that blocks you can't because if you start looking to i/o thread all the promises from reactive just fall apart and collapse so you must not block never and here is a tricky scene how do items rights and who knows best so let's take two items the first one is callbacks callbacks are very simple clean you really season seven driven Nate you're here the right number this is some vertex code where you attach a request under and every time that the HTTP server get a request this is called so we really see this event-driven manner on request do this tricky thing with callbacks that it doesn't compost well so very quickly you end up writing such kind of code and it's really hard to read up to razón about indication is a nightmare so it doesn't really scale where on the other side you can use our active extension and like your programming and so use a synchronous data streams to manipulate a synchronous objects a synchronous action and compose them directive extension define a lot of different operators so you can compose almost all you want to operation there is a few issues with this approach it's hard to learn and really quickly you end up with your map slash black pepper angle and we we have seen developer writing nice code very elegant and say oh yes that's pretty nice I love it and then one week later coming back to the current a what did I try to do so the fact that it can abstract neurology it to make your logic not necessarily easy to follow is is really really hard to read and how to maintain and the gap for regular developers writer kind of code is really when you're high we have seen that with we have trained a lot of variety developers over the last five years and they're really struggling learning and understanding this so let me now introduce Metheny mitten is a novel reactive programming library that as I said at the beginning analyzed yeah during the last five years everything around were active what we wanted to do with mutinies who are really an event with an API so the API would be composed with an item on failure on completion on overflow and so on so really on something do that the API we want it to be navigable the tricky thing is that when you implement reactive extensions we define a lot of operators it hand ups with classes with hundreds of missiles and some missiles have dozen of overloaded variants so we have some developer in their IDE trying to scroll in this list and trying to understand which one they need picking the world that max their signature of the expectation was not really understanding what it was actually doing we did we wanted to avoid this saying and not seeing we want to focus on neurologic all we are going to all you are going to express your new positive neurology and avoid any mathematical concepts so in mutant you are going to write that kind of thing so it let's imagine that you have an a second of service called service where you can order you get an a synchronous result that we call an uni in whittany and then you say on item do this on failure recover with that and so on the subscription block is very important it's what trigger of the computation by default everything is lady and can be reused and the subscription is really what's trigger it so then once you have this the events are going to flow in your pipeline and you will be able to under all the events that have been trigger mutiny comes with two types uni and Mooji you needs for one item or failure it's perfect while some cannot surprise ionic it provide all the composition construct you need for this and then multi multi is for data streams you can have so 0 to n items and its support backpacker what I mean by this is at multi element right two streams publisher so you have the right key frames back pressure depending on which type you are you don't necessarily have the same type of events but mostly similar and GIP I is mostly similar ok so what we'll also learn about your active over the last five years is that the one good way to let you explain what to activities and how you use it in structure it in action and that what we are going to do now and we are going to build this system so first we have a database which has been kept a plated with super arrows arrows and supervillains we have the soup service that will use this database to explore some assign panels rest and point then we have a fire service that we call the soup service to get your alga tabular and make them fight the outcome of this fight is going to be stand to the browser and send to Kafka where err on the other side we have a stud service that we collect them and compute some statistics about that so let's now switch to my card here it is so I are three my three services are all quadrants applications running in a development mode so I will be able to write my code and would be automatically refreshed so here we have the soup service the fight service and the start service and this will be this is my first resources for my soup service and what I can do immediately it is to do something like greetings public mutiny strings let's consult with teens and we'll turn some uni directly from an item that I know like greetings so if I do that what I mean by this is I'm creating a uni created from this item greetings so let's try this oops proteins okay it get it works so we had seen the wreck completion on this screen here and so now it should be much faster because there is no work completion tricky thing here that that doesn't make any sense we know the response so why we do it in a non synchronous and active manner and you're absolutely right so let's not switch to the VLANs class Villa is using what we call our active panel small entities so it's connected to and it's exposing a reactive API in cooperative activity I mean means meeting the API and what I want to do here is to pick a random VLANs for my villains collection so first thing I will do is get the number of villains drugs that I am then an item I will pick a random random one so I'm in this chrome so I will do one dumbed up next in value so now I have a random one in the bone so between zero and count and now I will retrieve it so on item police unis this is my index and here I will return final and one way to do that there is multiple way to do that but it's actually to do to get the page that start by at the end X and get one result and here we go I will remove this returns that and we have our way to retrieve one done I belong so again we retrieve the number of document this is a synchronous because it called with a database then come back once we have the result we pick a random number and then we retrieve the villains from the database so if you are used to writing programming you say what are those missiles I'm not used to that I'm used to Matt and flatmap I have a good news for you you can just to map and flatmap here so muesli I need to change a few scenes this is hero this is hero and that should be enough yes so why we support this on item and even driven approach we also support map and plan map and a couple of really well-known operators however be aware that this if you are cleaning them too much on nested them too much it makes you called not necessary nice to wait so be careful when user that we provide them so now that I have this to my shot list let's use them here so let's create slash a rule that will return a union for arrow and here I'll just do a roll dot find one done okay I'll do the same ways blend yeah and here so let's try this and I get and here oh yes can I get yes so I can get an arrow and Avila so it's your insolence of an mage or lever underneath what I can do now is also getting a stream of arrows so for example I can do oops I get that will return that will be on /e rolls and I'm going to return that as an SEC so server side server sent events so we are going to trim the result to the client each event is going to be JSON object okay and now I will overturn a milky of a wall and let's say that I want I roll emitted a blister gone so I create a milky thread from ticks every the guns and every time that I have a tick I'm going to retrieve an arrow and I need to return that and here I need to melt so this last part is actually interesting because we will trigger many a synchronous actions and we have to close Israel we don't care about interleaved results all we care about I'm all we want the ordering preserve nails doesn't care concatenate preserving it so know that we have this I can do stream and every segond oops oh I called up a rolls rules every second I will get a new evil so again every seconds we have a ticks that trigger anderson chrono sections and go to the database and retrieve it so let's no switch to the oral serum service of fight service so the fighter is is going to call this soup service get to enroll ghetto villains and make them fight to retrieve that I'm going to use a macro profile as client so this is a soup service client that has been connected to my applications and I retrieved my Wanda Monroe and my random villa in Anna synchronous manner so see I already returning unique and now in my Westeros I just need to do enrolled ships dot a trinomial but it's a distributed system so things can fail so I need to be a little bit more careful here so let's say that if I have no item after duration 500 minutes guns and fail ok and on failure time not or not whatever type of failure you will recover with a roll dot for Mac so I will do the same with Pilar get on them and inhale at that point nothing has been done I just represented my request but they are not really executed and I want to meet them but not one after the other ones that would be a waste of time I want to omit them at the same time and one boss we pride compute the outcome so I will do this by creating another uni that is a combination of or Eunice here arrow and villain and I will combine them with a missiles of our live rods which is compute fight outcome we don't exist anymore and I will work on that so this method is very simple it just take my heart take my villain and do some random things and decide who is the winner nothing very smart behind this so but now with this if I try to call it here we got two selected arrows selected villains and the winner which is does the name of the arrows of villains odds are one so I can do that a couple of times so that's pretty nice right it's it's a actually how I compose a synchronous actions very very nicely and here every time I do this it calls a ship service twice get boss result call another service another missile and returns at so one thing we can do with this following the same thing I can also get to stream a fight which every seconds will do exactly the same thing get a row get to be lands and make them fight and this is the same trick I did earlier so I get a stream of ticks every seconds and five eight seconds I just trigger fight one thing I did not mention yet is that my computer fight outcome is actually sending the results to Kafka always it done it's done using micro profile wretchedness and ring and an emitter and every time that I get a fight it's right this fight to the channel fights which under being a cop capice so now I can on the other side in another micro-service consume those fights that comes from the five channels and do some computation on top of that though this is a game using macro profile right you miss engine and here I get my trimmer bytes and I need to produce the streams of stats so fight on every fight I'm going to scan so that means accumulate your results I need a strict rules that is going to be stats Stricker's which is the stricken curves you see the details here one by year old one by villains ok and once and every time that we have a fight we are going to call this compute miss compute mossad and what on this so again what did I do every time that you get a fight its artists fight attack lemmy accumulate this fight with the statistics we are and just update the contours so now if I go there and I do stream ok so at the beginning of 0 0 and then because it's kept guy is going to be play all the fights we already a plane so once a so wow the villains are definitely winning seven against one so let's try a few more fights to see if we can try to get better Cynthia Pro against 9 well ok so we cannot pledge that like this so it rolls must win so we are going to help them remember in the fight service I have written this code here and one thing I know for sure is up the villain fall back is actually not that good in term of liver is doesn't have a lot of power so if we can make the random villain miss so the little bit too slow then we are going to use a call back the call back and then arose I have a higher chance to win so let's do this I go back to my soup sir here this is a method I want to make slower and here on item delay it by once again something that's it so again it's very fluent it's very clear of what you want what you mean here I'm going to delay it by once again so now if I trigger some fight so we see that it's minute II it's the villain fallback that is used because we are after the deadline after the timeout so that means that the heroes are always do winning and here it was a no one eleven against nine so what we can do to is to close the soup service we plot it and I can still trigger some fight and by doing this I get balls for bags with a fall backs of the arrows which is Donatello total ninja and minute ex4 for the villains and so we can Dave for sure is going to win and yes so no a roll to 114 against nothing there's a few things that are interesting in in mutiny like how do we test typically some things that we can do in tests because we are we are not allowed to a block in your code but inside your test you could do that and blocking is done like this oh wait and definitely or wait utmost and you give a duration so that also helped a lot testing your applications in writing miss enduring we also have an in-memory connector that lets you avoid having to use CAF dyno test so we have plenty of sinks or runs ads that are already delivered I will switch back to my slides here that's how I have for you today we showed out a few minutes for questions if you aren't 30 by quackles or by mutiny and all mutiny has been integrated in caucus go to caucus dot IO almost all the services are api's caucus provides a variety of API that is now using mutiny this also includes every client from vertex the engine of quark it have a mutiny API do you want to stop coding and I can totally understand that cut the caucus I owe you generate to project and you're ready to go you want to interact with the team quark is do not only innovate in term of technologies it's also innovating how you want to write with the team by using something called Zurich if you never heard about the lip it's a lifetime experience the first week is interesting after that it's really great you will love it but yet the first week is weird you can follow us on Twitter and if you like crackles if you like what you have seen today go to this last URL here it's a card from Quackers give us a star it's not only useless but it makes house a quark you stream very very happy and that's it so at Sonic we have do we have some time for questions yes colonel well thank you very much for this very nice presentation I'm pretty sure we'll get a lot of github stars and a first question that your Frank is asking will the muting stuff running the worker threads of jax-rs or the vertex io threads so what if the internal operations are blocking those make these are great questions so by default when you do objective rates and point it's going to be called on a worker thread no quirk use provides this but also provides something called wacky routes where you will be called on the audio sweat so you decide what you want to do if you really are looking for high concurrency go for active routes if it's okay go for the regular worker thread apart for from interact arrests we have published on the quark is blog an article explaining the difference and why and what the concurrency different so go to the blog from Quackers and you will have all the details ok and I think it's related to the same subject is there anything that I should not not be reactive or can everything be reactive from beam issues um one of if you have a very blocking logic heavily cpu-intensive which will take few minutes let's say 3d modeling or something like that then yeah it's not I you'll bond so in Zakia is right it won't help much as soon as you have a lot of iOS and it's actually rarely receiving requests cooling other services relative is different in helping a lot one thing to say is that between a support context propagation so you can use transaction with moschini so before that was the thing all you cannot do that week you can use transaction with mutiny ah that's nice so since we're talking about transactions Ally cause is asking so does it make sense to compare combined mutiny with hibernate because of blocking JDBC so that's all getting a great question so yes I'd rather by default using blocking to the PC and that doesn't really make sense well you can still use it we we have seems to make you use it in whittany but yeah oh you lose a little bitty advantage what is pretty nice is that we are working on a racket version of hibernate that will avoid this and that will be based on reactive drivers that are totally non working in reactive so stay tuned it's coming okay and junior sensor asking what is the best way to handle clients connections um client disconnection there is a few things you can do here so let me write some code sets up won't really fit in this demo but for example on a failure you can we try so we connect let's say you want we try with some backups for example duration of seconds one and direction of don't 10 something like this you can also add a jitter if you want or that's two or something like that so we try is already built-in you don't have to do anything I'm not sure I'm going to increase this okay so you can do we try you can also do as we have seen recover you can recover we try and sit like that so it's going to be under like this once also one interesting aspect too is that you may want to do to do a cleanup when action is concerned we also provide a way to do this like on termination are on consolation you can execute some cleaning card again you really Cesar this event driven nature that we wanted to infuse at the core of mutiny and Iago is asking here is will mutiny replace reactive streams operators or will they both coexist and can be integrated so registrants operators is a spec from micro profile but it's it's it's a spec so it's a set of interfaces mutiny is really more a library so it's not a spec yet we are starting discussing whether or not it will make sense to provide a speck on top of that it's not we didn't take a decision yet one thing is that I have we implemented Y Q streams operators on top of mutiny so now I have two implementations I have the first one I did a few years back and one which is based on meeting so they can in what at the same time there is no problem with that and you can decide which one you want I strongly recommend meeting me because actually right it seems ups is what make us who are lies are something was not great so for the developer it was still too hard to understand to how to read and to how to maintain okay I think we're on the top of the hour so the last question is from Alexander does j-unit support are reactive stuff tests so when I need to test raki things I can I can use as a way to provide jobs if I show you so oh wait at most and indefinitely and synced up so I'm making blocking I know but I'm in my class so that's fine I'm okay with this I recommend I wait till et our libraries which lets you do almost the same thing or wait until the condition is met if you plan to do tests for even driven micro services like class car m2p or whatever we have something called in-memory connector which actually stitute a chart to cut count something like this and you can say okay I'm sending my site ABC through this missile and I am interested to see what what is the outcome and then you are you are also primitive to with without come and say okay that's the right processing that we expected or something like that so we provide a lot of tests utilities to do this even inside mutiny we provide test subscribers and signal jobs with a weight that we have seen and couple of thousands in taxes but basically if you have a code and you want to test it make it blocky make it blocking to relax you write it easier the tricky thing is that generally easier to reason about and test can be very very complicated and if not then just use a weight ability and keep it on blocking and at the end just wait until the completion nice I think we ran out of questions we ran out of time already so clémence I would like to thank you again for this very nice presentation I think the audience is as excited as I am about about Quercus and of course now you should be excited about reactive and mutiny oh thank you very much and hope to see you again in our nest next divination Java Tech Talks on Fridays thank you it done thank you for having me bye you
Info
Channel: Red Hat Developer
Views: 15,014
Rating: undefined out of 5
Keywords: Red Hat, Red Hat Developer, Burr Sutter, DevNation, DevNation Tech Talks, Java, Middleware, Quarkus, Mutiny
Id: kWlrGtwvOxg
Channel Id: undefined
Length: 34min 18sec (2058 seconds)
Published: Fri May 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.