1 00:00:01,280 --> 00:00:06,250 We've now got our custom a new ticket listener put together along with the bass class of listener. 2 00:00:06,280 --> 00:00:09,320 Now at this point there's something I really want to clarify very quickly. 3 00:00:09,320 --> 00:00:12,470 We have our bass classical listener and a ticket created listener. 4 00:00:12,470 --> 00:00:17,000 The idea here is that we're going to define this listener class inside of our common module. 5 00:00:17,150 --> 00:00:21,650 We'll then import this into our different services we're going to eventually create that inside of each 6 00:00:21,650 --> 00:00:22,570 of our services. 7 00:00:22,580 --> 00:00:27,950 That is where we are going to actually subclass listener and create some custom listener that's going 8 00:00:27,950 --> 00:00:33,980 to work specifically for say the payment service or say the ticket service or whatever other service 9 00:00:33,980 --> 00:00:35,140 we are creating. 10 00:00:35,150 --> 00:00:36,640 So listener is just a blueprint. 11 00:00:36,650 --> 00:00:38,770 It is a guide on how to create a listener. 12 00:00:38,780 --> 00:00:43,040 We're going to actually implement these things with very custom logic inside of each of our services 13 00:00:44,150 --> 00:00:44,360 all right. 14 00:00:44,360 --> 00:00:49,050 So that out of the way next day I want to do we'll take a look at our listener test file. 15 00:00:49,100 --> 00:00:53,230 There's a lot of code inside of here right now and it's really hard to figure out what is going on. 16 00:00:53,300 --> 00:00:57,800 Let's try redistributing some of the code into a couple of different files inside this project directory 17 00:00:57,960 --> 00:01:03,800 just to make all this stuff a little bit easier to understand so inside the SRT folder I'm going to 18 00:01:03,800 --> 00:01:10,240 first begin by creating a new folder called events inside there are going to make a new file called 19 00:01:10,300 --> 00:01:12,550 base listener T.S.. 20 00:01:12,910 --> 00:01:17,440 I would normally not use the name of base listener for this listener class. 21 00:01:17,440 --> 00:01:21,260 We just put together what we already have a file called listener inside of our project. 22 00:01:21,280 --> 00:01:25,600 So rather than calling it listener and having to listener files which should be really confusing let's 23 00:01:25,600 --> 00:01:28,370 just give it a name of base listener. 24 00:01:28,430 --> 00:01:30,810 Then go back over to the listener test file. 25 00:01:31,030 --> 00:01:34,170 I'm going to find the abstract class of listener. 26 00:01:34,180 --> 00:01:35,480 I'm going to cut that entire thing 27 00:01:40,340 --> 00:01:44,750 and I'll paste it into base listener. 28 00:01:44,830 --> 00:01:51,670 We then need to add some imports at the top are going to get message and Stan from node Nats streaming 29 00:01:53,510 --> 00:01:57,150 and I'll make sure that I also export that class. 30 00:01:57,160 --> 00:02:03,870 Now let's try to also extract this ticket created listener so inside the events directory as well. 31 00:02:03,870 --> 00:02:09,690 I'll make a new file called Ticket created listener. 32 00:02:09,780 --> 00:02:12,430 I'm gonna go and find the ticket created listener itself. 33 00:02:12,450 --> 00:02:13,050 I'm gonna cut it. 34 00:02:14,590 --> 00:02:19,730 And then paste it into that new file and then again we do have to add in some imports at the top or 35 00:02:19,730 --> 00:02:33,050 listener from base listener and let's also get message from node Nats streaming. 36 00:02:33,100 --> 00:02:34,870 Then make sure that I export the class itself 37 00:02:38,650 --> 00:02:41,490 now finally back inside of the listener test file. 38 00:02:41,700 --> 00:02:48,560 We have to make sure that we import ticket created a listener at the top so I will import ticket created 39 00:02:48,620 --> 00:02:53,690 listener from events ticket created listener 40 00:02:56,940 --> 00:03:04,030 I can then also clean up the imports up here for a message and Stan helps ALEX Good. 41 00:03:04,100 --> 00:03:04,340 All right. 42 00:03:04,350 --> 00:03:07,750 If I go back go read my terminal I should be able to confirm that everything is still working. 43 00:03:07,770 --> 00:03:13,350 Yep still running and if I pollution events I see it appear in one these terminal windows. 44 00:03:13,410 --> 00:03:14,300 Very good. 45 00:03:14,370 --> 00:03:15,930 So just a little bit of code cleanup. 46 00:03:15,930 --> 00:03:16,640 Quick pause right here. 47 00:03:16,650 --> 00:03:17,610 Continue in just a minute.