Building Event Driven Systems with Spring Cloud Stream

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning good afternoon or good evening depending on your time zone and welcome to the spring webinar program my name is Peter Humphrey and I am as always your host today I'm very excited to introduce you to Jakob Jakob Tillman who is going to be talking about adventure in systems with spring cloud streams - Jacob would you like to introduce yourself hello hello everyone thank you Peter so my name is jeff Bingaman and i work as a software engineer currently i am an independent consultant so I I try to help companies in building better software architecture or if I hope so when I dropped out I learned classes as a trainer and in a company called Bottega I see mine host on a blog here is the URL and my memory of interest our object orientation the management design is even growth development in architecture so today I would like to talk about building event driven systems so thank you all for joining this webinar I appreciate your time and first of all the question is why do we do our systems in an event-driven manner in an event event manner so I think it's mainly because it helps us in delivering software in a loosely coupled way so we have a producer and we have a consumer of event and the producer doesn't know who the consumers are and the consumers consumers must know who the producer is so they don't even have to be alive at the same time the order for them to communicate if there's for example message broken into between them so first of all it helps us in there very loosely coupled systems second of all it follows open-closed principle right because we can add functionality without touching the crowd of the producers of the producing side so we can build some new functionality upon an event emitted by the producer and we don't have to modify the code from the producing side but in my opinion the most important why we do that is that our systems and try or at least they should as they should to try to solve the business problems that we that we are facing so what is the business demand this is the man is nothing more than furious of edom of the main event of business or business event so if we try to capture them in our code and they represent as first-class citizens in our in our code base it's easier to reason about the domain so for me to me their most important reason why we should build our systems in there and then even jiggle manner so we're start for talking about how to find your events you know in your domain if you don't have them yet in your code base so do not be worried if half an hour we don't even mention the word micro service or sprinkle stream or messages or something like that because first happen I will expand on finding our even in a normal normal object-oriented object-oriented domain and then we will try to rewrite this domain to an even forcing mechanism mechanism which is basically a different way of storing our state that will go to spring called stream tool which helps us in delivering even driven systems we'll talk a little bit about commands where responsibility segregation and we will see if it's difficult or not to build event email systems that have for example professes that spans multiple bounded contexts if it's possible if it's difficult and how wrinkled swim can help us by doing that and by doing that we will see some architecture patterns and challenges that we have to face so let's start to start coding so I think that's almost every domain that we are aware of or at least most of them has a concept of a user let's create a class named user ok and what I do at this point when we have our concept in the decide of the class I try to find the behavior so I think we shouldn't be thinking at this point about data structures that goes behind this user or what kind of properties it has but we should we should focus on what kind of behavior it exposes what is the concern what are the methods what are the signals that we can send to our object and to do that I recommend you suspect things like even storming core domain storytelling we don't have time to cover them but you can find many materials online about that so let's assume you are done with that we went through even storming session with for example business faults and we had identified that our Enzo should have following behavior for example I'd know we can activate our user we don't know yet how to do that but we know that we should activate them somehow it has this behavior so - also we can be active item if we can activate him let's say we can change his nickname to anything to a Newton in Munich name you know nickname let's say we also can ask our user several questions like hey user are you active are you activated I like to throw more force for a while to make it Kampai because again we don't care about data structures inside to care about the behavior similary we can ask him whether he is deactivated and also we'll talk for zero and let's say we can ask him that user what is your nickname - a real returning extreme again for a while - to an empty string but at this time at this point when we have our our behaviour exposed what I do that and what I recommend you to do is always try to think about invariance by invariance I mean what are the state transitions that our objects allows us to do so basically these are parts of if statements in our model also they can be found by for example anthemic sessional the my storytelling when we found when we have when we have them defined I recommend and I like to do the following I try to capture them in am in a test specification so for that I use for example groovy it's readable so we can you can program in a few days of test cases so let's say that we identified that for example the activated user cannot be cannot change name nickname there's the first environment second in violence for example can be activated user can change nickname the third one would be pretty simple let's say a new user can be activated and let's let's think about it the activated or activated user can be deactivated of course these are within state transitions that our object that our user allows us to do let's say that activated user cannot be activated again because it doesn't make much sense right and the same with reactivation reactivated user cannot be activated yes but we haven't defined these are the invariants so that would be the time to do proper TDD so we have in with a store but we don't supply for that so let us write all the test cases upfront and then go to the implementation part okay so we'll initialize a new user user should have an identifier okay so let's let it be UID so let's actually create new IDs here in our code it should be private final final UID setup other to a constructor parameter are you not it's almost time in fact oh okay I think we'll be needing gather for that so let us add together so okay we have a user and yes waked user cannot change his nickname so give an activated user when we try to change he's making to let's say Barry then our system should not allow us to do that so let's say here I go take exception from but activate that user so user dot activate when we try to change this nickname - Barry it should say okay my new nickname is Barry but when we ask in your nickname it should say Barry new user conductive I said this one is pretty simple so when we try to activate it zero then should be activated simple enough then it's activated activated user can be deactivated so when the given user is activated when we try to deactivate you it should be deactivated right user activity user cannot be activated this one goes like this user not activate when we try to activate them again then Allah God says exception should be from and same here even which I given user that is deactivated when we try to deactivate him again then like our state exception to be from if we run those tests right now I guess they will say because we don't we didn't implement anything oh it's random and let's jump to actual implementation building and they should be all orange yeah so there their web has go through the implementation and so now we have the behaviors and now we have the environment called as a series of test cases so now is the time to think about data structures and the actual implementation so when we activate user you should check whether it is already activated if it is we should throw this illegal State exception right if not we can change state to activate it so let's let us create a new data structure let's let it be an atom usual state I guess initialize initialize activated deactivated and at this point we can say okay my state is activated the invariants as far we need to have a feel for that private user state state and let us initialize it with change alive for the very beginning if it passes then the current state is of course activated right in here if we try to deactivate already deactivated user then something is wrong so we should throw new illegal state exception and it's not we can change state safety to either state deactivated fight cool technique then so there was an environment that says we cannot change Nick them if the user is deactivated so we could reactivate it similarly for later set exception if not nickname should be equal to new nickname right we don't have this nickname so let us create that seals nickname and at the very beginning it can be empty string against cool so we have to connect thing we can return it when we are asking our objects our user about his nickname and two more methods I think there's a type of you is be activated so to a method slow to implement these are those so it has activated fit simple if I were said is equals to activated and say here right um if States is equals to deactivated let's run the test again I hope this time it will pass or at least top of them in fact all of them are perfect cool so this is our domain model and but the main model is useless without any kind of precision so much right so let's create some repository for that so we will create a new path actually it will be an interface because we will have a couple of implementation okay so we have a new the repository interface and it will be very simple so which has exposed to behaviors we can save in user and we can load the user by we can find C in PI I guess UID right so this is our contract I will use the repository interface and let up interment apps with very simple in memory user repo so I think we can stop him we can store those users in the hashmap private final map of UID as a key and user the value users should be equal to a new concurrent hash map like this as we are this is pretty simple right when we have said MOOC we should just update the key user stood user get a UID and user and here also your attorney now if this if it's empty it's not something which is under this key type it's really work I will create a small test for that because have different implementations so we will need it this far this one is feeble so I get the SPECIAL pass that name it to usual repository test and my test case of a CEO is a gas should be able to say it and note using right if we can do that then our we blow basically should be working so let us initialize a new repo here in memory the repo right so given we need random UID to create a user random UID and we need some user equals to new user with this UID but also we have to change his state we for example activate him and we will change his nickname so some user changed nickname to gain balance and now the time to save user so when we try to save our himself said some user and we try to load him again by this UID then I guess close it should be deactivate to be activated and loaded nickname should be equals to Barney let's check what else works I hope it will it would be wrong it's really simple test yeah it's green cool so I know it's pretty simple despairs but we'll be needing that whatever you will be changing this implementation to events or thing basically we want to we want this test to be green and to be still green okay so if we take a look at the user the behavior it exposes like activate deactivate change nickname too we can see that basically as we have we have said there was a behavior exposes a message as a method call so the signal I can send to my object protected by some invariant if it doesn't pass basically we are we tell me NEC k to our to our client so I'm sorry if the comment you want to pass to my object cannot pursue but at this point when the invariants are that will be invariant fast about all of the in volumes basically it's a good size of a TK and here we have state change at this point we are changing state this state change with laser caught by for example if we are looking hibernate or any other or and this change will be would be would be seen by dirty-checking mechanism and store in our database as they ask you a statement so here we have we cannot deny that the comments has happened from this point because there in value of the fossils at this point there is an even even as a past event that something has happened so this is a way to find your even in your application these are basically the state transitions that that are the task after the invariant so these are the events this is the event and how to find the name of the event so I always try to extract this method let's go for example the new of the change in claim the same kill this is the method this is the this is the behavior of this is the invariant and this is the the state change so I try to I try to ascribe the method from this point and try to name it it's hdk so i guess i can use back then for example user name change so at this point when we have this method basically this name is the name of the event if you want to capture in our code this is the nail name the name of the even so now we have the events now we need the content of that even what is the comfort of not even the content of the event provided for us for free by our IDE so when I did extract method everything that went here is the content of our event so basically I can say that our event I have one big parameter here that is an even so at this point we have only 100 meter but imagine there would be like four or five all of them would be captured in one username changed event and you will have a new user name changed event and the content is of course unique name and also it's good to have timestamp of everything so I guess it is instant death now so let us create the trap strange new nickname in instant when and we can bind parameters for fields and we will be needing a getter hold up nickname come on right let's go back to user and here we can sign event get in the meeting now we can repeat that exercise with every behavior we have for example deactivated we can say okay user deactivated right and here it will be new users deactivated this even carries only time sense we can create the staff and by informative so field and similarly we would have same the same thing we all have this parameter here we'll have the same thing with the activation right we can have either activated here and basically this is user activated instance god now I think we can compute a single deactivated because it would be the same to end with with the quickl so yeah we have user activated here we doesn't go by yr because we have to add parameter to that method so at this point if we take a look we have the behavioral invariant and the ACK the state transition and the user and the event is being emitted here so this is the way to find event system so by the way let us check whether they protest for user still mr. works if it's the win I hope it is and that will go like go through with their events or things what exactly we have to do is we have to somehow and get rid of that dirty-checking manganese that would be would be enabled by for em and we we have to solve our changes on our own so what are our changes our changes are those objects right these objects represent represent the main object that is being changed so I think we can keep them in an internal collection let up create we can create a marker interface for all of them I think it can be called mainland event or changes equals to new array list right who have to report a scrap you don't have to mind is when to let us create that it will be an interface and this interface should only provide us a science type of an organism so for example instance of field F and now what we have to do is you have to have to implement this interface in our domain event implements the main event and this is because we have the times up here so we also need when the same with user deactivated if we go like this and we implement too many balance this is similar we can implement this method and we will return will be returning when as well and the last one is your name change should also implement the domains and we can use amend those methods and return when here so now what we have to so we can do we have to import list we can anytime the state is being changed we can say that okay I have a new change up is they're activated thank you changes up is a deactivated so anytime someone has changed my state I had to add this change to my internal collection of changes changes then he will same event to make it similar I will name it user name changed okay cool so why we do that and because now we can we can ask our object if it's dirty or not if it's change or not whether it's delcie we have to check if our internal collections empty or not so now is the time to create a set of the second repository you can complain that one and we'll call it events or sync even toast user repository and this is the tricky part because what we have to stop you even so scenario we are not allowed to store state so we don't stop user instead we're storing only the main events for this of the domain event from the very beginning when our object was born so how it looks like the real example I had a slide that said how we re creating stage in even choking scenario so basically we go the event stream which is append only log of immutable events and we have to we have to have an initial state which is basically menticles right with this empty constructor we apply again this object a first occurred even for our lock so with this in this case if user created and user create that carries one information that the name is John so we are mutating our state from returned by this construction we are taking code name an electronic a new state and we are plying the second event so we are with mutating state again we are changing sending the active flag the true and we are returning home baited state we go to the 13 and so on so forth absolutely very end this is basically what evenflo think is about if there's anyone familiar with special on programming this is basically left fold so we are consuming the stream of events and producing the very job so we progress should be familiar with that content because there is something which is called get and get work exactly the same or databases underneath they have production law which is basically the same concept it's nothing new how things will end up in our code so let's think about it we have to use them we are we were solving States now we are not allowed to do that so what we have what we have to do we just have to append the new events from our user right when when someone is calling safe so what this is the Delta checking my honey if it's empty we will not add anything if it's not empty we'll add new changes that's it end of the story so let's get new changes from our user get I think it doesn't have to get on from Apple we have to create that yeah it's on changes man I would like it to return in with a little copy of that so that anyone no one can change it right so we have the new changes we can have current changes basically because we have them in our map this is user dot get kettle default because if it's empty we want an empty list and the current changes this is get by UID user gets you ID or an empty array this what we have to do you get to append new changes to current changes so add all new changes and we have to put I'm both current changes in our map that's it but now we have to also inform our object hey you are not dirty anymore so please slap your changes basically it's the equivalent of trash in hibernate for example we are flashing states where your object is not dirty animal so we created that metal shear and it should say I guess changes don't empty it dot - so clear again yeah but feel so we are cleaning the internal collection of changes and that's it that was their impact the tricky part is how do I create a space here so this is basically this left for that we have to implement that we have seen on the slide so I guess we can say that if our map does not contain the new ID basically we don't know that object so we can return now right you just get a contained key if it doesn't contain return now if it contains please return new user that is being recreated from all the domains even from the very beginning for this left fault so let us slide the factory method for that user don't recreate from UID and we have to pass all of the events we have to pass me by ID to initialize an ethical and default factor but also we have to pass users and get our list of events we don't have that backup so we have to in the melt that would be static we create from UID and list of the main event and this is the tricky part in the Java 8 because Java IDE doesn't support left falls out of the box we would have to play with that that's why I prefer to use one liner from Java flying here and looks like this Java flank Travis blank or collection from collection list all of the main events within in products and basically as I said left fall from the initial state which is new use which is initial state is nothing more than new user from UID and methods that will treat each event accordingly to its type so this is the basic basically the way that we know okay that was user activated I choose mutate my flock or my stage this is user name change I should mutate shrink nickname so this is the one method that should know how to handle each event so let's I think we can call the top method handle events and we have to internment that method it should be returning user so mutated user the main event and the argument and yeah this one compile and now we have to run this right this method so basically I do a big if statement or switch statements or instructional way so let us keep typical functional it would be patronage so we have to patent Mars our events so we can again use camouflage we can putter much and this pattern of free cases case 1 would be obscenity instance of if it's in terms of user activated craft and we have to run a method that will mutate state and we have this much already there because we did it after even before talking about events this is user activated we did this method we implemented that matter before this should be returned something and you a misstep and here we have to import yeah it stopped complaining because I don't know why but see ah because user activated should return mutated state and at this point doesn't return anything so we have to change our method to return this state exists right here and here as well and also here I guess was it metal here yeah and we have to return this because every invitation should ritual mutate state because we have to go later on with the left foot yeah now it's compiled but we need two more cases from in here right so let us copy page that we need Thomas here I guess yeah and if it's usually deactivated calf these from usually activated and if it's activated man please run if you see the name change please run this metal site here we have to change it oh my god to user name change okay hopefully it's compiled this is what I like in functional programming what is compiled it was a big jump this will work so let's see now what we can do is we can go to is a repository tab and we can change our repo tests to to even closing new even source repository and now lots of times let's see if it works or not if it's green it's green so as you can see we implemented even sourcing with couple of lines of course it's in the mall but it could be easily saved to a database I clearing genome this system and even so this was fairly easy what is the magnetic of having this this architecture audience protection but this pattern so first of all take a look at this slide those for example um there's this app and unlock of immutable event so this is natural audit log of our domain right there was user created to activate the doodle change the name change user deactivated and so on and so forth it's not rule out the clock to us how it works but we can prove because this is out o'clock from which we can recreate state but we cannot be invalid that's one single point of true so this is one thing second thing is that those preventing us from reading the state for example up till this point so we can go back in time with our state Jess I can adjust it as we can do wait why we do check out from heat from historic comet this is the same pattern here so if we go to the to our office on Monday and see bunch of the exceptions on today and we cannot replicate that mark because the state has changed we can easily create change from husband by reading the internet stream after your family you know what I was writing the men's app because it's certainly easy in this scenario I think we can incorporate that method and we will add a new method that will recreate state from their specific concept so we'll find a new user add when maybe it was a good name at time 10 20 yeah this is basically which book this should be looking same as the previous network but we will not consume the whole the whole stream but we have to we have to cut our stream at some point so we can do our swim and we can filter all swim event and we are interested in even that happened not after the timestamp so before I understand or at times them oh I think you feel if we write like this even those accused add is not after timestamp and we collect that to list collect dot list I think it will work to prove that you can we can try-try the text for that so I think we can copy/paste this scenario and we will play with time a little bit so I guess this is named should be able to load state from historic timestamp so given the right D and some user user it's activated user changes his name we are saving the user and let's say from one second set path it's not a good idea to use sleep in a unit that I know but just for the sake of the of this example and some types of paths and let's say the user changes his nickname again connect them to jog we don't need that then basically if we try to log the user again so 5 by UID at this is basically current state so yet making should be equals to John but if we try to load say from their history so fine you I dance dot now - - English once I can send a little bit like this I guess then I know what's happening because usually positive in interface so we have to cast it here like this now we can use our method and our our state from the path setup okay nickname at this time was Barry let's run this test let's see if it passes if it passes that we implemented basically going back in time oh it's not passing what happened expected John and should be buried here John and should be bad the current issue because we didn't save our user again right so we have to of course when you change them to John we have to save our user in our repo some news that will explain and now I hope it will pass yeah fingers crossed it's green cool so this is the way to implement events awesome basic events or something and just in memory of course we should do that in their tool and normal database all the time to think what we can do with those even so for example we could we could we could edit of even to some external component and we could create a scenario like this as we have user service basically the service description just created and some other cells is called UI and message broker in between so we will try to implement that right now what we will do is we will create a different system UI and for example there we could store we could get those event and create some reporting mechanism we could create SQL the normalized reduced in order to have fast reach we could create hashmaps to get very fast with we could create a new photograph for example to have social connections between our our users and so on so forth this is basically the concept called common clear responsibility segregation and it setup not always the motor you used to write say to a database is as performant as it should be in regards to do the situation when you reach the state from your from the database so if you want to know about more about it there's a second YouTube also on the Springbok there was also a famous Twitter story because they actually forgot about that and they used third normal form involve reading and writing tweets to the database and first normal form is optimized for we provide database because it doesn't get redundancy so this is basically what we will do right now so to do that we create second second service I will connect them by think of three okay so Sphynx out stream is a marvelous core which helps us in delivering micro services spring book in MOOC applications the basically talk with each other by the means of infrastructure that is actually a very important stuff because it's so easy to use that it's almost we cannot me wrong could think of cream so it operates on an abstraction of a channel so the channel is abstraction abstraction that connects to micro-services by the maintenance of message broker and sprinkles theme comes with three predefined classes of had such naming and to connect through some channel so first of all its its source I think this one so says that I connect to one MIDI channel which is output from my application that's why it's called sauce so basically I'm the producer to one even dream life there's also a thing class which is basically familiar but another way around this is one input channel so I subscribe to one event stream and there's also processor which basically is both so process so stink out stream kill with basically extent certain things so it has input and one output channel so what you have to do or what we have to do is we have to enable here this is the first up to use drink out stream we have to enable some channel binding one channel so our binding in user service would be source because we said we are producer to one event she saw strap yeah in podcast yes so we it was the first step to label binding to so start which has channel named output what you have to do next we have to go to the properties file and we have to set up three deals income stream I had bindings and my banks the name of the channel which was output destination will be the name of the for example Casca topic or a BTEC mq exchange let us name its users for example so this is the way where we we were saying that output obstruction the tunnel which is an obstruction it implemented by some a contact in our infrastructure no message broken for example caca topic ok or RabbitMQ exchange the second step the fourth step is to check whether we have something on the clapper if we have caca thousand Acosta then sprinkle team will try to correct the casket of it some users if it's rabbit then it's rabbit and you can easily play with that with slides having an enterprise in different different implementations it's really cool so crack up check enable binding check and application properties output cessation to the auto check now we have to run some code that will let us create messages and send the messages their usual topic in Kafka okay so we have to create a new craft I will name it and publisher website let's make it spring component and basically it will have one method I guess public void send event the main event event I think it's a good place to lock that event as well so let's select forge a login form about and an event right and what we have to do is when we announce the method with this publisher to channel source output output then any time we call this method sprinkle stream will deliver this method to deliver their return parameter very temperamental from that method to this channel so we have to return that even yes this time it will work now we can play with that and do that I think a good place to to publish those event will be even source is a repository so where we are storing them here we can also here inject pilot final event publisher and up constructor parameter like this yet we have even publisher and ah we have to make it spin component I guess become one cool and for every new event we can also publish up to Kaka broker so new changes so they're pending changes for each even publisher even publisher event additional send event event I think we can break up yes yeah it's one format for Nigel yeah so we can publish even and the last thing we have to do is we have to somehow create random users so that we can see something in our output application so that's create random user you dos it will be user user new user you random ie palette fail you will activate this user we can also I get change nickname to main stop new random next into right in the pan comparison vanish way to main people but for the sake of the example okay and we have to say that the user as well so we have to inject private final user repo here it has one implementation with extreme component so it should be okay user repo if you have to save user and this will generate two events right through even to Kafka and know what the time to run kappa i guess so capcom needs zookeeper to work so first of all we have to run zookeeper and then we will catch up okay so we can run after with this script hope it will work because there are some problems sometimes with with windows in Chaska I think it's connected we can go back to our application and basically what we can do it now we can run this application ah these random users no one calls this metal so I guess what we can do we can make it scheduled I guess every two seconds will create some users we have to an able scheduling here right now we can run this and I hope it will connect to cast hands we'll send someone to meetings not random but even connected with Daft old but see the log statement is very important and it's trying to mapping something yeah it's connected to chakra and yeah we are sending something see here we are sending some random even to Kafka so connect if elected to cast practically we didn't have to do anything so sprinkle stream leaves us without without even thinking about all of the infrastructure about them we need to do to connect to the message broker of course we can control anything if we want but if you don't want there will be a bunch of default parameters it's really cool now at the time to go to the second application basically which would be this UI application for users and we can recreate this exercise here so we will connect the Kappa broker but we have to enable binding and this application will be saying to our in our you will be seeing in our case because it will connect to one channel as a listener so it is a consumer point of entering what's more we have to go to application dot properties and we have to say real spring code team I have finding my terminal same input because we think ought to think we can see this same input and destinations user so there's there is the place where we connect those two applications right by this by this parameter users it will connect to users topic in Casper if we have proper Akasha but we have chakra so this is checked this check and an abundance check last week we have to do we have to implement the method that will be called every time and even comes so we can run it raineth public port and a long held event the main event here and you know what we can copy/paste or even to make it quicker from the pivot application the main event is activated yeah we can have it here and Cali paste it will need that I guess copy paste it to our applications yep and now we have yet we have no many burn so we can go and let's add we can log this even for a while but this is the place where we will be handling even before we see an event right this doesn't say anything unless we are now to do this of this little notation so the notation tells pinnacle string to help at once method to involve its message every time there is something on our channel and we have to certify channel of code this extremely signal to channel input let us double check this is input channel its users and then I was different up in our first application we had we should share out channel to users yeah so I guess if we run this application right now it should get be getting even so let us planet basic do this would be the place I can make it small yeah this would be the place where we can play with our events right yeah we are getting even to see every two seconds you are getting some even so how easy it was to connect to applications with think out stream and duty of data some easy to change to applications that have different process right now like rabbitmq binder it will talk with raveling to it's really cool but this is the place where we can play with our we can do reporting with reporting we can do complex event processing we can do event swimming we can do SQL normalized protection so with models anything we want we can have multiple projections of the event stream this is this is the whole idea of having even driven systems in the first place right so we have it connected the beauty of that is we you do have to do that math regarding in the infrastructure of our broken right I just want a car that's it and I keep them cold this is provided but also ask for free so what we can do it what I see that teams are trying to do nowadays they try to implement complex business processes in an even driven manner let's let us say we have product like this that when user is deactivated the payment has to be canceled and when user when payment is concert she burns has to be counseled and then they even have to be sent and so so forth this can go forever right there's a complex business process that we have to implement what I see is that people try to do is they try to implement it like this like we have a noodle service which empty event second bounded contact or second thing good micro service gets the event process it and sent another event that other event triggers yet another event and so on and so forth this is so-called event waterfall this is nothing that nothing with this being for any good because things are so good because oh I can now track this process how I can change this process how a developer in developers can come and say an answer to a question what the process of users activation looks like it's basically spans for five solid contexts it requires synchronization of settings it requires knowledge of five things and basically the maintenance of that is terrible because any change requires again couple of couple of deploys and so on so forth so this is not a good idea to do the better idea is to have something in the middle so I recommend this kind of an architecture which is called process manager this this question mark this big question mark in there in the middle is basically something which is called process manager you can really read about it for example in integration enterprise integration patterns fairly well-known so what we can do here is we can react by getting an event in our process manager and then we can span multiple comments or even different context on these comments you can be west coast or they can be also our message messages to a message broker it doesn't doesn't make make any difference but where we want to change the logical futures activation we have to test for a component here we have to tap this big question mark and for example and we want to see how the user of the activation process looks like we have to go under one code base provided like good API I've here here and here for counseling and sending emails imagine that every email that had to be sent in our domain will be processed by this thing by event so this team will only have to run event handlers for every domain even that requires email so basically they will hate it they will hate us soon or they would be flooded with change requests it battles one API here that says ok if you want to send email invoke that and phoned or sent me this message by a message broker that's it so to cut it short do not implement the business processes even driven manner for even waterfall we can do better with this and the cool thing is that even that sprinkle stream helps us in writing this process no needles and it's very very easy and the last thing to do is to write this process and since the manage process in our UI application so let's say our UI now it becomes now it becomes we can basically close it you see it works now the you are the state becomes our process manager okay so what do I have to do it now it has to connect to one two three four channels right four channels so it can't it's going to say enabled binding scene because it's not think anymore but we can write our own cutters that specify what channels do I connect to what channels do my process manager connect that's my process manager connected connects to so let us create this this discuss it's gonna be it's an interface we can call it channels and here is the place where we specified the channels that our application can bind to so it's like more than single sole source of processor but for different cases more complex cases right so we know that our channel our application should listen to event from users so this should stay right so let's say input I have one input channel called users and it's basically subscribable channel named users i have also one free output channels one of them is called payments let's say this method channel payment we can copy paste that into much and we can say that and instead of payments we have different output channel which is shipment shipments okay I'm miss parented with you again the last child would be I guess communication so one more time one into channel computers three output channels one of them is payment and then shipment and then communication okay if we take a look one more time at me at that at the slide basically like this payments typical communicator and user service coalescence reusing service and we are talking to payment shipping and communicator so now we have to go here and say we are not amazing channels for a binding full thing but instead we are using our channels okay now sprinkle stream will try to identify this channel but second thing we have to do as we remember we have to go to properties file and basically you don't have input channel right now because it is named users we renamed it we use name isn't this is basically here right this is here but we also have three more channels one two three mob them is called payments and let us say should be cut cut of these payments and the same here with shipments and communicate them okay so this is shipment and this is shipment and here I guess would be communicator commutation so let's double check communication shipment payments users communication shipments payments user I think we are good to go but go back to this application so now what we can do at any time and the right domain even comes and is this event which is user the occupation we should start the process right so if event is in terms of user via Asian user deactivated dance please start the process there is nothing wrong here I think it should be like this oh good yeah and the beautiful pink upstream but we can also easily test that so let us first to do the test can create test for our our code base let us recall it end-to-end test we can put it here it would be spinning book test and complex configuration would be of course our application class and loader would be before being boot contact over so I think that the behavior that we have to test is as follows if user when user is activated then three comments around our prom should be it should be saying payment the channel come at the payment channels flow and so on so for but to make it quicker I will just end like this and another sweet spot oh we can actually we can use our channels here these are this is thinking so we can use it and in the one section we can simulate that something comes to one of our channels we have one input channels called user so we can say hey well on the channels make users alter the message new generic message and it is new users deactivation now then basically free outgoing comment we're phone how to check this is really cool right we can simulate the function tell me something came to our system but we have to check whether something was out from our system as well right so how to do that mmm comes with that I've been called message something message collector yeah message collector and what we can do is we can call that an outgoing message in the blocking queue so we'll have three blocking kills one for each channel with each outgoing channel so we can we should have not into payment docking Q I can compare that gotten few shipments and log into a communication communication and in a before section they're set at least equivalent of unit before we can initialize those so payment is I'm telling right now message collector to store any of going message for channel payment in by docking Q payment the same I will do with the shipment for our channels shipment and the last thing communication message collector dot for channel channels we really easy right it we are not all a good to go with the assertion so we are expecting that on payment channel who proposes looking to you can recap the tallies of strings this table contains let's say counter payment coming I know that the pain that the comments should be also and independent cards but to make it quicker so we can cover the strings okay the same we have to do here that shipment for a string contains let's say council shipment I hoped this was the process that we are demanding and communication when the opponent is not in queue as think well it contains ten nine whenever you have this that I think to fail because we didn't implement anything yet but Chuck will track what that the context is up and everything is okay and then expected failure is their expected failure is there so we expecting this to fail right but something else as fail noble name input is defined Y so arm it says up there is some of our channel called input and it shouldn't be like there because all of our channel name is unnamed users famous ship as the communication bar here what you are listening to a stream it still says sink input it shouldn't be like this it should be users right now we can rerun our test and now the context should be up at the test should fail this is not this is not this I got the application excuse me we're on the test Jacob Amos yeah Jacob wanted it one of the audience members were seeing you at a typo on payments payments I don't recycle maybe he fixed it it was on number 28 he said pleasure named Haman equal payment equal and message collectors dot for Channel dot payment absolutely so is the test I get thank you very much it's like this good call thank you very much it should be like great whoever whoever that was send me your Twitter handle and I'll get your free t-shirt thank you thank you so now we are having pointer exception which is I guess expected because we are contain on an empty thing because there's nothing from the outgoing comments in the payment channel so if we finish this this implementation here I guess we'll be needing a new class that we'll be able to publish to channel we can copy-paste on the previous examples from the users event for the show and we can go and have it also here let's say it's common for the show its current position one method will be for channel users not users about payment and it will be named cent comment to payment and we already assumed that payment domain even that will be sending commenting streams also we have to check that and should be comment yet and we if we copy paste that two times we should have we should set your shipment I hope I'm not having typo right now payment shipment Sinclair payments should come onto shipment and the last one send comments to communication right cell come on to communication so this is communication yep I think we're ready to go communication shipment payments come on to payment shipments and communication no typos I guess he'll now now I will be much more careful hey cool so we can inject our publisher here final-final how did I name it comment publisher come on publisher we can add some structure parameter and here we can say hey if even if user was reactivated then I said I had to do several things right I have to a cultural payment payment and I have to also I have to cancel shipment so that he doesn't get anything for free can't shipment also we have to publish your comments through our communication Sal made stupid in the name of the trauma excuse me for that but I will leave it like this yeah let's run the test again this time I'm expecting it will be green because we implemented the process right let us yeah it's green cool so to double-check that we should we should we should run this and different tests right we should say that one user is activated no comments are wrong because we don't know we don't we don't want to counter Thema Keynesians activated no comments are from and user channels and users yet either activated message then basically we can get rid of that and we can say that users but users but payments is empty so they're outgoing someone for penance is empty same with communication is empty and same with siblings let's run this test I hope it will pass maybe how easy it is to test and implement a simple III I agree that this simple process is natural but it's really really cool how think of fear enables us with such tools like this method collector to check whether our black box get an event and we told some comments so that would bleed I guess there is much more to talk about scaling horizontal scaling and faster on you can fail over that I wanted to talk on spring clock you can find it but we don't have time for that all of the code that is there will be will be shared and will be soon and my kids have a chance here if you have any questions regarding the code regarding the presentation only feedback you want to provide you can drop in lines here or casually here attacking on a Twitter I would like to thank you very much for your time I appreciate your time there is a question I think there's the first time I see questions you with virtual Springwood I think 1.7 let's check it one point one point five seven one point seven five four one point five point seven so one more time Thank You boom I appreciate your time thank you Peter and I'm down you're welcome you're you're welcome yeah Jacob so we've just got a minute or two left here before the web the the presentation system is actually going to shut us down so um this is a really good time folks to click on the resources attachments and links section of you user interface as Jacob mentioned the source code and where people have asked the source code for this webinar is located at github.com pilote PL right up there you can see the URL we'll put a link to that on the replay page and since we unfortunately don't really have much time for questions what we're going to do is Jacob is going to go in to answer your questions and we're going to post them as an attachment to the webinar replay so the same URL that you used to register is the same URL that that the replay is on and we'll have answers for you hopefully by the end of the day latest probably tomorrow depending on what Jacobs got going on today's but we'll get those answers for you as quickly as possible and then if you are looking for a spring cloud stream bits obviously there's a in the attachment and links section there's a link to the spring cloud streaming project page where you can find the main maven and Gradle coordinates if for some reason you're stuck behind a firewall or 20 layers of proxy servers or on some sort of closed or military network and you really actually need HTTP downloads you can get them off of repo dot spring dot IO but if we don't make it easy for you to be honest but it is possible um so encourage you to use Manor or Gradle whenever possible for sure um let's see we we have a minute or two left um now would be a great time to give us some feedback if you would take a moment to go to the votes section there's a poll in there and then you can also give us some some feedback in terms of rating our presenter and telling us what you know you'd like to see from us in the future um so yeah please we'll take I think we've got enough question and enough time for just one or two questions I'll take one of the most top ones well yeah while we're doing that if you could please do the poll where it's under the votes votes for polls and the rate the feedback that would be great I'm very much appreciated so um Jacob we just have time for like one or two questions on is Kafka the default stream system like how would we switch to Kinesis or active you so as I already mentioned that think of Simcoe through some predefined binders so for example Kafka or rabbitmq I don't know about Canada I hope I think that I like outgoing implementation regarding for example Google Papa the thing is that only the only thing we have to do is we have to change our class two different binder that's it that the pure beauty of sprinkle stream and depending on how many planets there are in cemented III myself I used two of them a France lab thank you but as I said already I'm going to presentation of different ones I know about the status but this is the way to change the default stream system so there is no know something like like default stream system you have to have to provide some binder on the crossbar cool ok we really get a guess one more thing yeah not really go get it off in one minute so let's wrap it up yep ok that's wonderful I mentioned that the code is not barring yet on my gift wrap becomes but it's really done like one or two hours after the session ok because it's just with them so I didn't intend to put it on there very good ok thanks for that yeah alright everyone so um we're gonna be kicking off thank you so much Jacob really appreciate your time and the effort you put into this so check out Jacob's github repo and if we didn't get to your question we'll have answers for you today or tomorrow that same link that you used to register join us again really soon we're gonna be kicking off a 4 part 5 part series from Michael plude's at noq in Germany on domain driven design which is going to be awesome so keep an eye out for that we'll be posting it on the Twitter blog thanks everyone have a great day evening or morning depending on where you are and join us again soon for another webinar on the program Jacob thanks a lot thank you see you soon bye bye
Info
Channel: SpringDeveloper
Views: 22,864
Rating: 4.7941175 out of 5
Keywords: Web Development (Interest), spring, pivotal, Web Application (Industry) Web Application Framework (Software Genre), Java (Programming Language), Spring Framework, Software Developer (Project Role), Java (Software), Weblogic, IBM WebSphere Application Server (Software), IBM WebSphere (Software), WildFly (Software), JBoss (Venture Funded Company), cloud foundry, spring boot, spring cloud, event sourcing, EDA, event driven, eventing, apache kafka, rabbitmq, spring framework
Id: LvmPa7YKgqM
Channel Id: undefined
Length: 78min 8sec (4688 seconds)
Published: Fri Oct 06 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.