1 00:00:01,390 --> 00:00:06,890 Let's go ahead and put our events handlers together for the Postal Service and the common service. 2 00:00:06,970 --> 00:00:10,030 So I'm going to get started by going first to my post service. 3 00:00:10,030 --> 00:00:15,400 I'll find the index such as file and then turn the very bottom the file but right above the apt listen 4 00:00:15,400 --> 00:00:19,050 line I'll add in a new post request handler. 5 00:00:19,180 --> 00:00:23,390 So this will be asked post to slash events. 6 00:00:23,480 --> 00:00:26,020 We'll get our rack and rest in their 7 00:00:28,910 --> 00:00:34,250 and then remember this end point is going to receive any event that is coming over from our event bus. 8 00:00:34,260 --> 00:00:38,460 So right now inside of our postal service we don't really care about any events that are coming over. 9 00:00:38,530 --> 00:00:44,220 But let's just go ahead and log any events that we receive just to say hey this event exists I'll do 10 00:00:44,250 --> 00:00:47,580 a console dot log of received event 11 00:00:50,910 --> 00:00:52,970 and we'll just print out the type of the event. 12 00:00:53,070 --> 00:00:56,550 How about wreck dot body that's gonna be the actual event. 13 00:00:56,590 --> 00:01:01,660 And remember every event that we receive we said that it was going to have a type property dial up print 14 00:01:01,660 --> 00:01:06,160 out the type of event that we just got after that. 15 00:01:06,190 --> 00:01:11,320 I'll make sure that I still respond to the request that was issued just to say hey we got this. 16 00:01:11,550 --> 00:01:16,700 We'll do a red dot send of empty object just to say yeah we got this event. 17 00:01:16,730 --> 00:01:24,060 Everything's good to go so now repeat the same process over inside of our common service as well. 18 00:01:24,070 --> 00:01:29,700 They'll find my comments directory index dot J.S. inside of there we'll go down towards the bottom and 19 00:01:29,700 --> 00:01:32,250 right above the apt Atlas in line. 20 00:01:32,250 --> 00:01:35,300 I'll do an app dot post for events 21 00:01:38,280 --> 00:01:44,740 we'll do a console log of event received and wreck dot body type 22 00:01:47,640 --> 00:01:52,920 and we'll do our resource sent empty object OK. 23 00:01:52,970 --> 00:01:55,400 So that should be enough to test this stuff out. 24 00:01:55,420 --> 00:01:58,060 Now we're going to really see the entire process here. 25 00:01:58,070 --> 00:02:02,580 We're going to see everything from start to finish if we take a look at our terminal after we start 26 00:02:02,580 --> 00:02:08,790 to we met some events we should see some console log coming from our post service and the comment service 27 00:02:08,850 --> 00:02:14,590 and they should say every single time they receive some kind of event so let's try to test this out. 28 00:02:14,720 --> 00:02:17,610 I'll go backwards the browser and find my application. 29 00:02:17,610 --> 00:02:19,370 I'm going to refresh the page once again. 30 00:02:19,370 --> 00:02:23,850 Remember every single time we make a change to our code we dump all of our data. 31 00:02:23,930 --> 00:02:30,700 I'll go ahead and create a post of say new post and submit if I refresh. 32 00:02:30,730 --> 00:02:31,720 Yep there's the post. 33 00:02:31,720 --> 00:02:35,180 But more importantly let's go over to our terminal. 34 00:02:35,330 --> 00:02:40,700 Here's my terminal window and I can see that we've received an event for post created inside of our 35 00:02:40,700 --> 00:02:42,190 postal service. 36 00:02:42,190 --> 00:02:44,180 This terminal window right here is from my comment. 37 00:02:44,390 --> 00:02:50,150 And we've also received an event of post created or event bus is still during an air down here. 38 00:02:50,150 --> 00:02:55,340 That's OK because remember it's trying to send a request or this event over to our query service which 39 00:02:55,340 --> 00:03:03,390 does not yet exist let's also try to create a comment and just make sure that the event of comment created 40 00:03:03,510 --> 00:03:08,600 is being sent to the post common service as well so back inside my browser. 41 00:03:08,610 --> 00:03:14,880 I'll put in a comment here of a comment submitted I'll refresh. 42 00:03:14,910 --> 00:03:16,320 Just make sure I see the comment right there. 43 00:03:16,560 --> 00:03:18,940 And then finally I go back or maternal. 44 00:03:18,990 --> 00:03:19,620 There we go. 45 00:03:19,620 --> 00:03:25,440 So I've got my event of common created and common created. 46 00:03:25,610 --> 00:03:25,920 OK. 47 00:03:26,050 --> 00:03:26,980 So that is it. 48 00:03:26,980 --> 00:03:29,560 That is the full communication cycle. 49 00:03:29,560 --> 00:03:35,800 We have our postal service sending events over the event bus takes that event and sends it off to service 50 00:03:35,890 --> 00:03:39,210 one and two and then a little bit. 51 00:03:39,250 --> 00:03:43,590 Not quite yet but in a little bit I'll try to send off to the query service as well. 52 00:03:43,660 --> 00:03:48,610 So in theory if we had any kind of data dependency or more strict data dependency between our post service 53 00:03:48,610 --> 00:03:53,520 and common service we could watch those incoming events and deal with them in some way. 54 00:03:53,770 --> 00:03:57,370 As I've said several times down the last couple of videos the post and comment service don't really 55 00:03:57,370 --> 00:04:00,040 care about the events that are being emitted right now. 56 00:04:00,160 --> 00:04:03,900 But now that we've got these events coming out let's start to put this query service together we'll 57 00:04:03,910 --> 00:04:11,180 make sure that the query service listens for a post created or a limit created event starts to take 58 00:04:11,180 --> 00:04:16,250 that data and assemble it into some kind of usable data structure in the exact same way that we've discussed 59 00:04:16,280 --> 00:04:19,430 over all these last couple of diagrams. 60 00:04:19,430 --> 00:04:22,750 Where are they like this one. 61 00:04:22,760 --> 00:04:23,010 Yeah. 62 00:04:23,030 --> 00:04:24,200 Here we go like this one right here. 63 00:04:24,200 --> 00:04:29,110 Remember we're going to take all these events and assemble them into some usable data structure. 64 00:04:29,240 --> 00:04:30,770 So we're going to take more than just a moment. 65 00:04:30,800 --> 00:04:31,330 So see you. 66 00:04:31,330 --> 00:04:32,110 And just a little bit.