We have updated our common library so it now has all that code related to creating events and listening
to events as well.
We've updated the version that the tickets service is making yourself for the common library.
Now our ticket service has access to all that event stuff as well.
In this video the first you were gonna start to focus on is making sure that whenever someone creates
a new ticket by making a POST request to our ticket service.
So specifically this new route handler right here we're going to make sure that we create the ticket
save the ticket to the database and then right after that we're going to want to publish an event telling
every other service inside of application that someone just created a new ticket.
So to do so we are going to create a new custom publisher inside of our tickets service.
This custom publisher sole purpose is to publish an event saying hey a ticket was created.
It's going to end up looking just about identical to the one we just put together inside that little
Nats test project a moment ago.
So let's put this thing together right away.
Inside my ticket service I'm gonna find the SDR directory inside.
They're going to make a new folder called events and then inside of that I'm gonna make a new folder
called Publishers.
We're gonna have a slightly better folder structure.
The summer rounds we're going to have a directory for all the different publishers that we create and
a directory eventually for all the different custom listeners we create as well.
Inside of publishers I'm gonna make a new file called Ticket created publisher dot T.S. get so inside
of here we're gonna put together a very simple publisher member a publisher is going to emit an event
over to that streaming server and again this thing is gonna look very similar to the one we already
put together.
So at the very top I'm going to import the publisher based class our subjects enum and the ticket created
event and all those are going to come from my common library
so then inside this file we're going to export a class of ticket created a publisher.
This is going to be extending the publisher base class that is a generic class which means we need to
put on those angle brackets and provide the type of event that we are going to try to we met with this
publisher.
So in this case it is a ticket created event
it's an outside script is going to try to guide us and tell us what we're doing wrong here.
Well if we hover over the thing it's telling us that we need to define some subject.
Remember the subject is going to be essentially the name of the channel that we want to make this event
to the name of our subject is going to be the ticket created event or something hot ticket create event
but subjects.
That's all we're looking for.
We do a command click on subjects we'll see that we've got the subject and they're named ticket created
so put in subject it is of type subjects dot ticket created and its value is subjects dot ticket created
as a reminder we have to do both the type annotation right here and the value assignment.
The reason that we have both on here is to make sure that we never tried to change the value of subject
so by saying that subject is of type subject start to get created we are not going to be allowed to
change this value to any other value at any point in time.
ALEX Good.
So we can save this and now in theory in some other file we can import this publisher.
We can create a new ticket created publisher past in our Nats client and then publish some kind of ticket
or something like that.
All right so let's take a quick pause right here.
We come back the next video we're going to figure out how to create a Nats client inside of our tickets
project.