1 00:00:00,850 --> 00:00:03,900 Let's get a quick reminder on some different aspects of these listeners. 2 00:00:03,970 --> 00:00:06,450 The person we're gonna focus on is the cougar name. 3 00:00:06,460 --> 00:00:09,180 Let's take a look at a quick diagram OK. 4 00:00:09,210 --> 00:00:12,500 So in this diagram we've got some publisher up here on the top left hand side. 5 00:00:12,600 --> 00:00:16,290 That's going to be eventually published an event up ticket created on the right hand side is our net 6 00:00:16,290 --> 00:00:22,320 streaming server and we're listening inside of our two instances of the order service to some channel 7 00:00:22,380 --> 00:00:28,760 called Ticket created when these two order services connected to this channel and created a subscription. 8 00:00:28,760 --> 00:00:34,830 They joined a Q group called orders service by being a member of this Q group that ensures that any 9 00:00:34,840 --> 00:00:41,570 time an event comes into this channel this event is only going to be sent to one of the members inside 10 00:00:41,570 --> 00:00:42,240 this Q Group. 11 00:00:42,770 --> 00:00:48,200 So the entire idea behind this supposed to make sure that we do not have our different services all 12 00:00:48,200 --> 00:00:52,610 independently processing the same copy of this event at the same time. 13 00:00:52,700 --> 00:00:57,950 So instead the Q Group makes sure that this event is only going to be sent to either order service a 14 00:00:58,400 --> 00:01:00,030 or order service. 15 00:01:00,980 --> 00:01:06,350 The only requirement of the Q Group identifier right here is that it is unique for all the different 16 00:01:06,350 --> 00:01:11,210 services that are going to create subscriptions inside this channel number one and number two it must 17 00:01:11,210 --> 00:01:16,490 stay consistent over time so we should not try to randomly generate a Q Group name or anything like 18 00:01:16,490 --> 00:01:17,820 that. 19 00:01:17,830 --> 00:01:22,870 Now the Q Group Name is one of those little variables or properties right here that's really easy to 20 00:01:22,870 --> 00:01:24,100 make a typo on. 21 00:01:24,130 --> 00:01:29,080 So at some point time we're gonna create another listener inside of our app let's imagine that it's 22 00:01:29,410 --> 00:01:34,150 some other listener inside of some other file and when we did so we would have to define this Q Group 23 00:01:34,150 --> 00:01:39,310 name another time or second time would be really easy for us to actually make a little typo here. 24 00:01:39,310 --> 00:01:44,770 Maybe we call it order service or maybe we call it order service without a dash or maybe do a slash 25 00:01:44,770 --> 00:01:47,010 instead or a colon or whatever else. 26 00:01:47,140 --> 00:01:52,120 And so usually rather than defining the Q Group name as a string directly inside the listener we might 27 00:01:52,120 --> 00:01:57,130 be a little bit better off if we define the string somewhere else instead of a project just one time 28 00:01:57,460 --> 00:02:03,570 and then import that value into our project or something into this listener file so let's try that right 29 00:02:03,570 --> 00:02:03,780 now. 30 00:02:03,780 --> 00:02:08,970 Let's declare a Q Group name and a separate file and then imported into this file again just so we avoid 31 00:02:08,970 --> 00:02:13,700 making any typos inside of my listeners directory that we just created. 32 00:02:13,780 --> 00:02:22,650 I'm gonna make a new file of Q Group name dot t s then inside there I'm going to export a concept of 33 00:02:22,650 --> 00:02:27,440 Q Group name and I'll hardcoded value to orders. 34 00:02:27,720 --> 00:02:32,180 Service does save this file. 35 00:02:32,370 --> 00:02:35,110 Pull it back over to our listener at the very top. 36 00:02:35,110 --> 00:02:36,920 I'm going to import you. 37 00:02:36,940 --> 00:02:37,900 Group Name 38 00:02:41,670 --> 00:02:47,490 from Q Group name and now I'll reference that variable right there instead of this hardcoded string 39 00:02:47,990 --> 00:02:48,220 though. 40 00:02:48,230 --> 00:02:51,680 Q Group name. 41 00:02:51,780 --> 00:02:54,370 So again just avoiding little typos. 42 00:02:54,490 --> 00:02:58,920 OK so let's get a quick reminder now about this data property coming too on message. 43 00:02:59,040 --> 00:03:03,000 So remember we had said that we're going to create an interface to describe all the different events 44 00:03:03,000 --> 00:03:05,280 that are going to be flowing throughout our application. 45 00:03:05,280 --> 00:03:09,540 In this case that interface we created was the ticket created event interface. 46 00:03:09,690 --> 00:03:14,500 We could do a command click on ticket created even anywhere inside this file or a control click through 47 00:03:14,520 --> 00:03:16,080 on Windows. 48 00:03:16,080 --> 00:03:23,960 And it should take us to the definition of that interface so all of our event interfaces had the subject 49 00:03:23,960 --> 00:03:29,210 property and the data property and data was describing the different pieces of data that was going to 50 00:03:29,210 --> 00:03:31,220 be contained inside this event. 51 00:03:31,220 --> 00:03:36,410 So to make sure that we applied some type checking on the data flowing into this on message function 52 00:03:37,040 --> 00:03:41,470 we reference the event type interface and then we're saying off that interface. 53 00:03:41,510 --> 00:03:47,550 Take a look at the data property and that's going to be the type of this data argument right here then 54 00:03:47,550 --> 00:03:51,850 finally last little reminder is this message argument as a second argument. 55 00:03:51,870 --> 00:03:52,830 So what is the message. 56 00:03:52,830 --> 00:03:56,700 Well remember this is an object coming from the node not streaming library. 57 00:03:56,700 --> 00:04:00,690 The message thing is something that tells us about the underlying data coming from the known out streaming 58 00:04:00,690 --> 00:04:01,260 server. 59 00:04:01,260 --> 00:04:04,380 But most importantly for you and I absolute bar none. 60 00:04:04,380 --> 00:04:09,240 Most important thing about it we do a command click on message and go to the type definition you might 61 00:04:09,240 --> 00:04:09,690 recall. 62 00:04:09,690 --> 00:04:17,110 This thing has a method of EQ and that was what you and I really really cared about. 63 00:04:17,320 --> 00:04:22,540 We call EQ when we have successfully processed a message or an event and that is a signal to note that 64 00:04:22,540 --> 00:04:26,350 streaming server that we have process this event and it does not have to worry about trying to send 65 00:04:26,350 --> 00:04:29,020 it off to another copy of our service again. 66 00:04:29,080 --> 00:04:34,120 So after we successfully process any event inside of our different listeners we're always going to finish 67 00:04:34,120 --> 00:04:35,970 up by calling back. 68 00:04:36,060 --> 00:04:38,960 Now the keyword here is successfully process. 69 00:04:38,960 --> 00:04:44,840 So I guess the keywords successfully process only when we successfully process an event do we call ach. 70 00:04:44,980 --> 00:04:49,870 Otherwise if there's some kind of error or something like that we usually it will not be calling EC 71 00:04:50,020 --> 00:04:55,030 because an error will usually indicate that we want to try to re process this event again and we would 72 00:04:55,030 --> 00:05:00,070 do that by just not calling Ach that would cause our event to time out after a couple of seconds and 73 00:05:00,070 --> 00:05:04,060 that string server is going to try to take that event and send it off to another copy of our service 74 00:05:04,060 --> 00:05:06,140 for reprocessing. 75 00:05:06,150 --> 00:05:06,390 All right. 76 00:05:06,420 --> 00:05:11,310 So hopefully that gives you a really good reminder on what's going on inside of our listeners. 77 00:05:11,310 --> 00:05:15,510 Again we're going to be writing on the same exact code again and again and again moving forward for 78 00:05:15,510 --> 00:05:16,380 all these different listeners. 79 00:05:16,380 --> 00:05:20,170 Just really important that you keep the definitions of all these different things in mind. 80 00:05:20,190 --> 00:05:21,010 All right sounds good. 81 00:05:21,010 --> 00:05:22,210 So let's now take a quick pause. 82 00:05:22,210 --> 00:05:25,800 We're going to start to implement the body of our on message function in the next video.