1 00:00:01,310 --> 00:00:05,380 All right my friends let's build a listener that's going to listen for the order created event. 2 00:00:05,480 --> 00:00:08,820 Whenever we see this all we have to do is build up a new order and save it. 3 00:00:08,840 --> 00:00:10,790 So will be pretty straightforward. 4 00:00:10,940 --> 00:00:15,410 Let's go and get to it right away instead of my payment service off on the SRT directory. 5 00:00:15,500 --> 00:00:20,000 Inside there I'll make a new folder called events and then inside there I'll make another new folder 6 00:00:20,030 --> 00:00:21,750 called listeners. 7 00:00:22,060 --> 00:00:25,910 Now you might recall every time we made a listener we need a cue group name. 8 00:00:26,120 --> 00:00:30,580 And we've been defining that Q Group Name inside of a separate file inside the listeners directory. 9 00:00:30,590 --> 00:00:34,660 Let's do that right now since we know that we're going to need it very shortly anyways. 10 00:00:34,760 --> 00:00:41,060 The first filing in a crate inside the listeners is Q Group name dot t T.S. the inside of here we will 11 00:00:41,060 --> 00:00:48,650 export a concept of Q Group name and we'll sign that B string of payments service 12 00:00:52,770 --> 00:01:00,400 then inside of listeners will make a new file of order created listener not t s inside of here we're 13 00:01:00,400 --> 00:01:05,710 gonna make yet another listener we've been this process so many times let's just go through it really 14 00:01:05,710 --> 00:01:13,740 quickly at the top we will get our listener base class the order created events and these subjects in 15 00:01:13,740 --> 00:01:24,120 them from our common module I will also get Q Group name from the file we just created of Q Group Name 16 00:01:25,140 --> 00:01:31,960 will then make a class of order created listener that's going to extend our listener base class and 17 00:01:31,960 --> 00:01:42,880 we'll feed in the order created even we can then define our subject as subjects start order created 18 00:01:43,490 --> 00:01:48,380 and that should be a colon right there and then the actual value for this will be subjects that order 19 00:01:48,380 --> 00:01:58,170 created our Q Group Name is Q Group name and then finally on message 20 00:02:00,820 --> 00:02:06,830 Let's mark this thing as async it's going to receive that data argument that is of type order a created 21 00:02:06,860 --> 00:02:14,880 event specifically the data property and then our message which is a type message and I neglected to 22 00:02:14,880 --> 00:02:22,310 import message at the top of the file so we'll do that right away we'll get message from node that's 23 00:02:22,400 --> 00:02:22,850 streaming 24 00:02:25,680 --> 00:02:27,100 all right it's now inside of here. 25 00:02:27,130 --> 00:02:32,620 Well as you mentioned all you want to do is extract some information of this data object use it to build 26 00:02:32,650 --> 00:02:39,000 a new order and let's say that order then finally act the message that is it nothing else in order to 27 00:02:39,000 --> 00:02:39,950 actually build the order. 28 00:02:39,960 --> 00:02:41,750 Well we have to import the order model file. 29 00:02:41,760 --> 00:02:42,750 We just put together. 30 00:02:42,800 --> 00:02:54,800 So I will import that right away from up to directories models order and then inside of on message I'll 31 00:02:54,800 --> 00:03:01,200 create an order with order dot builds we'll make sure we pass through all those different properties 32 00:03:01,200 --> 00:03:06,180 that we've just said that we would so in total we need the idea the order version user I.D. price and 33 00:03:06,180 --> 00:03:11,750 status so ideal the data dot I.D. price will be at data. 34 00:03:11,780 --> 00:03:14,120 And remember this is nested on the ticket property. 35 00:03:14,150 --> 00:03:25,000 So the data that ticket price status will be data dot status user I.D. you'll be at data dot user I.D. 36 00:03:26,380 --> 00:03:33,060 and our version as well data dot version it we built our order. 37 00:03:33,070 --> 00:03:33,980 Now we have to save it. 38 00:03:34,030 --> 00:03:36,070 So in a weight order dot save 39 00:03:38,790 --> 00:03:41,970 and then assuming that went as expected we can ask our message. 40 00:03:41,980 --> 00:03:45,420 So a message dot EQ and that should be at 41 00:03:48,320 --> 00:03:48,540 debt. 42 00:03:48,560 --> 00:03:50,740 So I'd say this looks pretty good. 43 00:03:50,930 --> 00:03:55,550 Now I would as usual really like to test this out very quickly. 44 00:03:55,790 --> 00:03:59,480 We're gonna make this next video we're going to write out a test for this optional so if you're really 45 00:03:59,480 --> 00:04:03,230 tied with testing no problem you can skip over if you want to. 46 00:04:03,230 --> 00:04:05,860 Otherwise stick around and we'll go through some testing in the next video. 47 00:04:05,870 --> 00:04:06,530 Very quickly.