1 00:00:01,180 --> 00:00:06,310 Now that we have created our expiration complete event we can create a publisher to publish this event 2 00:00:06,340 --> 00:00:08,460 inside of our expiration service. 3 00:00:08,470 --> 00:00:11,220 It has been just a little bit since we have created a publisher. 4 00:00:11,320 --> 00:00:16,150 So let's just get a quick reminder on how we do it by taking a look back at our order service. 5 00:00:16,150 --> 00:00:21,610 Back inside the order service we can find our SLC events publishers directory and inside there maybe 6 00:00:21,610 --> 00:00:24,520 just look at our order created publisher. 7 00:00:24,580 --> 00:00:26,210 So this is how we create a publisher. 8 00:00:26,260 --> 00:00:27,250 Just make a new class. 9 00:00:27,250 --> 00:00:33,250 We extend our publisher base class and we put in the type of event that we want to publish and then 10 00:00:33,250 --> 00:00:34,320 for the subject. 11 00:00:34,390 --> 00:00:37,090 We just defined that using these subjects in them and that's it. 12 00:00:37,090 --> 00:00:39,310 Nothing else very special about it. 13 00:00:39,430 --> 00:00:46,270 So let's create one of these or our expiration complete event back inside of the expiration service 14 00:00:47,530 --> 00:00:48,520 inside of expiration. 15 00:00:48,520 --> 00:00:54,470 I'll find the events directory and inside there I'll make a new folder called publisher's and in there 16 00:00:54,560 --> 00:01:02,460 we'll create a new file of expiration complete publisher dot T.S. 17 00:01:05,430 --> 00:01:17,140 then up at the very top we'll import subjects publisher and the expiration complete event from our common 18 00:01:17,140 --> 00:01:17,560 module 19 00:01:21,920 --> 00:01:33,890 will then export a new class of expiration complete publisher Come on. 20 00:01:33,940 --> 00:01:34,350 There we go. 21 00:01:35,800 --> 00:01:41,800 That's going to be extending publisher and as the generic type will stick in the expiration. 22 00:01:41,990 --> 00:01:43,260 You bet. 23 00:01:43,270 --> 00:01:45,220 These are some really long variable names. 24 00:01:45,220 --> 00:01:50,230 That's why I'm pausing every school time because I want to make sure that I get the name exactly correct. 25 00:01:50,230 --> 00:01:54,910 All right as usual typescript says well if you want to extend this you've got a defined subject I'll 26 00:01:54,940 --> 00:01:56,190 set up these subject property. 27 00:01:56,200 --> 00:02:03,310 It will be up type subjects dot expiration complete and we will sign that a value of subjects dot expiration 28 00:02:03,340 --> 00:02:03,850 complete 29 00:02:07,730 --> 00:02:10,470 now looks like touch script is still unhappy here. 30 00:02:10,470 --> 00:02:12,780 Oh I put in subjects should be just subject singular. 31 00:02:12,780 --> 00:02:13,810 There we go. 32 00:02:13,950 --> 00:02:15,790 Now it's happy. 33 00:02:15,870 --> 00:02:17,210 All right publisher created. 34 00:02:17,220 --> 00:02:23,670 So now we can go back over to our Qs exploration queue and we'll find our process statement inside their 35 00:02:24,730 --> 00:02:25,610 sorry member. 36 00:02:25,640 --> 00:02:30,370 We go back and reference this diagram whenever we process this job whenever we receive it back from 37 00:02:30,370 --> 00:02:30,890 readies. 38 00:02:30,970 --> 00:02:35,530 That is when we are going to want to emit that new event or publishing event of expiration complete 39 00:02:35,850 --> 00:02:41,540 and we just need to make sure that we take the order I.D. out of the job itself so the code for this 40 00:02:41,540 --> 00:02:47,070 should be pretty easy and straightforward at the very top of our exploration queue file. 41 00:02:47,070 --> 00:02:50,180 We are going to import our publisher 42 00:02:57,230 --> 00:03:06,950 from up one directory events publishers expiration complete publisher and then remember any time that 43 00:03:06,950 --> 00:03:08,080 we tried to publish an event. 44 00:03:08,090 --> 00:03:11,050 We also have to provide the Nats client as well. 45 00:03:11,150 --> 00:03:18,020 So we're going to also import our Nats rapper from up to directories or send me just one directory in 46 00:03:18,020 --> 00:03:19,080 this case. 47 00:03:19,280 --> 00:03:21,930 Nats rapper. 48 00:03:22,160 --> 00:03:31,360 So now down inside of our process statement we can remove that console log and replace it with publisher 49 00:03:31,450 --> 00:03:35,220 is where actually we don't even really need to assign it to a variable we can write it all out inside 50 00:03:35,230 --> 00:03:36,940 just one statement so we'll just do that. 51 00:03:36,940 --> 00:03:46,230 We'll say new expiration complete publisher will pass in our Nats client and we will publish 52 00:03:49,210 --> 00:03:53,650 and as usual if we forget what we have to provide for publish we can just mouse over and touch crypto 53 00:03:53,650 --> 00:03:59,470 tell us we have to give in order ideas so put in an order I.D. and that order idea is gonna come out 54 00:03:59,470 --> 00:04:01,260 of our job number. 55 00:04:01,270 --> 00:04:06,430 Our job has a data property the data property is going to contain all the information we are storing 56 00:04:06,430 --> 00:04:11,940 inside the job which in this case is this payload interface or it is a object matching the payload interface. 57 00:04:11,950 --> 00:04:21,320 Just to be really correct here so for order I.D. We'll put in job dot data dot order I.D. and that is 58 00:04:21,320 --> 00:04:22,390 pretty much it. 59 00:04:22,400 --> 00:04:27,620 So now naturally we should try to test this out so we can once again use postmen to manually create 60 00:04:27,710 --> 00:04:32,690 a ticket manually create an order and then we could wait for that full 1 minute to eventually see a 61 00:04:32,990 --> 00:04:37,050 expiration complete event get published but instead it just make everything go really quickly. 62 00:04:37,100 --> 00:04:42,590 Let's go back over to our order created listener so inside of our listeners directory and we're going 63 00:04:42,590 --> 00:04:43,810 to do a test of all this stuff. 64 00:04:43,850 --> 00:04:48,800 But I'm going to come in out the delay right here that's going to cause the job to be processed instantly 65 00:04:48,800 --> 00:04:53,660 and so we should see the event of expiration complete processed instantly as well. 66 00:04:54,400 --> 00:04:54,540 Yeah. 67 00:04:54,550 --> 00:05:00,020 Gonna say this we'll go to postman and test this all out inside a postman gonna once again create a 68 00:05:00,020 --> 00:05:07,360 new ticket there is my ticket I.D. then use that to create a new order I'll put in the ticket idea right 69 00:05:07,360 --> 00:05:11,830 there send it off and we'll go back over to my terminal and take a look at the different events it's 70 00:05:11,830 --> 00:05:20,370 been published OK so let's kick off at order created right here from the expiration service we then 71 00:05:20,370 --> 00:05:24,420 get the console log that we're gonna wait some number of milliseconds to process the job but of course 72 00:05:24,420 --> 00:05:30,740 we just commented out that delay so it's gonna be kind of processed immediately so then see some other 73 00:05:30,740 --> 00:05:36,080 stuff about a ticket being updated another ticket updated during CFD and then that's what we're looking 74 00:05:36,080 --> 00:05:36,740 for right there. 75 00:05:36,740 --> 00:05:41,180 Event published to expiration complete from the expiration service. 76 00:05:41,210 --> 00:05:41,960 Awesome. 77 00:05:41,980 --> 00:05:44,610 That means that it's all working as expected. 78 00:05:44,660 --> 00:05:48,850 This looks pretty good and that is pretty much it for our expiration service. 79 00:05:48,860 --> 00:05:50,300 Pretty simple straightforward. 80 00:05:50,300 --> 00:05:56,180 All it really did was take an event wait some time and then publish another one in the future so last 81 00:05:56,180 --> 00:06:01,370 thing I'm going to do for the listener I'm going to comment that delay and make sure I get a call about 82 00:06:01,370 --> 00:06:01,930 right above 83 00:06:05,630 --> 00:06:07,380 and close all this stuff out. 84 00:06:07,380 --> 00:06:11,280 We'll take a pause right here and when we come back the next video we're going to move back over to 85 00:06:11,280 --> 00:06:17,910 our order service and make sure that we receive that new ticket or expiration complete event as soon 86 00:06:17,910 --> 00:06:18,570 as we get that event. 87 00:06:18,570 --> 00:06:24,350 We'll make sure that we mark the accompanying order as expired well so quick pause right here and we'll 88 00:06:24,350 --> 00:06:26,650 go back over to the order service in just a moment.