Let's get started working on our first listener.
It's going to be the ticket created listener.
It's inside of my order service.
I'll find the event's directory inside there I'll make a new folder of listeners and then inside of
listeners I'll make a new file of ticket created.
Listener Scott to us will then start to put some implementation together right away.
We're going to end up with a couple of different import statements at the very top.
So let's add in a couple of different imports.
First we will get the message type from a node not streaming.
I'm going to get my subjects you know by listener base class and the ticket created event all those
from my common module.
I'm also going to get my ticket model.
So from my model's directory right here I'll get ticket from up to directories.
Models
and then I think that's probably all we need for right now.
Let's start to put the actual implementation for this thing together.
So first off we're going to export a class of ticket read and listener and very similar to what we're
doing with our different publishers.
We are going to be extending an abstract class and this case listener.
And remember this is a generic which means we have to provide a type and the type we're going to stick
in here is the type of event that we're going to listen for.
Which is ticket created events Doyel plug in ticket created event like so well then see our class name
light up and touch script is telling us that there are three different properties we have to implement
inside of here all because we are extending that abstract class so we have to implement on message your
group name and subject.
Well first start off with subject to the right in the subject right here and we're going to use the
exact same system that we use back on our publishers.
We're going to define or declare the subject property and we're gonna give it the very specific type
that this thing is gonna be.
So we'll say subjects dot ticket created and then we're going to actually assign it a value.
Those subjects dot ticket created.
And remember this kind of two step process right here is to make sure that typescript enforces us to
never be able to change that subject property at any point in time.
Next up we're gonna define our Q Group Name so.
Q Group name in this case is going to be our quarters service.
And like I said I'll give you a reminder on what that Q Group Name is in just a moment.
And then finally we'll define our on message function.
So this is going to receive two arguments.
First is going to be the data from inside of our event.
And the second is gonna be the message from the note not streaming library so put in here data and that's
going to be up type ticket related event at data and the second argument will be message and that would
be up type message all right.
So I apologize for kind of speeding through this and saying oh yeah we'll come back to this and we'll
come back to this and this message thing and so on.
But I really just wanted through this code together because this is going to be very similar to what
all of our different listeners look like all of our different listeners are going to extend the listener
base class have the event type plugged into it and then define a subject a Q Group name and then on
message now that we've established this kind of as the blueprint that we're going to be copy pasting
over and over and over again.
Another quick pause right here.
When we come back the next video we're going to get a reminder on what that Q Group Name is why we have
this weird invitation for data right here.
And a reminder on what this message thing is as well.