1 00:00:01,060 --> 00:00:04,840 In this video we're going to get a quick reminder on how we create a listener you might recall that 2 00:00:04,840 --> 00:00:10,720 inside of our common module and the SRT directory in the events folder we had created that base listener 3 00:00:10,750 --> 00:00:11,730 class. 4 00:00:11,770 --> 00:00:16,750 This was an abstract class and so we're going to extend this to build out different classes inside of 5 00:00:16,750 --> 00:00:22,270 each of our services that are going to listen for very specific events when we extend this listener. 6 00:00:22,270 --> 00:00:26,350 We're going to make sure we provide a event type as the generic type. 7 00:00:26,350 --> 00:00:31,480 And then inside of the child class we're also going to be required to define a subject such can be subject 8 00:00:31,490 --> 00:00:36,160 we want to listen to on that string server a Q Group name and we'll get a reminder on what that's about 9 00:00:36,160 --> 00:00:37,040 really quickly. 10 00:00:37,120 --> 00:00:42,070 And then finally the on message function the on message function is what's going to actually receive 11 00:00:42,100 --> 00:00:45,450 an event that's we're going to implement some amount of business logic. 12 00:00:45,730 --> 00:00:50,290 The first argument is going to be the data inside the event and the second argument will be a message 13 00:00:50,440 --> 00:00:52,730 and we'll get a reminder on what that message is in a little bit. 14 00:00:52,790 --> 00:00:57,910 ASM The other thing I want to remind you about is that when we create an instance of a listener we have 15 00:00:57,910 --> 00:01:04,320 to provide a Nats client to it when we create an instance of a listener and provide the Nats client 16 00:01:04,590 --> 00:01:06,690 that doesn't actually start the thing up listening. 17 00:01:06,690 --> 00:01:11,160 Instead we have to call the listener method which we have defined down here. 18 00:01:11,160 --> 00:01:15,540 This is what is going to actually tell the client to start to subscribe or create a subscription and 19 00:01:15,540 --> 00:01:21,540 listen for events on a very particular subject or channel then whenever we receive a message that is 20 00:01:21,540 --> 00:01:27,240 when we were going to actually call the on message function so in total in order to create a listener 21 00:01:27,390 --> 00:01:30,000 we're going to create a new file inside of our different services. 22 00:01:30,030 --> 00:01:35,190 It's going to extend this base listener class we're going to plug in at the event type 1 to listen for 23 00:01:35,460 --> 00:01:37,540 and then define a couple of different properties inside of it. 24 00:01:37,740 --> 00:01:38,810 And that's pretty much it. 25 00:01:40,160 --> 00:01:44,000 Now as a reminder the first listener we're gonna put together is give me a listening for the ticket 26 00:01:44,030 --> 00:01:49,400 created event and we're going to implement that inside of our order service. 27 00:01:49,560 --> 00:01:53,250 Let's take a quick pause right here and then start to implement this first listener in the next video.