We've now got our custom a new ticket listener put together along with the bass class of listener.
Now at this point there's something I really want to clarify very quickly.
We have our bass classical listener and a ticket created listener.
The idea here is that we're going to define this listener class inside of our common module.
We'll then import this into our different services we're going to eventually create that inside of each
of our services.
That is where we are going to actually subclass listener and create some custom listener that's going
to work specifically for say the payment service or say the ticket service or whatever other service
we are creating.
So listener is just a blueprint.
It is a guide on how to create a listener.
We're going to actually implement these things with very custom logic inside of each of our services
all right.
So that out of the way next day I want to do we'll take a look at our listener test file.
There's a lot of code inside of here right now and it's really hard to figure out what is going on.
Let's try redistributing some of the code into a couple of different files inside this project directory
just to make all this stuff a little bit easier to understand so inside the SRT folder I'm going to
first begin by creating a new folder called events inside there are going to make a new file called
base listener T.S..
I would normally not use the name of base listener for this listener class.
We just put together what we already have a file called listener inside of our project.
So rather than calling it listener and having to listener files which should be really confusing let's
just give it a name of base listener.
Then go back over to the listener test file.
I'm going to find the abstract class of listener.
I'm going to cut that entire thing
and I'll paste it into base listener.
We then need to add some imports at the top are going to get message and Stan from node Nats streaming
and I'll make sure that I also export that class.
Now let's try to also extract this ticket created listener so inside the events directory as well.
I'll make a new file called Ticket created listener.
I'm gonna go and find the ticket created listener itself.
I'm gonna cut it.
And then paste it into that new file and then again we do have to add in some imports at the top or
listener from base listener and let's also get message from node Nats streaming.
Then make sure that I export the class itself
now finally back inside of the listener test file.
We have to make sure that we import ticket created a listener at the top so I will import ticket created
listener from events ticket created listener
I can then also clean up the imports up here for a message and Stan helps ALEX Good.
All right.
If I go back go read my terminal I should be able to confirm that everything is still working.
Yep still running and if I pollution events I see it appear in one these terminal windows.
Very good.
So just a little bit of code cleanup.
Quick pause right here.
Continue in just a minute.