Deepdive into Reactive Spring with Coroutines and Kotlin Flow by Sébastien Deleuze

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay welcome everybody i'm sebastian dollars and the spring for mocha meter and I'm also responsible for the court in support of the value spring project and today we are going to do a deep dive into reactive spring with school routines and cutting flow so we are going to see a wide range of topic spring boot-cut liens reports what are kuru teens what are the new part of the reactive spring stack like a 2d BC for reactive SQL and a circuit so we are going to see all this topic in details we are going to start by your presentation so the first parts one hour or one hour and a half will be a presentation about why cotton is interesting to build an application on the JVM especially with spring woods we will see a status of the quadlings report in spring because in spring farm work 5.2 and spring good to the two we have provided values new features so I would like to share that with you we are going to talk about reactive in general air to the BCA circuit and what our core routines and what is the core regions officials reports that is coming with spring we will have a big break because I know that's very yeah that's a lot of time and in the part two we are going to build an application with all this thing with value step so we are going to start building an application with spring wave flags and A to D BC with the cout routines API we are going to have a look to the route our DSL and the functional API as well we will introduce a circuit supports we will develop the front end not with JavaScript ah typescript but with curtain GS and that will be for us the opportunity to have a look to the curtain multi-platform support so we will share some codes between back-end and front-end and we will finish by an experimental project I have launched last year which is spring foo which contain Khufu DSL which is basically explicit configuration for spring boots via occurred in yourself so part one presentation taught to developing such application and I would like to start by asking why should we use cotton to develop an application because obviously a lot of developers the majority of developers are using Java a spring boot to develop applications but I think cotton which is currently mainly used on Android side could bring a lot of added value for server-side developers as well who has a rigid develop ratio and please if you are already developed an application with Scotland ok alfe of the room I guess so so this is my reasons maybe use could be different and maybe you will agree or disagree with what I say but my first reason is to improve the signal-to-noise ratio of your code our code is to express our IDs to implement our algorithm we have to maintain that and being able to write concise code that is written quickly and is readable and understandable easily is super importance and I think in the while working with visualize sometimes we we forget about that so I really think improving the signal-to-noise ratio is a big reason to use cotton the second reason is safety and especially near safety so in Java world we have this issue with nurse safety which is usually called to be billion dollar mistake I think it's much more but let's call it the billion dollar mistake because nil is not something which is specified explicitly in the right type system ok I really think null is not an issue by itself but when you have this thing which is implicit you have issues like you have in dynamic languages its unspecified and that can produce a new pointer exception at runtime in Kirkland we still have new and we leverage that by dealing with no safety explicitly on the type system so when you have a type you specify if it's new labor or not you still have to deal with new safety but at compile time so if you forget to deal with new safety your compiler will raise an ero instead of waiting production to raise an importer exception at the worst point this capability is also very important and Kathleen with this DSL hello basically to you to discover various api's via autocomplete and I think that's pretty important too to be able to discover the new API is that are coming with a new version of your favorite library for example and the DSL it's it's still code so you have autocomplete and it's valid cutting code but at the same time it look like document so it's like a good trade-off between codes and documents with kimmel validation basically and everything in your IDE a pleasure I think that's a very important and that maybe the most important reason for me to walk on cut in I mean nobody asked me to introduce cut in support in spring I just like this language I think that's a good fit with server-side development and I have lot of pleasure expressing my ideas with that language and I think before working with Kirkland I mean I was talking with people liking Ruby or thinking like I think languages like that and the were super passionate about the language and I like Java but honestly I have much more pleasure developing with Curtin and we spend so many time developing code I think that's a pretty important thing the Android community has switched to from Java to cut clean in a very short amount of time I think nowadays majority of unreal applications are developed in Kirkland Android is now cut in first so that means that Google is developing features for code in first and then it's available for for for Java on server sides we are still Java first and we will remain it I think I don't think cut clean at least short term or middle term will beat Java but I think the fact that the huge number of Android developers I coming learning Kathleen will have an impact on server side as well and in the JVM community we add basically Java and all the other language alternative language groovy Scala code in etc and I think now we are in an ecosystem where we have Java first cut in second and then the other languages and that's pretty new because yeah that never happened the Meucci platform aspect is important I think it is still the early days of that but I really think there is a lot of values so go clean as first class report for the JVM but it has also support for other platform so on the way it is a kind it's also just gvm but it's also different and maybe in the future it will be even more different than regular JVM we do in server side Kathleen can also be used to develop front-end application so we are going to see later that we can develop front-end application with Kathleen I am NOT here to sell anything so honestly developing a front-end with Curtin it's still the early days there is a lot of things to improve and I keep providing feedback to JetBrains and the country team pointing because I'm also a front-end developer so I'm not just a server-side guy I like JavaScript I even created a small JavaScript framework a lot of time a long time ago that's I really think cutting and that script for example as some common point I really think we could have a lot of added value using the same language for values targets sharing some code sharing some validation logic so even if that's maybe not 100% usable nowadays if if I had to do a front-end application maybe I would choose typescript today but it begins to be more and more usable and when with forms like webassembly on zarada which is a kind of bytecode for the web I think it could be really interesting to use cut-in for front-end as well there is also native support it's mainly created for iOS support don't expect to do I mean you can create some kind of server side application but I think grant VM with a coach in JVM is more suitable for that kind of use case but still you have a platform which allowed to develop application in gotten and compile it to native via LLVM toolchain so spring love cotton and I'm going to explain how much so we love cotton as much as we translated all the spring from work reference documentation from Java to katene so basically what I did was to take every single code sample in the spring from reference documentation and I translated it to Kathleen when there is some specific DSL or extension available for the cotton code it is used so it's not just an automated translation it's also a way to provide you guidelines about hi - how to write idiomatic codes for you spring good application with Kathleen so if you go to the Spring Framework 5.2 documentation you will see an additional tab for every code sample you can switch from Java to Kathleen when you should when you switch to Kathleen the switch is active for every code sample available and if you are going away and coming back after that to the documentation it's a persistent so doing that was pretty extensive important efforts so iodine is the time to do it for spring farm work okay that other spring project will also get their documentation translated to Kathleen so spring boots spring good to that free next year will it's documentation translated to Catelyn first bring that spring that is composed by 17 projects so it's a lot of work so I don't promise that we will translate everything and I'm also not the spring that I predicted so I can't promise you that but we have discussed with Mack Parrish and the spring data team and we will try to get some part of spring that other conscient translated my hope is that we would get spring data commands bring data GPA and spring data to DBC documentation constitute to Kirtland next year no promise but that's our call and spring security documentation will be translated to cut in I will talk again about spring security just after that so for spring boots a new feature I mean we we did that change a few months ago but when you are going to start that spring that i/o to create a new spring good project with Kathleen and if you select grade L we will automatically use the grader cut in DSL so a few months in a few years ago grader announced that in addition to the groovy DSL which is used to write you a builder grade oh they will provide also a way to write your grader build with kirtland instead of groovy the advantages are that in addition to just changing the language they did a huge amount of refactoring to make everything more static statically typed because originally the groovy DSL is I mean you can do static type with groovy but the grader DSL is developed in a very dynamic fashion so they had a huge amount of work to make everything more statically typed and the advantage for you is to have a better autocompletes grader is a very powerful tool but I don't know how you walk with Gradle but myself with the groovy DSL I just take some example on internet and modify them and awfully that works with cutting DSL I am able to use autocompletes I'm lazy so I like to use it a complete check everything which is available and just write my code like that so it brings some kind of structure to grade our bid file and I really think that's a very good thing and I think that also triggers some improvement on the groovy DSL side so that's that interesting this DSL has some drawback again I'm not here to say everything is perfect so zoom biggest drawback of the Gradle cut in DSL is that currently it's a little bit slow in the IDE if you are using it and you are trying to able to complete it's much slower than the I mean in groovy I don't really use do to complete but it's slower than that for example using autocomplete in regular code in file there are the contain the greater team is aware of the issue they are working hard to improve that and in the next version of curtain 1.3 dot 60 the performance of the autocomplete will be much faster I think twice faster so they are walking out on the issue but yeah if you use autocomplete and if you change your Gradle build file you will see that there is a lot of CPU cycle recombining everything and you have to complete it slow hopefully it will get better and better we don't provide a choice so it's by default if you use Gradle and Kotlin the grader cut in DSL will will be used by default if you are creating a Java project and you want to use this grader cut in DSL it's not possible yet feel free to ask that on the issue tracker but for now we we don't want to provide too much too much checkbox so we provide this opinionated choice if you use Gradle and Kathleen we will use this DSL otherwise we will just use the groovy DSL configuration properties that was that was painful before we spring boo to that one when you were writing at configuration properties in code clean if you want to write this in a kind of idiomatic way you you want to use with cotton immutable I mean that a class is with immutable properties okay but it's not possible because spring would come from the Java world and in Java world immutable data structure are not first-class citizen and you had to use this kind of lady need VAR construct which is not super dramatic and I was crying every time I was writing a spring good application in Catalan so after talking a lot with the spring good team they provided this new feature in spring boot to the - which is also available in Java so whispering boot to the - you can create imitable configuration property classes and it's report data classes with imitable properties you have to use this add constructor binding for various technical reasons I had a lot of discussion with the spring boot team and it was not possible to support it without this a constructor binding maybe in the future version with caffeine we we will be able to say ok if it's cut in that a class with immutable properties then at constructor binding will be implied but for now you are to specify explicitly to be able to use this kind of structure and the good thing is that we can just use cotton idiomatic code whispering good to read to start the spring data you also help you to share a cotton project because basically you have a new share button that allow you to share crystal crystallized configuration so you go to start a spring that IO you select grader Kathleen every kind of dependencies and you can basically get an customized URL that will bring you or other people to this customized start the spring data your configuration you will have also form which is filled with what you you selected there is also more dia cells so we try to be careful and to not create too many DSL because with cutting materials like ESL's or extensions it's tempting to create extensions and DSL for everything so we try to limit ourselves to where that really makes sense and spring security is a very good use case because spring security has ESL to configure the security in Java which is pretty extensive it was also created before lambdas so [Music] it's clear that with cutting capabilities we can express the same thing in a more concise and readable way and I'm super happy that this spring security DSL is coming from spring security teams so I have nothing to do with that and Ria's stain from spring security team which is managed by Rob winch as created a dedicated DSL which allowed to configure everything in spring security with a cut-in DSL so this is not a community project this is really first class report for now it live in github comm slash spring project experimental we will mature it this year until next year and next year it should be integrated directly we sprint security 5.3 ok so for now I mean I don't remember if the first release has been published but it's about to be available so it will be available in experimental mode you can use it but we will maybe change a little bit the API refine so feel free to try it and provide feedbacks and it's likely it will be integrated in spring security 5.3 and remember just previously I talked about the reference documentation so spring security reference documentation will direct the show in its code clean-cut samples how to configure it using this DSL this is a little bit out of topic given the fact that today we are going to talk about reactive and ku routines but I would like to highlight that because the GSL is very similar to the kuru teen one and also this has been asked by a lot of people so I would like to take just a few minute to talk about the spring MVC DSL and the functional API that's our very very spring from our father too so you have with spring far Mach 5 you add two ways to write your control to do web endpoints you can use add controller and add request mapping this is a usual model everybody knows but it's is also possible to use the Catalan DSL it was previously available only for web flux and the idea is that we spring farmwork 5.2 is available for web MVC as well for spring MVC basically so you can use it with Tomcat and servlet underneath so you have basically you create your endpoints by creating under-under function that takes as input parameter server requests and returns several response in terms of implementation you you have value static methods available in server response that allow you to specify the status codes you can provide the body you can specify any kind of ITER's okay via of just this kind of API and you will plug this under into a hotel which will specify the mapping usually we are using collaboration seas like here with hello to make the link between the hood and and the Unruh you can then expose the route or to spring boot so to expose the route or you just have to publish a hotel function bin which will be automatically used by spring boots and your endpoint will be available if we are writing a more realistic example what you will do is basically creating underclass annotated with add components you will inject for example repository or service in Kathleen we really favored a constructor base injection I mean in in Java we try to favor it but a lot of people still are using other kind of injection in Kirkland it's almost mandatory because the language is really designed for rittany properties to use this kind of private Val repository and the answer type and remember that by default properties in codeine are public so here I'm specifying private because your there is no no sense to expose this repository in the public API if we are having a look to a more realistic under you can more realistic hotel you can see that here I'm specifying that for every reason media type slash person slash ID and slash person we will will be forwarded to the related hotels you can write any kind of request predicate you can combine them you can nest them you can specify condition on leaders and you can even write your own request predicate so it's much more flexible than the annotation programming model and you can buy right your your three of routes like that and it's much more than syntactic sugar because you can create routes dynamically obviously you need to take care of caching and thing like that but where annotation are basically statically defined with the hotel you can create routes dynamically for example when you start the application where even when you receive a request so if you are building some kind of CMS or e-commerce software where the roots are defined dynamically in your database it's possible to under that with these kind of roots where with annotation you are basically in big trouble I provide another state to stable because there is a lot of features so to make it clear what is reported we spring good to the to with reports the bins the answers web first who taught ESL the core routine water DSL that we are going to see later there is this new web MVC who taught ESL and we ever saw a mock MVC DSL which has been contributed by the community and the spring security DSL is innings in experimental mode and all this DSL will be supported in a projection ready fashion next year so we are now going to talk about why reactive so with springtime at 5:00 we introduced a new reactive stack in parallel of spring MVC tomcat which is more blocking style to provide better scalability and efficiency typically the spring MVC and tomcat stack is using a lot of threads and with web flags based on the native runtime we are more scalable and more efficient we try to break this HTTP exchange equal thread coupling by being able to process a lot of HTTP exchanges in parallel with just a few threads and that's that's possible with less memory consumption it's also possible with this kind of stack to be neutral to latency if you are building micro services or if you are just I mean if you have to do some processing that inverse on some latency like cooling remotes endpoints that you don't control which will be super slow because I don't know you have some customers and some partner that expose a very slow rest endpoint that will basically make your application network latency and I mean the fact that the remote endpoint with decorative time to answer will not impact the scalability of the conception of who owned service there is also back pressure which is flow control to avoid other overwhelming the consumer so the idea with back pressure is that you you have you deal with the demand so instead of being overwhelmed by when you are developing a slow slow consumer and you have a very fast producer basically what's usually oql with the without back pressure is that you have some kind of buffer that grow grow grow because you can't process all the data and at some points you a service crash because it does not have any memory available with the with back pressure with back pressure you will be it will be possible to limit the amount of in-flight data and if you don't ask some data you won't receive them so you won't have this both growing buffer issue and that provide a better programming model for concurrency and with the decorative approach you have in API like flex for example it's it's much better for for dealing with concurrency and if you deal with streaming like with server sent events or if you want to stream data between two micro services that's also very good use case but that's not a free lunch and using reactive stack requires to change from imperative to declarative and using a dedicated stack and I won't say I mean imperative is great declarative is great it's it depends of the use case it's not that imperative is bad I think for some use case imperative code is great for other use cases decorative is great and we are going to talk a lot of about that in the upcoming State spring reactive stack is based on reactor which is a reactive streams implementation so in spring formal spring security spring boots and spring data every reactive feature is based on this project light or foundation and I'm now going to talk about air to DBC because when we have introduced this reactive stack we have provided some support for persistence in spring data but only phone no Sakura solution so persistence reactive persistence super was available for MongoDB reddy's Cassandra but only for new SQL and people were asking what should I do if I use SQL so obviously you can use a regular gdb C or GPA API into reactive application but you need you need to take care about using a dedicated schedulers and basically creating a dedicated thread pool to execute all the best on staff and that's that's not the way we want to push people to deal with that - to the assistance with our reactive stack so we have worked rotten and to add to DB C which is basically reactive SQL so after the BC directive spi for SQL drivers and it embraced reactive types and pattern so in earth with the BC API you will see it will use a lot publishers it's not blocking all the way to the database it's documenting it have to document it specification it provide various drivers and we are going to see what drivers are supported it shrinks as the driver SPI and that's important because gtb/c try to basically JDBC is used useful for database driver and it also should be usable for end users actually BC don't try to do that you really focus on a very narrow low-level API that should be implemented by drivers and then it it let open the choice form on more human API it only depends on Java 8 and reactive stream so there is no dependency on reactor for example in the - DBC SPI in implementation for drivers that depend on like obviously it depends the dependent reactor but G SPI is pure Java 8 and reactive streams and since Java 9 include reactive stream CPI we can say that it's basically conceptually just Java 9 API is used in the SPI so what drivers are available in this reactive SQL ward the first party drivers are PostgreSQL Microsoft SQL Server and h2 database and developed by the community there is my sequel so we have two - driver for my sequel ASAP Anna and Google Cloud spanner and we have values database under that are contain key contacting us for a 2d BCT report so this list is going to grow in terms of clients by clients I mean how do you how do you use as a developer f2 DBC so the one that we are going to see today is bring data to the BC that's a spring data project that expose you an API that allow you to deal with reactive SQL there is other ones you see a lot of clients in developments and I have linked the values github issues for this report we are now going to talk about sockets so we have worked a lot on reactive streams rector even after the BC but it's all included in the JVM so what happens where you are when you are using a reactive stack when you want to communicate between two server for example so until now you we provided some streaming support using server sent events even even web sockets but that was not really propagating the back pressure across the network and that's really what s okay a socket is providing and yeah I'm excited I a to DBC but I'm super excited about a socket I really think that even with a programming model and we are going to see that with coroutines we can leverage a socket semantics that's a very interesting protocol so that's basically reactive messaging that allow communication between two remotes endpoints and we are going to see the characteristics so the first characteristic is that it does not require cogeneration ok so you don't have you don't have to have cogeneration you can be learned above also get some air pieces system that imply cogeneration if you want to and there is a few ones already available that's by default you don't have to we don't force people to do cogeneration because we sometimes it's it's relevant to avoid that the second point is that you have clients available in various languages and technologies ok so it's a circuit is a specific specification written by clever people and pretty well write written so it's available for Java and Kirkland the Java Kirkland clients is written with reactor so that's also another reason why we like this protocol but another giant is available with JavaScript C please please go that net Python and yeah again I ever already implemented some crappy specification the L circuit one is really a pleasure to work with and the reason of another point is that a circuit is independent of the transport so you don't have to use a specific transport with a so cats it's possible to use TCP directly if you are inside the for inside the firewall you can use WebSockets you can use I think there is some HTTP to support so you have the choice of the transport and it's pretty nice to be able to decouple what you are using in terms of protocol from reactive messaging and underneath transport used it's possible that you have already used a socket on your smartphone for example because there is stakeholders like Facebook and other big company so even if you have maybe not heard a lot about that protocol it's already used in various application especially especially between server-side and mobile applications quite a lot and you have all this company data one way or another walking on this protocol and now part of the recce foundation so that's the foundation about those reactive technologies and as I get is now part of this this foundation the risk reports of a circuit in this spraying projects so it's already available or it will come shortly spring fan marks prints occur it is spring boot sprinkled getaway and spring integration all based on project reactor we are going to see more about a circuit protocol so a circuit is an application protocol for multiplex duplex communication so you can basically multiplex values connection into a single connection at one spot level and it's two ways communication so that's a duplex port so if that remains you WebSockets that's true that WebSocket allows to do that that's WebSocket is super low level while a socket is more more aware it deal with back pressure it's deal with messages so it's it's much more higher level and WebSocket is available as we transport to carry a circuit if you want to use it for example in the browser so like I said you have various transport available and it's up to you to choose the most optimal optimal one for your use case so you have UDP TCP WebSockets and other transport will will come and you you have the choice it provides for interaction model the first one is request response so in the request response interaction model it's similar to what you have in HTTP you will send requests and you will get a response with with the plot request theme is a little bit different so you send a request and you receive a stream so it could be similar to what you have with server sent events okay but here I forget natively deal with various messages you have requests channel with is basically creating a two-way channel for discussing between a client and the server and you have bi-directional streams you have requests fire-and-forget so here you are just sending something and you don't care about is it received or not so this is useful for very efficient communication you want to have no non-critical data so you want to send a lot of logs for example of thing like that you don't care about is it received or not you just push a lot of things so that's pretty pretty powerful mechanism like I said this duplex so you can use both ways communication and in HTTP you just have the client which is a requester and send some things over to the responder which is the server and then you get the answer it's with a circuits the server can be the requester and send some data and get some response so that brings some new possibilities compared to HTTP its implement reactive stream semantics but not just inside the JVM but on the network so it deal with a for example back pressure so the protocol will send for example request end data and then the responder will will send just the number of data requested and that's super important when you are using the network because like I said the issue that we want to try to avoid it is to have buffer that grow and grow when we have a slow consumer and very fast producer so it's it's pretty interesting to have this back pressure managed at the network level you have session stream resumption and that super importance and super useful because that natively supported by the protocol so if you have some connectivity Lost's and if you are developing some application that imply mobile phone for example you will have that all the time the protocol will natively under connectivity us and just resume the connection where it was closed so you will avoid duplicated or lost data okay and you can you can resume and it will resume exactly at the point where it it lost the connection and it's it require some state management and server-side but not a lot because again with back pressure we don't have to have huge buffer to store everything so that's very good fits with the back pressure management at Network level the back pressure is per stream by default so you may ask what about the total number of requests and stream since I have multiplex connection and I can have a lot of different channel opens what if I want to basically deal with I don't I want to limit the total number of parallel requests and stream that what is called leasing in the protocol so leasing is that but managed for all the opened channels and you can configure that as you can configure request routing with lease with associate clients like usually for this kind of protocol you have also fragmentation and reassembly and a bits to detect when a connection is closed so this is if you have already develop some application with a server sent events or WebSockets this is all the kind of issues that you can have with this low-level protocol are here correctly and natively solved with a socket okay so we are now going to talk about coroutines and we are going to begin talking about coroutines in general and then we will focus on what that means for the spring support so cou routines are lightweight threads I mean you can create thousands of threads but you can create and read of thousands of kuru teens because for one coroutines you have a very small allocation and you can create basically you decouple the OS threads from the stress that you deal on the the a new programming language side the Phoenicians are encoding language but there is very very small amount of things that are implemented at language side most of the implementation lives in the library side in clinics that go routines and that's pretty interesting because unlike other languages and technologies it make routine super flexible so kuru teens are interoperable with computable future frogs mono every other kind of type where where everything is up coded in the language it's it's usually not possible or so when you talk about proteins with somebody or when you think yourself about coroutines think about what that means because when you say the word co-routines in Catalan context you could talk about the library about the language feature does about this lightweight thread so sometimes there is some confusion about corrosion because because two people don't talk about the same thing so maybe explicit what you are saying or referring to when you say coroutines incur routines allowed to consume spring reactive stack with a nice balance between imperative and declarative style so it's not all about being imperative I will show you that it's a nice balance between both and for in my opinion that's that's a perfect balance between both approach operation a second shot by default and that's different from what we have in reactive side concurrency is explicit so concurrency is possible there is a wide range of feature to deal with that but you have to explicitly say that here I want to do things concurrently and there is three mini blocks that you need to know there is more pies and things go routine but if you need to learn just something I think knowing where these free building blocks is super important the first building block is suspending function so a suspending function is a cutting function where you will add the suspend keywords before the fan keyword and that will explicit that this function is a suspending one and so it will run on coroutine so when you add the suspend keyword that means it can run as lightweight threads as a routine a suspending function can call and invoke other suspending function so here delay which will basically not block but suspend the execution of the function during one second it's a suspending function okay and typically when you are using an HTTP client that will request a remote web service when you are going to request your database these are all operation that implies some latency and then you will use suspending function suspending function call or your API and I think that's not a bad thing but that's a characteristic you need to keep in mind there is a difference between suspending and non suspending function okay so like for example if you are using mono or flux there is regular API and there is reactive API that deal with flags and mono whisker routines the fact that a function can be a suspending function it's explicit and you can't call a suspending function from a non suspending function okay the other the second building block is structural concurrency so when you are dealing with a synchronicity with imperative codes you need to have some kind of building block because the asynchronous nature implies some specific concern so in this example we have this load and combined function and we define a crew routine scope which includes launching to asynchronous operation into hollol so we load image 1 and we load the image 2 and what happens in if you have a never in one in one of this function you need to define that for example when we having you have an era when loading image when you want to conceal image 2 and that's what Soto concurrency allow here we define a collision scope it's like a transaction for example we define just a scope to define that when image when our image to loading whenever you have to concern the other a synchronous operation ok think about it like a transaction but for this asynchronicity topic the third building block is flow so they chose the same name than the Java 9 flow which is the type that includes rectly streams interfaces in in java 9 but that's a totally different beasts so when I will refer this talk about flow I'm talking about : ecstatic routine that flow that flow not the Java that which if that control under flow 1 so this flow type was not available including last year and it is now available as non experimental API since coroutine 1.3 that was released a few weeks ago you can think to flow like the equivalent of flux interactive world but for coroutines and flow is interoperable with reactive streams and support back pressure so in terms of api we have this in co-routines library we have this flow type which is a generic type and in terms of design it's interesting because it contain mainly one single suspending collect function okay which itself contained a flow user flow collector parameter that's contain a suspending function that can emit values and since codeine provide extensions you you know with with flags or flow able appear in your Java you have this 1000 operators directly available in the type here a flow is a very narrow API and all the orgy operators are provided as the extensions okay that means that the operator like filter map zip provided by the crew routines library are available as extensions and that means also that you can write your own operator as extension as well so here I have shown the implementation of the filter operator and another difference compared to reactive API is that operator are pretty simple to implement when they don't imply concurrency I don't say every operator is simple to implement but in reactive world if you want to implement a reactive operator it's super hard and you have to be david kaynor course definitely need to be able to do that in coroutines world custom operators are doable by everybody when they don't imply concurrency operator with concurrency are more complex so here we have an example of the filter operator defined as an extension functions extension function add a new function an existing type okay and here we are adding a filter function in the flow type and we provide its implementation and that's filter operator provided with coroutines I have just taken the source code from the library so you can see the implementation is pretty simple when you want to create a flow you will use this flow builder so we create a flow and we provide a lambda and it's funny because it's imperative code so here we are just creating a for-loop we are calling this delimited to simulate some kind of oppression with latency so in real life you will for example request or emote rest endpoints and in co-routines world it's perfectly fine to suspend ok blocking in reactive world is bad but suspending in Korean world is perfectly fine so you will just simulate some remote operation and then emit the data and that's that's all so it does pretty interesting to be able to write reactive code which back pressure with this kind of imperative code in my code samples I have highlighted the extensions in yellow to make that more easily understandable so here when you consume a flow it will be more a declarative approach you will type flow that filter you specify the condition so you will just you will filter all the all the data where it is less than 2 then you have map operation you have zip you have all 0 not not all you have some of the operators that you have interactive world flow is a pretty young type so don't expect to have all the reactor and original operators but it will get better and better and you can call collect to trigger physically the processing of the answer of the data an interesting difference compared to reactive world is that you can do asynchronous operation in map where you are you are using a regular API and you want to do some asynchronous operation that return the mono you have to use flat map to flatten the mono inside the Flex in collisions world's values operators like map take suspending lambdas parameters that means that you are allowed to call any suspending function in any operator and that's why in map I can for example call any kind of asynchronous operation I don't have to use flat map for that flat map is just 2 Lattin flow to another flow and that's something that leads to simple simple code so what about the spring support for ku routines so we have this reactive spring infrastructure which is based on reactor and what I want to show with this diagram is that reactor is used for two different purpose in our stack it's directly phonation so all the internals based on reactive streams are implemented with reactor flex and mono schedules etc and when you will whatever asynchronous API you will use underneath this reactor reactive architecture issues but for the API that you are using a new application you have the choice with our annotation programming model it's super easy for us to to support value CPI's because basically you we just have to support the type that you are using in you as a return value or in parameters of your at request mapping endpoint for example so here we are supporting out-of-the-box mono and flex single maybe flavor from Eric so Java compatible future pretty sure if you are using that as a parameter or an value for your request mapping for example or any in spring data we will strip out that and we will translate that automatically into reactive streams and use it with rectal spring and recce of spring and infrastructure in term of API like web client for example the player that we provide for the reactive HTTP client or this kind of API where we provide an opinionated API until now until minoan flex was reported so what spring from of 5.2 and spring good to the two brings is kuru teens based API for both option and we are going to see how we have provided that some how recto api translate to coroutines when you add a function that was written in mono a void in Kourou teens world that just a suspending function that returned units basically so you don't have to return anything under that was returning a menu of T will just be a suspending function that return T and that's a little bit that's similar to new safety where you don't have to use optional in Catalan here I like the fact that you are just dealing with regular types without any kind of wrapper when you are just dealing with single value or no value okay and when you deal with flux the corresponding thing in kuru teens world is flow like I have shown previously the spring provides official co-routines report for spring wave flags spring data volts and a circuit for spring data with report Reddy's MongoDB Cassandra and r2 DBC so how we support that in web flags so no new types were introduced okay so we you are still going to use web client or other types that you are going on the rack of side but and we support seamless support with the injection forming model we provide context interoperability between coroutines and reactor so in reactive world we can't use Fred locals for example to deal with transactional security because we can't rely on that interactive world that does not make any sense because multiple requests will be processed potentially by the same threats and we come to that so to deal with transaction and security in reactive world we leverage reactor context which is basically kind of ash map link to the reactive pipeline and the interesting thing is that kuru teens as also a context which is kuru teens context and what JetBrains as done is that kuru teens context and real torrent regular context are automatically interoperable that means that when you put something on Korean context it will be available for examples of ham hock level and rectal context and in the other way as well and that allows to support reckless transaction and security in Koreans world I will show that later with the application we will develop so what that look like so if you want to use go routines the Shabbat is not available in spring MVC you have to use pin web flags so support in spring MVC will come likely next year but for now we are really talking about leveraging web flaps and instead of returning some things a mono of banner we will just return the banner with the suspend keyword and the internal processing will be asynchronous it's also possible to deal with a view rendering so same thing you are just using I mean the cut is very similar to what you would have written for a regular spring MVC application except that here you are using this to spend key world so we provide reactive type extension for coroutines api and that's how we can support core routines without introducing new types so for example we have this web client type which provide a reactive API to deal with remote HTTP endpoints and in addition to the bujji to flex a method that you have currently we provide an extension which is Buju to flow we have also extension like awaits with something to provide suspending function that are the equivalent of body terminal and that allow you to provide seamless coroutine support with that introducing new type there is also some support on web flex Waterside so here again we have added extension like body value and weights that allow you to write imperative code where you are dealing with single values for a socket and we are going to see all this in the application we are going to develop in the second part of the presentation we are using this associate requestor which is basically web clients equivalent for a circuit and in addition to the heat field flux method we have added this which gives of low extension that make it possible to use any kind of flow operator in your application and with report coroutines return type that means that you can return a flow or return or create a suspending function it will works as expected the wrist report and spring data at will be serious transaction and again we are going to see that in the insufficient we will develop that in in a nutshell the database client is the is the API that we are using to requests the database with some SQL requests and its report so we provide extension on air to DBC database client API like await and we provide also functional transaction support which is this execute and wait where you define the scope of the reactive transaction that we want to define it's also available for spring data MongoDB so basically the idea is that we provides corrosion extensions on top of reactive types where that matters so here we have added corrosion vector extensions on top of reactive and operations which is a pretty long name but that's what it is and you see that for suspending function by convention we are usually using this world awaits that identifies the suspending extensions and for flow it's just a world flow so Koreans are not the default way to go reactive so that's perfectly fine if you are creating a coating application and you want to use reactive api like you were doing previously but since people are asking some opinions and since since need to simplify the choice by default we provide the kuru teens dependency instead as being the tayo that means that if you start a new cotton project with some reactive stuff we start a swing the Tahoe the kuru teens dependency will be automatically added to your graded on maven build file and in the documentation by default it's coroutines code that is shown in the reference documentation again a new table with status of the supports so in spring booted - with reports in term of careers in support we have spring waveflex functional api's swimmer websites web clients spring wave flags at request mapping circuit add method mapping we are going to see that a little bit later spring the directive API and functional transactions what is not reported yet is spring MVC at request mapping because I don't know if you are aware of that but spring MVC is not as powerful a spring web flex but it provides some support for mono and flux so in theory it should be possible to support co-routines and that will be the case but next year mmm spring data repositories so when you are creating some as repository classes with fine by name etc it's not supported yet with spring data reactive support and transactions defined by annotation with a transactional are not supported yet so for now you will have to use the functional transactions okay so I think it's time for for a break we are going to see in the second part of the presentation Spring messenger which is an application that we will develop in five steps the first step will be creating spring web flags will be using spring web flags and two DBC for developing basically arrests server which is using spring the tire to the BC for the persistence second part we will translate the application which is using at request mapping and add controller with the functional hotel then we will introduce s question yes and we will finally use the khufu GSL to configure the application so basically that will be this kind of architecture we will have a back-end with SQL database used with spring data to DBC you will have communication between a button the backend with a socket with TCP connection and we will use a server sent events to discuss with the questions yes front end so yeah I have a break and in 30 minutes we will begin developing supplication Thanks okay we are going to start the second part of the presentation so like I I said at the beginning we are going to develop a spring messenger web app which will be composed by a backends developed in Kirkland whispering boot to the - it will use a database with a to DBC so with this kind of wrecked ship SQL API it will discuss with the but which basically will just send some messages via sockets using TCP transport and the exchange between the back end and the front end will be done via server sent events ideally I will use a socket yes for that but for various reasons I will explain you it was not possible to do it right now mainly because the circuit gs library was not using some extensions that we have added for the routing and also it's a pretty young library on server side is quite quite robust on front end it was yeah it was too complicated and also I prefer to use cut ingest so to show you the usage of coroutine on front-end I prefer to use server sent events it was simple but ideally if next year I will do the same talk I will use as a cat yes and if you are using a dead script or JavaScript you can totally use a circuit from the browser you just need the upcoming release that will support the routing metadata extension so we are going to to see this application okay so I will show you we are we are going to see five version so five branches of this application originally I was planning to do it full life coding but somebody stole my laptop two weeks ago so I had some yeah but if I was pretty short on time so I will do it the safe way hopefully that will be great for you as well but just to explain you what what happened so we have this application which is a spring boot one so you see we have this build that resulted kts in fact in your regular process you will go to start the spring data you okay we have a very nice the QI mud and you will select Gradle you will select cut lean and an interesting feature so you can see that we have a sockets reports okay here we can add spring or active web etc and we have this nice explore feature that basically generates instead of generating zip and you have to download it extract it and in your IDE in your IDE if you want just to take some part you you can just explore a couple n tests I think that's pretty and the new feature that allow you to just take what is needed without having to create see a cave so let's say we have created this project so you have this builder dradle that kts which is natively supported by Italy gid I'm not sure what is the support currently in Eclipse but generally yeah for now I really advise you to use into gid I push with cutting team I really try to make the captain's report and eclipse better but it takes some time so far now reusing until eg ID is almost mandatory so we are using the new grader syntax to declare plugins and that's especially important with the grader cut in DSL because that's why that's what will provide you autocomplete so you can you you can't use all the way with where you declare directly the dependency and you apply the plug-in that does not work very well with the grader cut in DSL it looked like the groovy DSL but everything is not statically everything is not statically type if I ask some other completes you will have the values capabilities provided here and that just yeah a regular grader will fight you declares the dependency so here we are going to use mustache for the templating we are going to use web flags we are going to use spring boots that I have two DBC so spring spring boot starts out that I had two DBC is still experimental it's you can find it if I go to spring projects experimental okay to be seen so it's available here okay it's not yet one that also it still Giotto configuration still live in this this project for now we are using h2 locally but in production or if you are using locally docker container you are likely to use plastic or SQL for example the Jackson Kathleen module is automatically added by status window toyou as well as cut clinics corrosions reactor dependency because we are going to use co-routines so like I said in status window toyou if you if you use cout lien and you are using some reactive dependency if you have a look to the Gradle build file the dependency is automatically added so you don't have to do it yourself so back in the code so we have this back-end application so for the main class is just messenger application its annotated with a spring boot application and spring boot provide a run application which is equivalent of spring the spring application that run static method and it's allowed to start your application notice that it's not just in sexy sugar you can also have access to various ways of configuring of customizing your spring with application if you add a lambda here okay so you can specify various things like if you want don't want to display the banner or crazy things like that mmm okay we have the model so here we are using a very simple model with data classes with read-only properties like it is usually the case with automatic code clean code may search user very simple and then we have a user repository this user repository is you using database client so database client is is a functional API to deal with reactive SQL through spring data a to DBC it's it's design a little bit like web clients for the HTTP side but here we are going to request directive SQL database with a reactive API and it's a lower level abstraction than GPA you don't have all the mapping object mapping side okay so that's really low-level you are directly writing SQL code so if you want to use specific feature of your database you can so you can use specific feature for example PostgreSQL has great design support or if you are using some special extension for example for your database this is not an issue here and spring data to the BC provide uses fluent API so here I specify if I want to perform a select operation or if I want to do insert or if I want to execute any kind of SQL code I'll specify so I can show you with giotto complete so you can choose what you want here then you can specify the table you specify a type of the return result okay so it will do some kind of basic mapping mapping well-known type to your object and then you fetch the data and here we have access to so all by default is a way to retrieve a flux that's why what is available in the API and flow is an extension so if I go to the code you will see that flow is an extension that we add on rows fetch a prospect which is a class of the friend API and you see in fact we just take all which is original method that returned flux and we transfer we convert it we adapt it to flow and that's a very lightweight operation so flow and flux shares this kind of reactive stream star R active stream seen on ticks so it's really easy to transform one type to the other ok if we have a look to find one this is a suspending method so in reactive world we would have returned mono F user but here we are just returning something plain user so in in a way we are able to write reactive codes in a more imperative way with a style which is closer to what we are used to and so we specify the SQL requests we specify we bind the login parameter so here it would have been possible for me to use a string interpolation okay because cutting provides the kind of nice feature but for security reason to avoid SQL injection I prefer to use the binding capabilities provided in the in the database client API I specifies the return type fetch and here I have values extension so still if I am going to through the code here I'm just using a 1 which return the moon oh and I'm using an extension that turned it into suspended return value and the IDE does a pretty good job who provide autocomplete for extensions so in terms of this capability that should be that should be ok here so unit is like unit in Kathleen is like void in Java okay so here this is return nothing and zpi is is again closer to what we we use to have in the imperative world for the installation I'm defining an event listener on the application read the event and here I'm creating a reactive transaction so there is no support for a transactional yet so you confuse that for now it will be available next year but it was more work for us and it was not possible but conceptually you can do exactly the same by injecting a transactional operator which is a type which provides reactive transaction management and what I have done is that I have just added some coroutines Ryan so here execute and wait I'm still using the wait prefix or any way to fix convention to identify this suspending extensions and inside I execute my operation you can see that the IDE indicates where when we are calling suspending methods via this little icon and everything if I have an error in one of these statements everything will be whole back its transaction like what we are used to but in reactive world again a transactional will be available next year so here that's just another way to express the same semantics if you are using the spring boot to the business report transactional operate or bin will be automatically available we use constructor based injection like it is advised in Kaplan best practices since my class has a single constructor it will be automatically Ottawa Yard I don't have to add I mean if it was not the case I will have to add auto auto wire odd constructor but here I don't have to do that because that is implicitly done because there is just a single constructor notice that transactions are available for suspending functions so here in this lambda everything will be transactional but there is also a transactional operator here so everything if I use this transaction neural pirata every spring data to the BC operation done inside the operators of this reactive type will be part of the transaction okay so this is available in imperative way for suspending function and this is available as an extension for flow type and again how we do that as an extension because obviously the flow type which is coming from the coroutines library does not provide any kind of spring transactional support so we are using an extensions to provide it like that and it's it's much more readable than a static method for example then we have the webparts so we have a user controller again what is interesting with coroutines is that your code is much closer to what you write with spring MVC which is a model that everybody knows you notice that when you return flow you don't have to make the methods responding it's possible but you don't have to because the suspending operation will be done inside the operators okay think about conceptually adding suspend keyword is like wrapping your return result into mono or compatible future okay so here I don't have to wrap my flow into something because asynchronous boundaries are inside GOP rattles we're here I see I'm you're joining a user so in rec you world I will use a mono F user within synchronous such a very compatible future of user so here I'm just using the suspend keyword with a user return value maybe a quick tip about how to by default in Tunisia it doesn't show use in fair return type because in Java we we write explicit types everywhere in code clean we have the choice to write it on it so I could write user myself but I usually prefer at least that my taste to little reg cutting great type inference to implicitly have this type in fact that by default it isn't I think it's not displayed by IntelliJ IDEA so you can configure it by going to and that's the long journey so be prepared you go to editor appearance show parameter ins configure cut clean and then you so this is my configuration show function return type ins that's the one which is pretty useful and not configured by default and also show local variable type ins I usually configure these two ones and that's pretty useful because with that kind of configuration you get the best of the two worlds you have the return types which is explicitly displayed but you still leverage cooking type inference to to infer it so yeah that's that's pretty useful I think mmm I'm using a tres controller at request mapping at get mapping it's it's basically if I add a spring MVC code it will be that without this is funky well okay you notice that if my under method is not suspending here I have any her because suspend function did it should be called only for macro routines or another suspending function and that's what I meant when I said that coroutines color the API is that you can call it seems a little bit magical because you don't have to use this reactive wrappers but in it really improves the readability I think of the code but it's not magical and things has to be explicit and non suspending function can't call a suspending function it's possible so there is capabilities to call that into lambda parameter but basically the rule is that you you need to call suspending function from another suspending function and in terms of characteristic it will be almost the same than if you are using react director flux or mono it's all reactive underneath we have also this controller strip out so here I'm writing my HTML controller I'm inject user repository and I'm using model to add my users and I return the name of the view notice that here for model so model you have add attributes but you don't have this kind of bracket notation which is specific to cut in so here we are using a cut in extension that it's an extension of type operator so basically it's define the set operator on model to be able to make it possible for us to use this nice notation instead of add attribute that makes the code more idiomatic we have our template so this is a mustache template you can use team leave if you prefer it mmm and I will just display some HTML and I will display dynamically but on several sites list of of the users and I have my tests so this is the basic one which is generated by default and this one is more interesting I'm building a test so in whispering MVC you would have used mock MV say for example to test that in a more efficient way here we are using web test client which is a test API similar to web client so we are going to test our user API so we are defining while using this client and we basically define what we expect so here we are requesting the slash user slash endpoint and we expect a body list with these users like I said since I can't call icon called suspending function from regular function I need to use this run blocking facility which is like that block with recto API and since we are in test that perfectly fine to use this kind of statement maybe later there will be native support maybe there will be some g-unit extension that's natively supported spending function but that's not yet the case so we have to do that mmm okay I think we have fine one user we have the other one that's the same same thing and here I'm creating some user in the repository I did it it has API and I check on the repository that it has been deleted so if I run this test unless the demo effect it should be green ok so so we are fine we have this if I run the application okay so we have this user are coming from the database and after I will add dynamically elements in the Dom with the congest front-end but for now we are we are fine so I'm going to go step two here I have chosen to use exactly the same annotation you will use with this is at controller at get mapping level okay so every routes is defined with annotation but like I said previously with web plugs I have the possibility to use the routing DSL with the functional API so I will do that change with this new branch and instead of using so the rest of the application is the same okay so our user per story is the same but here we are going to use the GSL to define the routes so I create a hotel configuration to expose my buta function bin I'm creating the desert with the code so hotel is for reactive API so if I write wood here it will still return a hotel function but if you have a look here I'm using when I'm using mano of several responds okay so this is the SL you will use if you are using flex and Munoz but here we are going to use the same infrastructure but with coroutine api so we are going to use instead this Cohutta API which is exactly the same but the signature that we are using here is to check the signature that we are using here is suspending function that take several requests parameter and return several response or return value so here I have with your autocompletes I have access to the values HTTP methods okay I can define some request predicates using some specific media type I can even define some some filters that are applied after or before the elements I can create some request predicates based on customized leaders and I you can also create your own request predicates and you can combine them so you can for example you can create get slash fool and you can combine it with other thing like that okay and then you you write what it return body etc so you can really combine everything nope not body body and weights because we are using the functional so functional version so we are you can nest the predicate so here we are going to prefix the request by decades with slash user so every request that's taught by slash user slash slash login or everything which is included this two nested predicate will be combined and you can nest any number of predicates that you want this is caliber references so I could directly write my implementation here but here I'm just to externalize the implementation of the Unruh outside typically in an underlayer that will have injected zero positively or the service that i'm using and here you see I have a suspending function that takes several requests and return a server response and I'm using several response that so here I specifies rich HTTP status then I have access to various methods so body is like returning something returning an object in the annotation based programming model here I'm chose to render a view so I will specify the name of the view and I add the data that are used to modify it dynamically my templates with by creating a map so this is a way to create a map in a pneumatic way in Kirkland if I go to my user on Blair it's still a component we inject the user repository and I have the same kind of pattern with my request as input parameter and I return a server response and here I'm using body and weight okay so body are the methods that are optionally available in serve in several response and the return mano of fluxes and boolean awaits its suspending function so it's it's an extension that just convert that into something which use suspending functions here what we are doing here so what is interesting is that whisker routines we are using exceptions like we use them in blocking world in imperative world this is not like in racket world where it's a little bit different so here we are just calling fine one on the repository you see fine one returned a new label user and like I said new safety is natively managed by Kathleen so if I just do that it will return an honorable user which is not what I want what I want is that it returned a user or it's funny hall so what I need to do is to use this question mark that lets [Music] notation that will basically it's like that map it will change it will modify the return value if what is written here is not new okay so if the if a user is returned I'm answering an ok status code n I specifies a return value as a budgie value using the security index tensions and if no new user is returned I will return a not found answer and in that case I will have expected behavior returned a user in jizan or throw a not found Evo status code here's the same same thing I'm transforming the returned value to just a server response if I want to specify the status code I have an API to do that okay so I'm just using status and I specify HTTP status that created and that's that's it we are now going to step free so we are going to introduce a circuit supports so here in addition to our back-end module which is again a spring boot application with a socket now we have added a circuit for the a circuit clients mustache web flags spring boots started at i/o DBC I have a bot module the purpose of this module is to create a very very simple but that will answer something when we get an answer and like I showed previously it will discuss with the back end with a socket so to do that I'm adding the spring boot starter a circuit dependency and I'm going to am using the same message class I could have created ocean but I will do that in the next step the interesting bits are in but controller so here we have a controller annotated with ad controller like us 10 points but instead of using at request mapping or at get mapping I'm using Atmos and mapping which is basically the way where we expose server-side endpoints for a circuit so in terms of implementation I can its report flow its report mono its report flux so you can it's flexible method signature like with spring reflex world so here in terms of communica discussion pattern we are using a flow of messages as input and a flow of messages as output and here this is a very crappy implementation that will just return is it me you're looking for if the message in input is hello so and we have also another channel which is a broadcast one so this one take nothing as input and we'll just return a stream of service messages okay very crappy implementation but just to show you a simple example we could also use a suspending function if I just want to to just return a value and everything is using back pressure over the network when you are doing that in terms of configuration here so spring boot has built in a circuit support so here I can specify what kind of transport I want to use so here I'm using TCP I could use WebSockets I specify the ports I specify also the logging here because I would like to to log the various messages exchanged and we have all sorts of tests so in terms of tests we are going to use the eye sockets requester which is equivalent for a circuit compared to web client in the HTTP world we are going to inject the local a circuit server port just ping boots and here I'm using the API so basically I inject not directly a circuit request about a builder of a circuit requester I specify what kind of mime type I would like to use and if with web well with HTTP endpoint usually you use reason here we are using to use Sybil Sybil is a binary format and usually when you do a circuit communication via TCP between two server sites macro services it's better to use a binary format that would be more efficient so for now we have support for so design which is a binary but we support obviously design because it is iniquitous we have support for Sybil and I think we have support also for other other media type but I don't remember exactly what was the other protolith I think we should I think we have support for protolith as well originally there is connected limited that return can show you with yet Oh completes connect TCP will return the mono of a socket requester but here we are using the Caribbean extensions so connect to subpoena wait and that allow us to deal with that in a very imperative way and then we specify that we want to request the hood but that messages which match with what we have defined here okay we send the data we create a sample message hello in order to be able to have so famous and so of Lionel Richie and we assert that we get this this answer and we also check that if we send a message which is not hello Lionel will say nothing okay then we have also updated the backend side so here we are going to use the a circuit request a builder okay to create a new a circuit requester and then in in this these endpoints will produce a stream okay so it will it will basically produce a stream which will be exposed yeah server sent events so let me start by the right parts so slash messages slash stream we expose we with text event stream which is a server sent event a media type we expose a stream that will be consumed on the front end and the implementation is that we are so you see okay that SSE that's a shortcut to space to specify that we are using the server sent events media type and then we provide a body of type flow so we are providing a flow of messages and this both messages is is emitting it melt free things the replies from the bots so a message sent by the front end vias with posts you see here we have a post endpoint that allow the front end to sense of messages okay took and we also get broadcast messages sent by our but here okay and we merge these three things and we we provide it to the front end via just a la santé events if I was using troop if I was using circuit GS not a circuits JavaScript support I will not use service and seven support of web products but I will do I will just use associate clients to provide the data stream via WebSocket connection to the front end but you know like I said I'm just using server sent events and I think we are fine okay so now we are going to go step four and we are going to use Kathleen on the front-end like I said you can totally use that with type scripts using secured GS etc but here we want to have a little bit of fun and I would like to show you that one of the interests of code clean even if that will be maybe more important on the long term than today is to be able to share some codes between various type of runtime and that could be between the front end and the back end so here we have our spring messenger multi module projects let me just update the Gradle configuration and we have values values modules so we have the back end and the but this is the same and we have front end and shared so shared is a multi-platform module so here I'm using took a bit better for you I'm using the multi platform cutting module then I'm defining that I'm enabling the JVM and the JavaScript platform for the browser I could also targets not GS here okay I can also target not GS and and create some code that run into not GS and server-side and so if is specifying the dependencies and then in that comment codes I have message and user and I have even shared test and the IDE integration is not finished so it does not work in the IDE but if I do so if I'm going to the command line okay if I'm doing front-ends test [Music] okay so I don't have any or put bets at esta Aaron you can believe me so that's it to be totally honest here I'm using a simple case where I'm using the string if I have some more complex type like that time and thing like that to be shared between JavaScript and front-ends this is more it's a bit more complex so there is some some support for multi-platform types that can be shared between front-end and back-end but here for the sake of simplicity I will just use string but the recent project with some multi-platform datatypes so in backends and but you will see that I don't have any more in the model I'm just using I'm just defining a dependency here in my Gradle build file towards a shared dependency and for but this is the same I don't have any more any model class here now let's see the front end which is this project so in terms of build file I'm using Kathleen GS plug-in okay I'm also applying Kathleen dceg SDC II is the plug-in that remove a newest code from the front end because of the wise the generated JavaScript is so huge that your browser will die it will work but you you won't deploy that in production believe me so yeah since this plug-in is to get quite concise JavaScript code by default then I'm defining the module kind so here I'm using UMD because I want this to be usable in the browser in addition to Nadia's and I'm defining a web pack test task so underneath it's using webpack but you don't you don't have to configure it yourself because usually as a especially as a back-end developer you don't want to pay the price to configure the complex JavaScript stack so it's possible if you want to configure directly web pack and run it from whether it's totally possible by by default it's hidden underneath when our front-end we are using steady deep - yes and we are also using the Carew routines dependency so cou routines flow suspending function our multi-platform library that is available for the JVM but that's also available for native if you want to develop an iOS application available for cutting yes if you are developing a front-end application and the great interest of that is that you can use the same API the very same knowledge and you can use the multi platform module of your own application so here thanks to this dependency I will be able to use message and user in my front-end code and this is the same code so no synchronization problem with both now in term of code so I'm developing the front-end with Kathleen the great thing is that I have access to all the features that can provide like extensions in like that and here is the main so this man will be executed when the browser is launched okay when my web page my web page will be available and you can so you have this document object available we have with values capabilities that are statically typed again I want to be fully honest the API exposed by cat ingest is not perfect yet it does not look like a geometrical clean everywhere but that's a pretty good start it's similar to what so types we provide but I really think that cutting GS could do a better job right here I have to have to cast it because basically is the automatically generated code clean binding for also DOM and the web api is so that was their best like that so here we get the user selects the message input to submit button Dom elements and then we define some callbacks so we're when we press ENTER and if the field is valid I will submit a message and send it to the back end I will reset the value and you know that same thing is I clicked on the submit button and then I will do something because I want to show you how we can use flow-on in the browser there is no API based on flow by default but I can write an extension because I am on the front end so I can add add as flow method on the event source event source is generated so this is a javascript eventsource type okay directly created from the doll in the web api s and here I'm using callback flow which allow me to convert basically a callback based API which will receive multiple message and expose it as a flow or something so I define this extension and then in my code I can write so event source I specify the URL which is the same one and exposed in my backends I convert it to flow because here yeah I can get it to flow I use that map so I transforms the objects which is just plain text with the design I pass the design and I transform it to a message and then I trigger the correction of the flow and I adding some Dom elements into the the right so Dom into the right Dom elements and when I submit when I click on the submit button I will use the fetch API which is a modern API from available from the browser and it has a Kathleen GS binding I specify the URL to to it I define that that to posts I defined so content type and the body I sterilize the message to reason okay and then I define dependency in my back-end so my backends - - it has not been updated not sure why my back-end should have a dependency on check I know okay it is here it is it is specified via a specific task on the process resource side and basically I depend on the front-end browser web pack task and I copies the output from a build / curtain GA / main to the static repository the static directory which is automatically exposed by Springwood and by doing that I will run my application so I go to my back-end in recent version of into the GID every operation every grader tasks are natively based on the grader operation so it will automatically deal with circuit in front-end part I also ran the buds okay so here I receive my service message I will open two two tabs okay and here if I send some message it is written here I'm everything is receiving everybody is receiving the service message sent by AutoCAD but and if I tap L oh yeah this is the most impressive part of my demo I know it's not how some data Leonel is answering me and I felt not alone anymore okay so now and yeah and if you go to the but you will see the the values a socket frame that are a displays here I'm using binary support format so you can see everything but you can use design or other text based format to be able to debug things if you need to I'm going to finish that with converting the application to use khufu so I have created this spring food projects last year the purpose of this project is to be able to basically configure your span good application with the DSL spring boots is natively built for Java and choosing a set of clever convention to be able to configure your application this convention are for example that when you have the jackson dependency on the class pass it will automatically configure the jackson converters and codec as needed that's super useful but with coupling we can configure everything explicitly and that's great because configuring thing explicitly means less less work to do as a soft app so it's that faster it consume less memory and you don't have any surprise because if you have a feature you have asked this feature it's not something that will pop up because you have added dependency this dependency could be a transitive dependency so that could be surprise so you are in control to configure everything with this application route DSL which is a kind of mother of all of our DSL and this DSL is leveraging the other ones beans wood etc okay so this is an experimental project which is in spring project experimental and if I so I have started stopped that okay so I switch to the last part I import the changes and here I have converted the back end projects into into an application configured with tofu so to configure an application with tofu you have to add the khufu dependency which will provide this application DSL and if we are going to the backend application we are we are still the main okay but here instead of using the annotation I'm defining an application of type reactive the resources report for spring MVC with servlet thing and we are basically allowing to configure your application you spin boot application in in a modular way by defining configuration slices so here I have free from configuration slices that I can feel where config and AutoCAD config and you see here I can define any kind of configuration so I can create some bins and these bins will be automatically auto by out so I don't have to inject manually other parameters I can defend is Mouse I can enable here to the BCS reports you can also configure logging so for example if I want to configure logging I'm using that and since I am lazy I would just have to follow the autocompletes to configure everything I don't have to go to the reference documentation find the right parameter etcetera and I'm just averaging capabilities of my IDE to do that again by default you will you will just use Jack and you will want to enable prettyprint for example to have something that display nice so here you are you have access to all the Springwood capabilities to configure jackson in a discoverable way and you can found that ok it says in on that but i want and you write it so everything is discoverable in my web config i define the bins that are used to implement the web part so here the wrist report for creating bins directly with a function table level function reference and every input parameter will be injected joke I'm defining the bins for the on levels as well I inner by well facts configuration is explicit so I have to explicitly say that I want Jackson ok it will not be enabled by default because Jackson is in the the class pass I also define explicit configuration for mustache and for a socket I'm just creating a bin of type a socket builder and I configure it with Siebel and this application can be run it's it's a spring good application ok but I configured in a in an explicit way so I need to rent a but application so I ran the boot application I run this one not sure if that works or not ok oh yeah because I have set the log level to ever that's not that way and my application is working as expected so this is something that is not yet projection ready I mean khufu so it's it's still in experimental mode and I will continue to improve it my goal is to get that integrated in spring boot as spring boots applications ESL but the resting a long way so I need to make progress on that okay so like I said previously so this was Spring messenger demo the ideal architecture would be to use a socket for the clients as well so it's possible to use a socket gs for the front-end and also to use a socket on on rate because there is androids means the JVM the JVM a socket film can be used in server-side and on an on the red side currently it only exposed a reactive API with facts and mono but it should be easy to define some extensions to convert it in code in co-routines and I think that's a that will be done shortly so if you want to have a look to a socket yes there is these projects and you can use it on front-end like I said it's a little bit young because metadata extension has just been integrated or so it's using flow from Facebook and not attached script so there is maybe you need for typescript definitions to be to make that it is easily usable on front-end hopefully that will matter a little bit and it will be available and I have created I have created this silly issue about so there is a socket Kathleen project because until recently it was difficult to use Java 8 paste code on Android nowadays it's more and more easy so I think so ahsoka Java client could be used directly on and on orede so there was some discussion about just shutting down a socket Kathleen which is based on cutting GVM and the ID I add was to propose a reboot of a socket cotton as a multi-platform libraries so the idea will be to expose a coroutines API for all platform coach ing VM Kirkland on with cotton GS cotton native we'll implement a circuit protocol which is just a protocol with a specification implement that can be implemented with any kind of API reactor or any active streams API are a good choice but you can also expose its whisker routines and flow and yeah some people are excited about that obviously that's a big work but that's maybe an idea for the future and I think that's a good use case for coupling multi-platform capabilities to be able to provide for all platform with the same API access to this great a circuit protocol thank you for your attention I will make the spring messenger project public just in a few minutes so you will be able to have a look to the source code you will be able to check out the various branches and I will update it so for example I think in the future I will replace the server sent events communication by a circuit communication for the front end you can follow me on s dollars on Twitter and if you have some question I can answer them thanks some questions yeah I pro preview is because so flow is a very recent type and it has been made non-experimental very recently so flow by itself it's not experimental anymore and you can use it without expecting some API changes but some operators which are specific extensions are in preview mode okay so that means that when there is this annotation it's just to avoid some warning in the IDE at the preview is to avoid some warning in the IDE because I'm using some specific operators which is not stable yet and the API could change basically yeah I'm using what kind of statement could you repeat yeah so the philosophy of the spring data F to DBC is indeed to just provide you a way to write so SQL requests with text so in a non type safe way it will be type safe in term of object mapping but indeed when you write the SQL request is not type safe and that's where I think the support from other kind of clients could be like joke for example it's not yet available but I think there is some early preview of reactive support in Duke so other kind of clients should be able to support earth with the BC underneath and exposing it as with the types of API there is also some Kathleen API like xposed which is basically writing SQL or requests in the types of in your type safe way using all the coding capabilities and expose is a very interesting library so maybe this kind of library will support at with the BC underneath and that's my hope is to see I mean spring data to the BC is a way to consume your reactive SQL database but like I said previously we expect other kind of SQL fiims with awfully type safe SQL API to be supported in the future but that's all new so we need to wait so ecosystem leverage that okay thank you last question yeah okay so no no okay okay so the question is yeah that is explicit configuration shown in the khufu GSL is going a little bit against bring boot philosophy of configuring convict configuring everything with conventions and indeed that's I mean that's reusing some part of spring boots but indeed the fields of his different so is it spring wood or is it something different that's why this is a separated experimental project but it's leveraging all the capabilities the spring boot to configure or juju ecosystem because spring boot is released integration points Asura Jeeva maker system but indeed the the GSL approach is significantly different in term in the fact that it it's a different way of configuring your application and everything is specified explicitly so it's just difference my gut feeling is that for Java configuration implicit configurations a convention is the right thing to do and that's why a spring bootie step X was successful this is because Java is not advanced enough to be able to do its business configuration with the concise code readable code etc and at some point I tried to create Java which was javadi I said to configure spring boot explicitly and even if some people are crying in the spring foo issue tracker III killed it and I won't respond it because I really think that's the noise in terms of code it's just not doable it's not maintainable and I don't want to go that way so I think this is another philosophy to configure spring boots possible because cutting allowed to write DSL like that with autocomplete with very readable code and it's not possible to do that in Jarrah so since spring which is coming from the Java world it's perfectly fine to do that in Java it's also perfectly fine to do that in Kirkland I mean that's what you should do if you are writing today an application with spring boot and coupling and that's perfectly fine but I think this kind of dsl like khufu a load to leverage even more cotton to provide not just you right exactly the same application with a different language which is fine but nuttiness in my opinion to really trigger a wide move toward cotton but you really leverage and embrace the philosophy of kirtland to to give you additional advantages like like I shown everything you define is explicit so code is still readable I have not shown everybody but you can define you your application you can define your slices of configuration in a very fine-grained manner and in your integration if in your integration tests you will just enable the slice that you want we spring boot regular code there is predefined slices like the data one the web one but usually and that's a very common problem people complain because too much is rent and their application integration tests are slower with this kind of approach where you are in possibility in charge of defining your own configuration slices you have the control to define only the right slice for your code your integration test mocking just on part and you have more control and everything okay thank you [Applause] [Music]
Info
Channel: Devoxx
Views: 3,984
Rating: 5 out of 5
Keywords: DevoxxBe, DevoxxBE19
Id: BoidEr_ZCGc
Channel Id: undefined
Length: 129min 42sec (7782 seconds)
Published: Tue Nov 05 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.