1 00:00:01,030 --> 00:00:05,140 As I mentioned in the last video we're gonna start to take a lot of the code inside of our nets test 2 00:00:05,140 --> 00:00:08,120 project and merge it into the coming module. 3 00:00:08,230 --> 00:00:13,600 We're then going to rebuild common publish it and then update the tickets project and start to use Natsumi 4 00:00:13,600 --> 00:00:14,550 server inside there. 5 00:00:14,560 --> 00:00:17,170 So let's get to it inside this coming directory. 6 00:00:17,170 --> 00:00:23,610 I'll find SRT inside there I'll make a new folder called events will then find the events directory 7 00:00:23,610 --> 00:00:28,040 inside of Nat's test and we're going to pull out the base listener. 8 00:00:28,190 --> 00:00:29,260 I'll do a multi select year. 9 00:00:29,270 --> 00:00:31,510 I'm also gonna get the base publisher. 10 00:00:31,540 --> 00:00:36,960 I'm going to get subjects going to get the event definition and that's it. 11 00:00:37,240 --> 00:00:41,830 The listener and the publisher are things that are going to be ultimately defined and implemented inside 12 00:00:41,830 --> 00:00:43,380 of our individual services. 13 00:00:43,480 --> 00:00:49,420 Because how a service listens to an incoming event like ticket created is going to be determined on 14 00:00:49,420 --> 00:00:51,160 a service by service basis. 15 00:00:51,160 --> 00:00:54,670 One service might want to take a ticket and do one thing with it. 16 00:00:54,670 --> 00:00:58,260 Another service White might want to take a ticket and do another thing with it. 17 00:00:58,300 --> 00:01:02,890 So we're only taking the first for inside of you're going to copy all this. 18 00:01:03,050 --> 00:01:07,220 I'll go to the events directory we just created and paste those four files in 19 00:01:10,260 --> 00:01:15,950 if we then go into that say base listener file we're gonna see right away that we get an error. 20 00:01:16,030 --> 00:01:20,770 So this is base listener inside of common we're getting an error because we have an import for node 21 00:01:20,800 --> 00:01:23,070 and that's streaming that's really fine. 22 00:01:23,110 --> 00:01:25,630 We have not installed no net streaming into the common module. 23 00:01:25,660 --> 00:01:27,020 That's why you're seeing the air right now. 24 00:01:29,170 --> 00:01:33,760 I do want to immediately add in one or two more events that I know that we're going to need right away 25 00:01:33,790 --> 00:01:38,950 when we start to make use of this common module or the update to it back inside our tickets service. 26 00:01:39,010 --> 00:01:41,500 So we've got a event here for ticket created. 27 00:01:41,500 --> 00:01:45,540 We're definitely going to need a event for a ticket update as well. 28 00:01:45,590 --> 00:01:49,680 So let's put together a event to describe that to to do so. 29 00:01:49,710 --> 00:01:52,680 We're going to first open up our subjects file. 30 00:01:52,840 --> 00:01:55,680 We're going to add in a new type to the thing of ticket. 31 00:01:55,780 --> 00:02:00,060 Updated and I'll use a subject name of ticket. 32 00:02:00,060 --> 00:02:02,850 Colon updated. 33 00:02:02,910 --> 00:02:07,890 Now we are not actually using order updated so I am going to delete that one just so we don't get confused 34 00:02:07,890 --> 00:02:13,780 on what we have and haven't implemented it's now I only have to get created and ticket update it. 35 00:02:14,190 --> 00:02:21,200 I'll then say this file and close it then also inside of events I'm going to make a new file called 36 00:02:21,230 --> 00:02:29,690 Ticket updated event not to yes inside of ticket updated we're gonna write out some code that looks 37 00:02:29,690 --> 00:02:36,110 very similar to what we just did inside of ticket created so inside of updated at the very top we will 38 00:02:36,110 --> 00:02:50,000 import subjects from subjects well then export an interface called Ticket updated event will say that 39 00:02:50,000 --> 00:02:56,810 this thing is going to have a subject of subject start ticket updated and will have some data as well. 40 00:02:56,890 --> 00:03:00,850 Now we've been kind of just assuming that these tickets and the data around them was going to be just 41 00:03:00,850 --> 00:03:02,440 the I.T. title and price. 42 00:03:02,440 --> 00:03:06,760 I think that still stands for right now until we realize that we need some extra information. 43 00:03:06,850 --> 00:03:10,930 I think we'll just stick with saying we're going to emit information about the I.D. title and price 44 00:03:10,930 --> 00:03:12,130 of the ticket. 45 00:03:12,130 --> 00:03:17,770 So if we emit an updated event well we probably want to include the updated information about this ticket. 46 00:03:17,800 --> 00:03:26,750 So once again just idea of string title of string and price of number. 47 00:03:26,890 --> 00:03:30,730 There is one other property that we might want to immediately add in however. 48 00:03:30,910 --> 00:03:36,280 Back inside of our tickets project if we open up that model's directory and take a look at our definition 49 00:03:36,280 --> 00:03:37,310 of what a ticket is. 50 00:03:37,390 --> 00:03:41,140 You might recall that a ticket also has a user I.D. property. 51 00:03:41,530 --> 00:03:45,760 We might want to add that into these two event definitions right away because there might eventually 52 00:03:45,760 --> 00:03:49,810 be some service that cares about who owns a ticket in particular. 53 00:03:49,810 --> 00:03:54,940 So let's add that into the event definition or ticket updated and ticket created in both them are going 54 00:03:54,940 --> 00:04:00,740 to add in a user I.D. That is a string so there it is inside of updated. 55 00:04:00,750 --> 00:04:07,590 I'll then go over to created at an user I.D. That is a string as well. 56 00:04:07,670 --> 00:04:13,070 ALEX Good Now one other comment I want to throw out there inside this coming module. 57 00:04:13,070 --> 00:04:16,860 We basically have everything just mixed up inside of this event's directory. 58 00:04:16,970 --> 00:04:21,320 So we've got the base listener base publisher we got a listing of subjects and then eventually we'll 59 00:04:21,320 --> 00:04:25,590 have a lot of different files inside of here as well to describe all the different kinds of events. 60 00:04:25,700 --> 00:04:30,250 If you want to come up with a different structure for this directory definitely go for it. 61 00:04:30,260 --> 00:04:35,000 I think that it doesn't make a lot of sense to mix all these folders or all these files together especially 62 00:04:35,000 --> 00:04:38,150 since we're going to eventually have several others in here as well. 63 00:04:38,150 --> 00:04:42,110 So if you could think of a better way of organizing this directory certainly feel free to do so. 64 00:04:42,110 --> 00:04:46,180 Just remember whenever we do an import statement you will have to adjust some parts. 65 00:04:46,190 --> 00:04:51,090 If you start to nest these files inside of some other folders All right. 66 00:04:51,150 --> 00:04:57,090 So before we do a republish of our coming module let's remember we have to go into our index not t yes 67 00:04:57,090 --> 00:05:05,100 file at the roots s our C folder and we have to export the contents of all these events files so we 68 00:05:05,100 --> 00:05:15,410 can easily import them into other services so inside of here we'll do an export star from events base 69 00:05:15,740 --> 00:05:23,610 listener and then just gonna copy paste that down a couple of times I think five ought to do it the 70 00:05:23,610 --> 00:05:36,870 next one will be based publisher then subjects ticket created event and ticket updated event and that 71 00:05:36,870 --> 00:05:39,380 should be at now last step. 72 00:05:39,440 --> 00:05:45,490 We're gonna go back over George terminal we're going to install no Nat streaming into our company module 73 00:05:46,530 --> 00:05:53,090 we're then going to republish this module and then update for right now just our ticket service so I'm 74 00:05:53,090 --> 00:05:57,560 gonna go back to my terminal I'm going to close down everything I'm running around us Nat's test stuff 75 00:05:58,890 --> 00:06:07,210 most going to stop the cubes TTL port forwarding stuff I'm then going to change over to our common directory 76 00:06:08,080 --> 00:06:12,690 I'm going to install node that's streaming 77 00:06:17,420 --> 00:06:22,880 and then finally I'm going to do an NPM run hub that was what our script was right was just simply pub 78 00:06:23,900 --> 00:06:30,710 let's take a look inside of common module Yep it was just pub will do NPM run pub that will do the commit 79 00:06:30,750 --> 00:06:37,760 the build the version delete the build do the publish all that stuff and it looks like I'm now on version 80 00:06:37,790 --> 00:06:39,410 1 0 1 3. 81 00:06:39,600 --> 00:06:45,410 Now we'll go back over to our ticket service also inside of our terminal and we'll do that update I'll 82 00:06:45,410 --> 00:06:51,080 go back or you tickets and NPM run me at NPM updates. 83 00:06:51,080 --> 00:06:57,690 That's better SGA tickets Bowman now going to expect to see some update message saying that this thing 84 00:06:57,690 --> 00:07:02,700 has been updated to one point 0 1 3 for me in particular your version is probably different at this 85 00:07:02,700 --> 00:07:04,160 point Yep there we go. 86 00:07:04,320 --> 00:07:06,620 All set. 87 00:07:06,640 --> 00:07:06,940 All right. 88 00:07:07,360 --> 00:07:12,020 Well we are pretty much done for right now anyways with this common module. 89 00:07:12,280 --> 00:07:16,540 We now have our listing of events inside there and as I mentioned over time we're going to come back 90 00:07:16,540 --> 00:07:19,320 to this thing and add in some other types of events. 91 00:07:19,370 --> 00:07:20,580 So let's take a pause right here. 92 00:07:20,590 --> 00:07:24,020 When we come back the next video we're going to go back to working on our ticket service. 93 00:07:24,130 --> 00:07:30,160 We'll make sure that any time someone creates a new ticket or anytime someone updates a ticket we will 94 00:07:30,160 --> 00:07:35,590 publish an event saying hey ticket update it so quick pause and I'll see you in just a minute.