1 00:00:00,810 --> 00:00:05,820 We have updated our common library so it now has all that code related to creating events and listening 2 00:00:05,820 --> 00:00:07,560 to events as well. 3 00:00:07,560 --> 00:00:12,160 We've updated the version that the tickets service is making yourself for the common library. 4 00:00:12,280 --> 00:00:15,590 Now our ticket service has access to all that event stuff as well. 5 00:00:15,750 --> 00:00:19,740 In this video the first you were gonna start to focus on is making sure that whenever someone creates 6 00:00:19,770 --> 00:00:24,020 a new ticket by making a POST request to our ticket service. 7 00:00:24,090 --> 00:00:29,520 So specifically this new route handler right here we're going to make sure that we create the ticket 8 00:00:30,120 --> 00:00:35,100 save the ticket to the database and then right after that we're going to want to publish an event telling 9 00:00:35,130 --> 00:00:39,390 every other service inside of application that someone just created a new ticket. 10 00:00:39,730 --> 00:00:45,840 So to do so we are going to create a new custom publisher inside of our tickets service. 11 00:00:45,840 --> 00:00:51,870 This custom publisher sole purpose is to publish an event saying hey a ticket was created. 12 00:00:51,870 --> 00:00:55,470 It's going to end up looking just about identical to the one we just put together inside that little 13 00:00:55,680 --> 00:00:58,390 Nats test project a moment ago. 14 00:00:58,380 --> 00:01:00,870 So let's put this thing together right away. 15 00:01:00,870 --> 00:01:05,060 Inside my ticket service I'm gonna find the SDR directory inside. 16 00:01:05,060 --> 00:01:10,050 They're going to make a new folder called events and then inside of that I'm gonna make a new folder 17 00:01:10,050 --> 00:01:11,720 called Publishers. 18 00:01:11,820 --> 00:01:13,800 We're gonna have a slightly better folder structure. 19 00:01:13,800 --> 00:01:18,540 The summer rounds we're going to have a directory for all the different publishers that we create and 20 00:01:18,540 --> 00:01:22,440 a directory eventually for all the different custom listeners we create as well. 21 00:01:23,060 --> 00:01:31,800 Inside of publishers I'm gonna make a new file called Ticket created publisher dot T.S. get so inside 22 00:01:31,800 --> 00:01:36,660 of here we're gonna put together a very simple publisher member a publisher is going to emit an event 23 00:01:36,690 --> 00:01:40,740 over to that streaming server and again this thing is gonna look very similar to the one we already 24 00:01:40,740 --> 00:01:41,930 put together. 25 00:01:42,000 --> 00:01:50,400 So at the very top I'm going to import the publisher based class our subjects enum and the ticket created 26 00:01:50,490 --> 00:01:55,770 event and all those are going to come from my common library 27 00:02:01,210 --> 00:02:07,950 so then inside this file we're going to export a class of ticket created a publisher. 28 00:02:07,980 --> 00:02:13,740 This is going to be extending the publisher base class that is a generic class which means we need to 29 00:02:13,740 --> 00:02:17,940 put on those angle brackets and provide the type of event that we are going to try to we met with this 30 00:02:17,940 --> 00:02:18,420 publisher. 31 00:02:18,690 --> 00:02:21,030 So in this case it is a ticket created event 32 00:02:27,430 --> 00:02:31,300 it's an outside script is going to try to guide us and tell us what we're doing wrong here. 33 00:02:31,320 --> 00:02:35,760 Well if we hover over the thing it's telling us that we need to define some subject. 34 00:02:35,760 --> 00:02:39,600 Remember the subject is going to be essentially the name of the channel that we want to make this event 35 00:02:39,600 --> 00:02:46,830 to the name of our subject is going to be the ticket created event or something hot ticket create event 36 00:02:46,830 --> 00:02:47,600 but subjects. 37 00:02:47,610 --> 00:02:48,780 That's all we're looking for. 38 00:02:48,780 --> 00:02:52,890 We do a command click on subjects we'll see that we've got the subject and they're named ticket created 39 00:02:54,300 --> 00:03:01,970 so put in subject it is of type subjects dot ticket created and its value is subjects dot ticket created 40 00:03:02,510 --> 00:03:08,010 as a reminder we have to do both the type annotation right here and the value assignment. 41 00:03:08,030 --> 00:03:12,920 The reason that we have both on here is to make sure that we never tried to change the value of subject 42 00:03:13,550 --> 00:03:18,320 so by saying that subject is of type subject start to get created we are not going to be allowed to 43 00:03:18,320 --> 00:03:23,370 change this value to any other value at any point in time. 44 00:03:23,440 --> 00:03:24,140 ALEX Good. 45 00:03:24,230 --> 00:03:29,100 So we can save this and now in theory in some other file we can import this publisher. 46 00:03:29,270 --> 00:03:37,250 We can create a new ticket created publisher past in our Nats client and then publish some kind of ticket 47 00:03:37,280 --> 00:03:38,200 or something like that. 48 00:03:40,540 --> 00:03:42,260 All right so let's take a quick pause right here. 49 00:03:42,340 --> 00:03:46,420 We come back the next video we're going to figure out how to create a Nats client inside of our tickets 50 00:03:46,450 --> 00:03:47,020 project.