1 00:00:01,010 --> 00:00:04,290 In the last video we discussed the pros and cons of option number three. 2 00:00:04,290 --> 00:00:06,570 So this is the option that we're going to go with. 3 00:00:06,600 --> 00:00:11,370 There's a lot of changes we need to make in several locations to implement this entire flow so we need 4 00:00:11,370 --> 00:00:14,480 to make changes to the comment service and the query service. 5 00:00:14,490 --> 00:00:17,670 We also need to create the moderation service. 6 00:00:17,670 --> 00:00:21,050 I think we should get started by creating the moderation service for right now. 7 00:00:21,060 --> 00:00:22,780 It's a good place to get started. 8 00:00:22,800 --> 00:00:26,340 We're just going to worry about putting together a little bit of boilerplate for the project in this 9 00:00:26,340 --> 00:00:31,440 video and in the next video we'll start to add in all these additional events and add in some code to 10 00:00:31,440 --> 00:00:32,840 handle them as well. 11 00:00:32,970 --> 00:00:33,720 So let's get to it. 12 00:00:33,720 --> 00:00:37,260 We're going to create this new moderation service to get started. 13 00:00:37,260 --> 00:00:40,300 I'm gonna flip back over to my terminal. 14 00:00:40,390 --> 00:00:44,660 I'm going to open up yet another terminal window which I've already got right here inside my blog. 15 00:00:44,650 --> 00:00:52,500 Project directory and inside there I'll make a new folder called moderation I'll then change into that 16 00:00:52,500 --> 00:00:53,550 directory. 17 00:00:53,550 --> 00:00:57,060 I'm going to maximize this terminal window really quick as you can see this very easily. 18 00:00:57,060 --> 00:00:58,760 All the other terminal windows are still running. 19 00:00:58,770 --> 00:01:04,530 I'm just using a hotkey to maximize that 1 window inside of you're going to generate a new package JS 20 00:01:04,620 --> 00:01:11,540 on file with NPM in it Dash y and then as we've done several times before we're going to install a couple 21 00:01:11,540 --> 00:01:19,000 of dependencies so I'm going to get access express node Mohn. 22 00:01:19,060 --> 00:01:24,130 And in this case we do not need cause because we are not going to have our front end application make 23 00:01:24,160 --> 00:01:26,730 any direct request to this moderation service. 24 00:01:26,740 --> 00:01:32,980 So the course module not required this time around so I'm going to install that stuff and after that's 25 00:01:32,980 --> 00:01:35,330 all done. 26 00:01:35,450 --> 00:01:36,060 There we go. 27 00:01:36,060 --> 00:01:39,480 I'm going to pop that kernel window back into this tile. 28 00:01:39,510 --> 00:01:40,950 We're not going to start up the server just yet. 29 00:01:41,010 --> 00:01:44,670 Let's go and write a little bit of code and I'll come back over and start up that additional service 30 00:01:45,600 --> 00:01:52,260 so I can go to my editor here's the new moderation directory inside there I'll make a new file called 31 00:01:52,260 --> 00:02:00,870 index dot J.S. and then at the very top let's add in some different require statements so I'm gonna 32 00:02:00,880 --> 00:02:01,660 get express 33 00:02:04,330 --> 00:02:05,350 I'm gonna get body parser 34 00:02:09,150 --> 00:02:10,250 and I'll get access 35 00:02:13,170 --> 00:02:18,240 then once again create a new express application and wire up the body parser middleware. 36 00:02:18,550 --> 00:02:23,540 So I'll make sure I call Jason as a function all right. 37 00:02:23,570 --> 00:02:25,240 So what does this service really need to do. 38 00:02:25,250 --> 00:02:28,430 Well all this service does is watch for events. 39 00:02:28,430 --> 00:02:34,370 It's just gonna watch for that event we mentioned so common created whenever we see come and created 40 00:02:34,460 --> 00:02:38,780 the moderation service is going to need to emit the comment moderated event. 41 00:02:38,780 --> 00:02:44,450 So we really just need all we need inside this thing is one root handler just a single root handler 42 00:02:44,480 --> 00:02:49,700 for that slash events end point that we already set up previously inside of comments query and our post 43 00:02:49,700 --> 00:02:50,980 service as well. 44 00:02:51,490 --> 00:02:58,540 So inside of here we're going to add an app dot post or events will then take our rec and rez like so 45 00:02:59,410 --> 00:03:01,930 we'll come back to that root handler in just a moment. 46 00:03:01,990 --> 00:03:07,440 First let's make sure that our app actually starts listening on some port now at this point in time. 47 00:03:07,450 --> 00:03:13,440 We've got several different ports in use so as a reminder we've got four thousand four posts 1001 for 48 00:03:13,480 --> 00:03:16,610 comments or thousand to four. 49 00:03:16,610 --> 00:03:17,170 What is this. 50 00:03:17,170 --> 00:03:21,680 The query service and we'll use 4000 in three for moderation. 51 00:03:22,030 --> 00:03:23,740 So we will do an app. 52 00:03:23,890 --> 00:03:32,950 Listen four thousand three and inside of you I'll do a console log listening on four thousand three 53 00:03:35,580 --> 00:03:35,990 okay. 54 00:03:36,010 --> 00:03:41,050 Before putting together any implementation on this host event and post root handler right there let's 55 00:03:41,050 --> 00:03:45,220 set up our package not just on file with the script and just make sure that we can run this thing successfully 56 00:03:45,220 --> 00:03:46,710 at our terminal. 57 00:03:46,930 --> 00:03:52,120 Here's my package that Jason File I will delete that existing test script and replace it with a start 58 00:03:53,290 --> 00:03:55,810 and we'll do the Woodman index dot J.S. 59 00:03:59,480 --> 00:04:05,130 Okay that looks pretty good let's go and run this project so I'll go back over my terminal once again 60 00:04:05,900 --> 00:04:10,620 I'm going to find that terminal window that's going to be in charge of running our moderation service 61 00:04:10,680 --> 00:04:16,860 there it is right there and inside there I'll do NPM start okay there we go. 62 00:04:16,860 --> 00:04:20,570 So we've now got many different services running for our application. 63 00:04:20,640 --> 00:04:21,330 Definitely. 64 00:04:21,330 --> 00:04:23,310 Hey you know this is of course about micros services. 65 00:04:23,310 --> 00:04:27,210 So yeah we're going to create a lot of services just understand how to create them all and get them 66 00:04:27,210 --> 00:04:28,620 all working together. 67 00:04:28,710 --> 00:04:32,970 Look it looks like that is running on port four thousand three and we've got a good start to this moderation 68 00:04:32,970 --> 00:04:33,810 service. 69 00:04:33,840 --> 00:04:35,000 Let's take a quick pause right here. 70 00:04:35,010 --> 00:04:39,300 When come back next video we're going to start to add in some implementation for the events handler 71 00:04:39,300 --> 00:04:45,630 right here and make sure that any time we see an event of type comment created we do some moderation 72 00:04:45,660 --> 00:04:46,210 on it. 73 00:04:46,290 --> 00:04:48,270 And then eventually emit this comment. 74 00:04:48,270 --> 00:04:50,210 Moderated event in turn. 75 00:04:50,260 --> 00:04:51,060 So a quick pause. 76 00:04:51,060 --> 00:04:52,110 Take care that just a moment.