Reactive isn't Complicated with Vert.x and the new Mutiny APIs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] so i'm very pleased to be back on on the manning twitch it's my second meeting i did one in october where i introduced vertex and active programming and reactive systems all these things um and i'm back today on friday it's friday evening here in france um so depending where you're in the world it's maybe lunchtime i don't know um so so we'll see um today i'm going to talk to you about all the things in right in the right space so obviously vertex will still be at the core of what i will be showing you today but i will also show you some of the stuff we've been developing in the recent month um and stuff that wasn't available when the book was released and namely these things um there are two things that have been new in the vertex world the first one is mutiny so mujin is our active programming library that i will show you it's in the same space and field as eric java for example that i was using in the book but it's a new reactive programming api that we've been designing at red at and which we have for vertex and quakers and we think it's a nice way to compose asynchronous operations and the other um novelty we have is is called hybrid interactive so you probably know hibernate because hibernate is that very famous object relational mapping technology um but it was interactive before um so now we have iphone interactive which you can use with vertex and you which you can use uh in corpus um maybe i can have a quick check in the chat so do you people know about vertex or is there anyone who doesn't know anything at all about vortex okay so nobody okay nobody seems to complain if i just don't talk too much but about the basic uh anyway i will show you some basic stuff with vortex in a way because i will use it to show you some um some some ways to use muji with vertex um so i'm going to show you a few slides but not it's not going to be a presentation about you know huge slice all the time stuff which doesn't make um doesn't make too much sense i'm going to share my screen um and i will give you a brief outline of what we're going to show today um so today um so yeah the i'm basically we're using a presentation that uh i did with my friend julian viet who's the leader of vortex um where we just talked about these things so these things um i i want to talk to you about directive continuum we've been uh creating a thread at um it's not a red light presentation but since i work for reddit i'm obviously going to be right at centric but this technologies they are not you know you can use them in non-red stacks if you want to that that's not an issue um so the first thing is on the left you have reactive um so it's what i'm more or less explaining well i hope it's not less but so what i'm explaining in the book is that reactive matters because you want to build systems that scale well and that are resource efficient so you don't want to use too much threads uh you you want to use a tiny number of threads and have many concurrent connections multiplex on this flat um and then by doing this you you get what we call a resource efficient design that's really what vertex is all about having that resource efficiency so you have vertex this modern reactive toolkit for the jvm so again vertex is not a framework um it's it's a toolkit so you get to pick the elements you want to build your your your services and then i will also by the end of this uh of this session i will show you um a modern interactive framework built on top of ibernite mutiny vertex which is called quarkus so i want to focus too much on quantus but basically the message is that corcus is based on vertex and you know vertex is repowering many things that you have in quarkx so in quarkx what you get is a nice framework which is well integrated uh batteries included a nice development experience but still it's powered by protect so you can really choose if you want a toolkit if you want a framework if you want both that's fine as well so again if you have any question anytime in the chat just paste it in the chat i will try to monitor and get back to you if you have any any question so again the benefits of going with reactive it's um basically with reactive you're going with non-blocking i o which is extremely important if you want to be resource efficient by doing so you're gonna use one thread to handle many many connections so typically with me i don't know four eight threads um you can deal with many many many many connections so the goal is to have a better quality of service because you're supposed to burn latency so burning latency in two in two cases um the first one is if you want to if you need to scale up because you have a traffic spike so if you have this kind of situation where traffic explodes you want to squeeze as much connection on on a service instance as you can and then if you need to you can spin your instances in your cluster like in kubernetes et cetera so that's one thing that's the scalability thing of going with non-blocking io but then the other bit is um being resilient so i'm not going to talk about resiliency today um but keep in mind that if you do reactive what you want is also to build a system that just handles failures and that can be resistant to failures and recover whenever whenever something wrong happens and again the goal is to keep latency under control so for example if your database is down you don't want to wait for 30 30 seconds to get an error you just want to build fast because you know the database is down so you need to react to this so that the the benefits of reactive so before i dive into um into talking to you about vertex um so we have a synchronous io which means we have to compose these asynchronous operations and it's not like in traditional imperative um programming where you have a thread you know you have this thread which is associated to your connection and that thread is going to follow along and you just do blocking io operations that's the imperative traditional model you can find in traditional stacks basically and not just in java like stuff like in python etc when you go with asynchronous io basically what you have is callbacks so you have callbacks and you get notified um whenever say a buffer is available or your your http request uh has completed etc and you need to compose these things uh and just if you just have callbacks it's not it's not really nice because if you have callbacks because basically you're gonna nest things and there are certain kinds of compositions that are hard to express a good example is if you have say 10 http requests that you want to do in parallel then is going to be a mess if you have callbacks because you need to aggregate the responses or the 10 http requests and and then check whenever you have a request do you have my whole request is it a fader etc it's not really nice um and i have examples in the book by the way if you want to check why callbacks are not always great so we have a bunch of programming models to deal with asynchronous io and specifically asynchronous operations composition um one which is uh now built into vertex four is the future on promises um it's a very simple model because uh you know you have something you get a future and when the future completes you know you you get your response and it's a nice model if you want to chain operations like you have a sequence of asynchronous operations it's uh it's a pretty good model uh then it tends to fall short if you want to have other things like um expressing retry policies if you want to enforce timeouts if you want to compose streams of operations it's not it's not really great um then we have reactive extensions um and reactive extensions is uh it's all about composing streams of asynchronous uh asynchronous events so that's what we have in the book with eric java and it's what we will have today with mutiny and the last model um which sometimes people think it's the silver bullet of asynchronous io uh is coroutines um so with creotins applied to us in canon scio uh you basically get the illusion of um writing imperative sequential code but underneath um you will have asynchronous operations um so it's a good implementation of that is the go in go the routines in cutting the kotlin curtains they are great but then again people tend to think it's magic and it solves all the problems it's not the truth um there are certain things that you know may be complicated with coroutines uh and i'm not just speaking about performance on the jvm because on the gvm right now we have nothing to do it properly so our offering to do um asynchronous io programming well relative programming in a nice fashion it's mutiny so it's a project we started like less than two years ago and we did this because we identified two problems uh in the um erective programming libraries on the jvm so one problem is what i call the mother the hell and it's the example you have on the left is basically an extract from the book so i'm still proud of this code no problem but the thing is if you look into it there are certain operators uh from heroes eric java um but there are certain operators that like flatten as flowball flat map single etc etc um these operators they come from um from functional programming and it's not exactly related to a problem domain you're trying to solve um so basically the the thing is if you want to use say this particular library in your code to compose asynchronous operations you need to uh to be familiar with um the digiums of asynchronous sorry functional programming um so after a while it's really it would be familiar for you to think that flat map is more or less i take an operation then i compose with something else and then i do something um but you know it's not it's it's not really readable and if you come back to this code a few months later later it's not necessarily obvious what it's doing like you you're like why is there flatteners followable i don't actually remember why but i had to please the tape checking somehow and on the right um is this the second problem we had identified um and which is the what you call navigability of the apis um so basically in these libraries um whenever you start to complete you know you use the good compilation of your id um you get you get shown so many many methods like you can see here you get concat with concave map single concat map dd error and there are many you know variants of these of these methods and you just you know you just overload with uh method to choose it to compose the next operations um so we think uh there's my friend phillip in the chat so i feel it um so yeah basically you need to you know to to get your head around these methods and functional programming and yeah not everybody will like it and i think and we think there's a problem so in mutiny and i'm going to switch to code to show you to show you some some proper mutiny code we take a different approach um we take an approach of not being based on functional programming idioms although underneath is more or less the same but instead of saying fat map we say on item do something so we have these groups like one item which is to say what happens when i get an item on twitter to say what happens when i have a failure etc and by using these group and methods and more explicit methods that do capture what you're doing when you think in terms of i have a stream of asynchronous evidence and i want to compose them uh it's a bit more um it's something you can read so it's a bit more it's a bit more verbose but on the other hand um you know it's it's easier to uh to get your head around so i'm going to quickly switch to my ide and by the way if you have questions again just put them in the chat so that's my idea i'm going to i have a main method and i'm going to show you how to create a stream with mutiny so using mutiny's you create form that create form can be you know a bunch of things like you can have a reactive student compliant publisher you can have um you can create a multi from a fader from an emitter so an emitter is an object which allows you basically to bridge with anything so you have this object and you just push events whenever you want um so basically whenever you connect if you want to plug mutiny with something that's doing asynchronous io um you're likely going to use an emitter because it's it's what they should be using uh you can you can create some ticks if you want to have a timer and from items etc so if you and completion stage if you just want to have a one shot operation and a multi which is going to publish just one element so i'm going just for the sake of doing a demo i'm going to um to have a few uh a few items so i'm going to start from a collection and then i can do some stuff so basically the groups we have is are the the following ones so it's direct to to the evidence you may have uh in your multi so you can have an item you can have a failure you can have a constellation because you can cancel a subscription um what happens when you overflow when you have a completion blah blah blah so a bunch of things you can do and then you can see why i'm talking about um [Music] i'm talking about the uh navigability uh it's because when i do on item does something then it's i'm only showing methods that make sense if i want to react to an item which has been pushed down my my stream so for example i can say i want to transform this element to a string like um i'm going to do something like i like doing just hello world stuff then you can do another one item if you want to um you can skip elements like the first you can skip the um so you can have predicates stuff like that but i can say i want to skip the first two elements um what else can i do i can select if i want to like select where so it's not like sql but you know it's this kind of operators they can be nice so i'm going to change actually i'm going to create a range from 1 to um 20 i'm gonna select where n so m modulo 2 equals 0 then i'm going to transform like this keep the first two items and then because it's a stream i have to subscribe so i'm going to say subscribe with um the consumer to say and oh it's a string so i'm going to call it s i'm going to system out oops system out dot print line like this um plus n um now s okay if that's the case uh where i have an item i can have another one which is uh if i have a failure like um so if i have a throwable um i can do something like print stack trace like this which can be summarized as a lambda and then when i get when i get to the end of my stream i can do something like an action to say uh i'm done and because philip is here and i know philip loves emojis i'm going to have an emoji to say i've reached the end so i'm going to have this rocket like this is it crashing no i thought it was going to crash my id okay and that should be it so if i do this i'm going to select some of the elements in the range from 1 to 20 etc etc transform skip the first two and subscribe so if i run this it should work obviously yeah of course so it worked you can see that i skipped the first two elements the two first two are positive elements so that was two and four and then i went to six eight blah blah blah to the end and i have my stream so this is a multi a multi stream it supports back pressure um if you want to avoid having a producer which goes too fast for a consumer um the other thing is so if i had an error i could so in this case we're never gonna have an error but i can say on failure we try like with a backup so if you want to have an exponential backup that's what we implement uh you can have a backup at most indefinitely etc until so you know you can really express how you want to deal with failures um something else you can do is recover because sometimes you want to recover and you can say recover with completion to say okay i just dropped the error and i just complete normally that's you know one option you may have so that's multi um and then you have the friend of multi which is called uni uh and uni is a bit like is more it's the same api the the only difference is that uni is just for one shot operations so a uni it represents an operation like doing an http request that's a uni whereas with multi uh it's a stream of heavens like if you connect to an mqp stream q sorry a q a in mqp and you want to consume all the events that would be a multi uh and if you do a one shot operation like pretty most asynchronous stuff do you will use a unit and it's the the friend of um of multi all right so that so that was that was mutiny and again i'm just trying to convince you that this is actually readable um and it makes sense so i don't see any question if you have any question feel free to ask these questions um because otherwise i'm going to go to um a bit of vertex and things we're gonna discuss in the in the in the remainder of this uh of this session okay so don't be shy there are stupid questions anyway just ask any ask me anything which of course is ready to do this okay so teeny bra tinny break has a question how do you switch threads in mutiny uh it's a very good question so there are two two options basically um so one is you can have run subscription on um and you pass an executor to uh so instead of doing the subscription on the thread where you describe this pipeline like like here it's going to run on the main thread um with the run subscription on is going to be you know on some other executor um [Music] and the other one so that run subscription on and the other one is emit on if you want again to offset the emission of the events to another executor because basically the source you connect to is going to emit from a threat and then you you may take the evidence and emit them on another thread you you control so that's something you can do um which you know is like in the other programming libraries you may find reactive programming library sorry very good question so i think that was the the only the only question uh anyway just if you want to just drop a question on i will i will switch i will get back to you uh if need be um so now now let's switch to um the last the last slides because then it's going to be just demos demos and demo um so i'm going to talk to you about directive ecosystem we have um and why it matters so again uh it all starts because reactive is the mean and and the best way to go with resource efficiency so by design you're gonna be resource efficient if you do reactive at least if you do it properly so you so you will basically save money because you will consume less resources to deal with more traffic then in the middle we have vertex and this extremely mature and solid and robust ecosystem for um as a toolkit to to build end-to-end reactive applications and the last bits is all that we can pack now in a very modern reactive framework which is called particles based on on some of the nice technologies so just a few words about vertex and then i i will switch anyway to vortex so vertex is a project from the eclipse foundation if you didn't know it it's a toolkit it's extremely flexible and it's it's a low cerebral money uh toolkit like if you just want to expose um an http server on port 8280 and just respond with hello it's all you have to work to to write so you start with the main method there's no you know nothing to to override or there are no annotation of any kind not nothing like this you just create your vertex context and then you create your http server you say how you want to respond and you listen and that's it so vertex is great for that because it's what we call an opinionated because it's not a framework so you can just really choose you know whatever you want so of course and as i'm as shown in the book which of course i recommend because it's a great book what you can you can do more than just an http endpoint which is going to say hello you can do full uh modern distributed systems with with vertex so in the stack of vertex and interactive which which is another side of the community you have database clients you have messaging systems you have integration security clustering so all the nice things you need to build your applications um even stuff like open api so if you have an open api specification and you want to um to bind to it you can do it so really it's a nice and complete ecosystem um so among these new bits so again this is not covered by the book because this is more recent than because it basically came available when once while we were finishing the book um so in the book what what i was discussing is the great sql clients we have uh it's invertex so we have create um reactive drivers uh for popular databases and there are more databases that will be coming for sure i won't i won't you know give any spoiler but there are although the database is coming um so we have an excellent support for postgres mysql but postgres is really great db2 and ssql so yeah all the big the big names you may want um we had them covered with drivers we we implemented so it's not jdbc uh because jdbc is based on uh blocking io paradigms so we you know we took the protocols of each of these databases and we recreated drivers asynchronous drivers that are very efficient so this is covered in the book but what you don't have on top is hybrid and mutiny so hibernates now exist with ibono interactive so it's hibernate is this this familiar model where you have objects you want to map you map to your database that's object-relational mapper and then you can reach to hibernate reactive with mutiny and completion stage but you should only be doing it with mutiny i guess or at least that's my advice because i'm also working on mutually so um clearly um the nice thing with this is that you can have an end-to-end application which goes from which is asynchronous where you get the request asynchronous in the middle where you do your database stuff and then you reach out to database so you can really build something which is um completely reactive and it's great and the last bit is quarkus um so i'm not going to um spend too much time on carcass for c because uh you've probably been hearing about quakers which is our framework and which is using vertex in so many places um we say to start to write java applications but the people who work on reactive say it's a stack to write reactive application and it's really great because you have a nice developer experience uh and yeah it's it's really a modern framework which is nice to use so again if you like the more toolkit optional vertex you have vertex which is great and sometimes in some teams in some contexts you may prefer a framework we have you covered and it's the same technology so you can reuse your vertex knowledge and qualcus and benefit from the uh from the environment um so i have three demos for you uh three more demos and actually it's not three it's full because i will get back to um just vertex and mutiny uh but yeah so it's yeah it's four i shouldn't have reused this slide um so we start with vertex i will show you the reactive sql client um so it's going to be um pure sql interactions like in your service you prepare your query you do the query to database and it's you know there is no object mapping of any kind you just pure sql which is great as well um and especially in the book i advocate for you know using pure sql sometimes because it's simple uh and it's it's not as hard as you think um especially if you know what you're doing with the relational model you know it's it's pretty nice then i will show you how to integrate hybrid interactive with vertex so still take advantage of the greater active sql clients we have but we use that familiar object relation objection relational model which may be more convenient in some cases and then i will show you how how you can use it in quarkus uh and basically what i will show you in the middle it's what you have in quercus except that the inquiries it's all integrated for you and so you don't have to do the glue between all the systems you just pre-package for you um so that's all the slide that i had um and i see that you're still here and sit around so it's great it's always more encouraging so let's get back to this [Music] so i'm going to kill this goodbye michini and i'm going to show you a vertex application but which is using the um the mutiny bindings so [Music] the mutiny bindings we maintain them separately like they are made for vertex but they are not part of the stack of vortex because we still need a different release train uh really space right now so they are developed separately in small rail reactive right now and just like in um in the stack for the bindings of eric java for example or the cooking coordinates we use code generation to uh to generate the bindings for all the well not all the modules but the main modules you you may want to use in vortex so the only difference it's not an iodine vertex dependency it's an ios monorail reactive dependency and instead of being say vertex web is going to be small right eugenie and you you can see yeah again you have all these modules and my completion isn't complete because i have a kafka i have you know all the stuff you may want to have so again let's create a basic vortex application um but now with mutiny now so to do it i'm just going to take my class um i'm going to say i'm a this is a vertical so the i'm too tired and it's friday so if you don't if you haven't read the book or you don't know vertex um the vertical is the unit of deployment so it's what you deploy in vortex to process uh asynchronous servants it's like i i would say it's a the asynchronous component you want to deploy it's not in a gb it's a nice let's say it's an asynchronous cgb and i'm sure i will make friends by by doing so so i have my vertex context so i'm going to create it i'm going to deploy a vertical like i deploy main or i use um i mean i'm going to give the supplier because it's a bit oops and he's not happy why i don't know okay um like this okay so i'm going to be differently because now okay so i'm just going to do main like this okay so intelligence is happy so that's my vertical that's what i'm going to deploy and then i have a a fairly simple programming model and because i'm using the mutiny bindings um the start method is it's called async start and it's returns a unique so the uni um oh thank you tiny big uh i don't know if you're julia or anybody else but like yeah you need deployment options if you pass a supplier so it should be something like main new correct um and new deployment options oops deployment options and then okay we pass the supplier and maybe i can say something like i want to um set instances i want two instances like i'm going to deploy this this vertical twice for example um so let's start i have vertex um and i can do something like a periodic timer like every three seconds i'm going to do something uh and this idea like this i think i need a logger because logging is it's important if i want to show you the what happens we with with red threads um so i'm going to do log dot info tick like this um and then i can return vertex dot create http server that request so that's my request so i'm gonna request that response that end and forget to say i don't want because it's an asynchronous operation so i just want to end and say hello like this and replace oops and listen because i want to listen on on the port and replace with void because i don't care about the http server object so by doing so by doing so um i should have a service which is running so if i run the service let's just see what happens so i will have four instances of oops what went wrong so okay i'm gonna get back to something that i know works because the demo guides are not with me today uh oh yeah i know why because i need to subscribe because it's mutiny so it's not it's not the same so i need to subscribe with the consumer to say um okay and i do nothing because i don't care and it should be working this time okay so you can see that we have every three seconds we have a tick uh it's running on a vertex event thread so a thread which is tied to the event loop uh which you're running uh and if i do an http request then it should tell me hello like this i do a q request and if i look into my logs you can see that i'm going to stop it you can see that it's all running on the same thread to show you this i should have put a log here to show you happens with um the threading when i process the http request so request um nothing too fancy to be honest so i'm going to do this make a request a few requests and you can see that you know it's all been working on the centroid like this okay so that's vertex but you know with new gene apis so so that's that's interesting um we're going to switch to the um mutiny sql client um so how do how do i talk to database with vertex and i'm going to talk to um this windows great so i'm going to talk to um a postgres database so just to make sure you understand what's going on um so i have a main method here which is more or less the same so i create a vertex object um i deploy and i pass you know references to my database um so you can connect to it the only thing is i'm using test containers here because for the the development purposes uh it's nice to have you know a container started for you so i could use docker on the side like docker compose to start the uh postgres database um but here in in this case i just want to to do it for my code in the case of a demo it's really great so i'm just using postgres um test container sorry to start my database and then you know when i start my application it will start with um a database for me just on the side um so i you know you can try this kind of thing um and i will talk to you about how it works um in caucus inquiries you have something like this which is very new which is called the uh dev services so you can see that you know it's been more or less most of the bug of the time was to start the uh the container and then the vertex itself is stopped really really fast so if i show you this um oops so if i show you this um what this service is doing you have an api you can have products um like i can post like a baguette and i say the price is 90 cents which is not the correct price anyway but i know all the french people will hate me for for this but you know it's an api and basically these products they are stored into uh into a database so how it works i'm going to stop it so this is with vertex pure vertex and pure secret client um so how it works so when you start so you need this this thing so pg pool it's your pool of connections to postgres uh because i'm using the vertex postgres sql driver so to connect i need you know a connection object um to tell me what's the host the port the name of the database the user the password which is a nice password anyway um so i have my pool and i get you know i create my pool like this and then the the rest of the code here just the um http api using protex web so products maps to this this method fetching a project by id this method is a water basically all the products is this method etc and then you start the http server so it gets more interesting when you get to here like this method these products um so what you want to do here is list all the products in the database so it's a very classical select style from products query so with the sql drivers over or vertex you do it like this so you have your pool of connection um you can do stuff like queries pre-broad queries you know transactions if you want to etc so you do a query you execute it because it does nothing to pass when you have an item which is a rosette so a bunch of rows from database um i construct a json array with all the responses and the responses are just the rows in json there are ways to make it simpler because in rosette there's a now it's another uh edition of vertex sorry but yeah anyway we have shortcuts if you want to do it more quickly uh i have also on fader to say to recover and just give an empty um array if i have an error like my databases down so we just respond with an empty array etc if i go back to another method so create a product is when i want to [Music] insert into my database so what i'm doing i'm extracting things from the http request um in this try catch i'm doing some extraction and validation like i want to check if i have all my keys and if they're correct and you know there's no issue extracting if ever it's the case i just returned with the uni with the failure because i need to return a uni there um and then to do the insert i have a prepared query i insert with some placeholders dollar one dollar two um to pass the name and the price i have a total which are going to be my values for dollar one dollar two um and then you know you just have one item on fader and you do your stuff so this is a very simple way to deal with sql databases where you um where you do sql and again if you do sql by hand it's it's not bad it's not dirty it's not it's it's very simple actually because you can do um a lot of things with plain sequel if you like it um i'm going to switch now to the example so it's going to be the same the same api deal with vertex except that now i'm using hibernator active so i'm changing the programming model a little bit um and i'm going to show you what you need to to make it work um so i could run the product the the service but it's going to be exactly the same thing the same endpoint some http queries you get your stuff in the database etc instead i'm going to show you something which is more familiar to many people and that's an entity for hibernate so instead of manipulating pure json and row sets in my database i'm going to map to have an entity which is a product and this is going to be mapped to a table in my database by hibernate for me so what you have here is a product with your primary key which is your id a name which is unique so again um the column here which is the price which cannot be known etc so this is you know traditional hibernate code you may be you may you may be doing this this is a very typical entity with some getters etc etc um what's important is you know this like your your your very classical so to make it work um when you get to your object here first thing you need is a session factory so that's your session factory from ibernet and you have different variants so this one is mutiny dot session factory and there is completion stage dot session factory it depends which asynchronous api you want to use but that's your you know entity mana well entity management session factory um so what i do when i start when i start the um the service um so i'm going to create this um so i just need to tweak some of the configuration of ibernet we'll get back to it um so don't be fooled with this jdbc for the persistence url is just to reuse the configuration that exists in hibernate but when you do this and we have reactive as we will see it's not going to be jdbc it's going to be the vertex sql driver of the postgres so i'm just doing this because i need to override the configuration because i'm using a test container or a database in this container then i just create my my persistence you need call it call it the way you want um as a session factory and then i'm just ready to go so this is again the same code for the http api nothing nothing really fancy and then um if i want to lead the products so whereas in the beginning well in the sql version we had to do the sql query outsells in this case uh we go through the session and with the session we create a query which is from product to give me a product of class and we get the list and that's it so we get the uni off list of products because fetching from a database it's a one chart operation anyway it's not a stream right databases don't stream it's something you should remember um so we get to uni with the list other products and here i'm not doing sql i'm just using um ibernet which you know same thing here if i want to store into database um so i'm using the session i'm persisting the product which i just built here so i have my bin i create my bin i fill uh i fill the values i persist then chain it's a shortcut for on item dot transform to uni uh it's it's a it's a mutiny thing to chain asynchronous operations um in a nice fashion so you flush so to your database and then uh because you want to respond with something you just put back the product which is going to be mapped then to json and same thing if you want to find something by id you have session.find etc so you have a bunch of queries sorry methods in ibernet but the cool thing is you are using mutiny to deal with the asynchronous nature of the operations the last thing i need to show you here is how you configure it so i hope it zooms i'm not sure yeah it zooms right great so you still need this processor.xml file which is here so this is this this is a very typical um persistence xml file you know nothing extraordinary uh we just say that we are going to use the reactive reactive processions provider of ibrunite so it's hibernate reactive and then in the configuration you know nothing nothing else you just you know you say if you won't have logging or sql queries you get the password to the database connection parameters etc so that is plain ibernet and you can use it in vertex applications so again you can have pure sql you can have iburn attractive if you want to um and in the a great addition in vertex 4 as well is that in the mutiny bindings and it's because in vertex web we have some 90s we have some niceties so right now you can return the asynchronous operation rather than having to subscribe to the uni uh so if you it's because we use in the in the vertex router we use respond uh so it's a new thing it's not covered in the book i didn't talk about it because it's fairly new in the book i showed you android like it's what is being called when i want to deal with this endpoint um and in the case of vertex 4 now we have respond which basically in the case of mutiny is going to subscribe for you so you provide a uni like in the method you have here you provide a uni and when you have your http request is going to be subscribed for you and by subscribing it's going to trigger the whole the whole operation of talking to your database and you know giving the response so it's pretty pretty pretty nice um what you have in in this service is more or less what comes packaged for you um in um [Music] in quercus but i will show you some other goodies in quakers i see that i'm still going to run this service because i just want to show you that it works so again i'm starting postgres it's really the thing which is going to take time like starting a container it's not a cheap operation and then you have ibornet which is kicking in in the beginning um it's been creating the table for me again it's a nice kind of experience vertex itself is fast to start and if i do http like this so i put a baguette in my database and i get all the products you know you can see it works again so that's ibernet and mutiny and it's pretty nice and the last thing that i wanted to show you is basically this code but in caucus like in corkus is going to be what we did here is more or less what caucus is doing with all the bits like um the http endpoint written in rest is directed as we will see uh talking to the database using the um um hibernator active et cetera so i'm going to start with this um so that's my quarkx application like i'm going to run it um so you can see so so when you do maven like this quarkx dev um it's the maven plugin for qualcus and the nice thing is is it manages portrait for you uh automatic critter and in this case it's also starting using test containers to start a database for me um there's a configuration to do that but in development mode um if you don't want to start a database on the site by yourself you can just let quarkus do it for you and you know everything is managed for you so that's that's pretty pretty nice um if i do just a few requests just to make sure it works uh products i have nothing each i put a baguette and i get all the products so yeah it works which is always is always good so in corkus um so if you want to you can you can use vertex for plain vertex like a vertex context if you want to uh and you know manage manage http endpoints with vertex but you you may you might as well use rest easy reactive so it's rest easy that you know that familiar programming model which is based on an annotation so it's not a router like in vertex which is great as well i like it but for stz it's another annotation based model and you define your endpoints like um if you want to get all the products it's a multiple products um you do add get etc etc so that's you know this programming model um i don't need this actually the path forum in rest is he i don't need it because [Music] he's going to figure out by the name of the parameter on the query so i don't need it and because there is hot reload it should be done for me automatically so i just restart i don't need to restart i just let cork do its thing and it works um so that's rest is erected but under under the hood it's using vertex so you still have the same you see the power power vertex in it and then the only thing that i did a bit differently you know in this case uh is using some so you can use hibernate entities just like we did in the other example um but there is something in carcass which is called panache i know it's a french name [Music] and you can define your entities but using the active record pattern so if you've done lots of ruby and rails you know this pattern but you may know it from other technologies as well so the idea is that you define your entity like this you don't have to define all the getters and setters and stuff like that you just say i have a name i have a price you could also say it's a primary if you wanted to and then you have factory methods like all to do the stuff for you um find by name so you do find you say my query is going to be on the name and you pass the name and you give the first result so with financial it's even more compact you write some more compact code and you get tons of nice helper methods um for you and it's also using mutiny so really all i have in this example is a rest is the endpoint um a punish entity and you know it's all assembled into uh into a framework uh which is doing more or less again what we did manually with with vertex so again i think it's it's interesting because especially if you're a cordless user and you want to understand reactive um using the vertex bits it gives you an idea of exactly what's happening in this magic that you have in a framework because a framework is always a bit of magic and things that you know work magically together so it's interesting to understand it uh and i think that's it from my side um i'm going to switch back to you can see my face uh and the book um so before i take a few questions and remarks on anything um just want to thank you again for having joined this session um you can have the book so i don't know so this way it is so the book is here right you have a code if you want for 40 off on the book or any other book at manning and i will be would take a few minutes um and if you have any question please space in the chat and i would be happy to answer and i hope it was useful the question which is how do you tell mutiny to use the vertex threads [Music] so if you're basically it depends like if you're doing vertex plus mutiny like with the mutiny apis by default there is nothing to do because you know in vertex you will say i want to respond to this request and compose these operations and by default you will be bound to the vertex event loop thread uh more technically um you will be bound to the uh vertex context which attaches to a thread an event thread so there is nothing to do if you want to be on the project's uh thread with muji there's nothing specific to do so so by default dispatching will be uh will be done for you um and again i'm going to temporarily give you my screen again because if you so that's the uh quarkus example um so it so again with vertex it's you know it is done for you and in the case of quarkus if you do some reactive you can see that you know all the operations they happen on vertex and event threads meaning that you're doing a synchronous right so when you get a rest easy um request it's on on the vertex eventually thread and then when you talk through iburnet to your database uh it's it's also something which is happening on the vertex event right so there is no no worry like you may worry but you don't need to worry this uh in most cases like you won't you don't need to worry there may be cases if you do some more advanced stuff or you may have other threads but again you can just say i want to execute back on the vertex thread and you know there's a section in my book about how you bridge multiple threading models together and make sure you respect the vertex threading model so this applies to projects it applies also to caucus when you do reactive uh thank you gaspar 8080 was okay doesn't have a question but happy so thank you um there's a question before from zeitgeist i hope your name is right so would this example in quark is built as native binary uh yeah it will it would work as a native binary uh i'm going to show you um so let's hope it works um so i'm using sdk so i recently switched to sdk man so it's this java i guess like this no i don't want to upgrade in the middle of doing this um so i'm still not familiar with this to be honest so i should be using ground so i will be using guava um you can use mandrel which is our distribution as well but you know so sdk views is it like this yeah so i know sdk man i'm just checking i have native image installed just to make sure it works okay okay so i'm going to clean package and be native i don't remember if it's p native or g native but we will see so this should produce um [Music] so why is running test i mean i don't care about test okay uh i'm going to skip test because we've usually test it's going to start a container and all stuff so skip test so cyclonic you will have your answer in a few seconds or maybe a minute because it needs to compare to native okay so it's comparing to native um with all the stuff carcass is doing and he's got it's also doing lots of stuff at build time so when you start the you only start when you start the service you don't need to do anything um so what is compiling um tiny big is is asking are these examples available in a repo somewhere yes so if you follow me on twitter and i'm this person and this person just i'm gonna zoom so you can all see i'm this person on twitter and you can see my face in big you know super pro so just follow me um i will post the um i will post the links to the um to the repositories they are they are already on my github but you know i will just write you on to something and just put them down um so yeah it's compiling like you can see it's compiling and it's taking some time um so the binary it will compile it will work the thing is i need to start a database on the side and then it should be it so yeah again it's taking some time to compile i just want to check if i can um i just want to run the database on the site um so i think um i have a docker compose yeah so this one should be should be okay uh doctor composer i think this one has the correct you know password and stuff so it's still combining like six gigs of ram to compile and it's not finished but i should get a native image so native image um it's interesting but it's not the it's not the primary feature you have in quercus it's you know it's it i mean it's not because of the carcass that you have to convert to native just in pure jvm it's already pretty interesting and very efficient in terms of memory usage so just checking is it finished so apparently i have a postgres which is starting [Music] yeah so it should be working uh and by at the same time we have our native image so the name is catalog service runner blah blah blah it's not really great um i mean you can override but when you deploy you can get um i'm just going to show you the size so it's a 60 meg thing and if i run boom okay you have your service um it started in a snap and if i do my queries just to show you that it started and it works but things we're compiling in uh in caucus they tend to work um so what's the error um okay i'm not i'm using mr bin so it's not the correct password um so let me fix it i don't have to recombine anything i just need to um just need to fix my darker compose like this like this [Music] should be something like so html so i hope it doesn't break you is it user like this um okay okay anyway i don't remember so i'm not i'm not going to break it again but still the thing is it worked kind of it kind of worked um yeah the compilation times yeah it can be improved but you know um the i i mean it's something you do once in a while when you when you deploy so but yeah the people are working so yeah um yeah you ziglanite you can trust me it works uh it's connected through you know it you can see that the error is just that you know i'm using the one user and the wrong password which makes total sense but we have an executable and it does work um thank you lcao thank you others um i think we will have one last question if you have one last question anybody ask me anything any question if there are two questions i will ask them two questions if there is one question i will ask someone and if there are no questions we'll close at some point okay so i think we are going to stop um so i hope you all enjoyed um this stream i hope you learned a few things um do you notice that you get back to me over twitter or other places um if you want to i can do uh so caspar 8080 will you do this more fun in the future yeah sometimes i i i try to think i should do some twitch uh because it's fun it's it's a format which is fun so yeah definitely i can do it again at manning um i may also do some twitch session on my own twitch it's just that i need to take time but just you know ping me on twitter and say we want you to do some twitch sessions i will and i will try to do some some stuff for you so thank you everyone i'm going to close the stream in one minute i guess so have a nice day uh you know it's all dark here in new york it's all dark here so i'm gonna get a beer i guess or something and have a nice evening everybody see you
Info
Channel: Manning Publications
Views: 1,157
Rating: undefined out of 5
Keywords: Asynchronous and Reactive Java, The Vert.x framework, Kotlin, Scala, asynchronous communication, data persistence, java, spring boot, reactive programming, what is reactive programming, reactive programming tutorial, reactive programming example, vert.x, Reactive isn't Complicated, is reactive complicated?, why is reactive complicated?, reactive is ot complicated, reactive is easy with vert.x, reactive programming with vert.x, reactive programming with mutiny apis, julien ponge
Id: 3tdU5WRvuuo
Channel Id: undefined
Length: 68min 26sec (4106 seconds)
Published: Thu Jun 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.