As I mentioned in the last video we're gonna start to take a lot of the code inside of our nets test
project and merge it into the coming module.
We're then going to rebuild common publish it and then update the tickets project and start to use Natsumi
server inside there.
So let's get to it inside this coming directory.
I'll find SRT inside there I'll make a new folder called events will then find the events directory
inside of Nat's test and we're going to pull out the base listener.
I'll do a multi select year.
I'm also gonna get the base publisher.
I'm going to get subjects going to get the event definition and that's it.
The listener and the publisher are things that are going to be ultimately defined and implemented inside
of our individual services.
Because how a service listens to an incoming event like ticket created is going to be determined on
a service by service basis.
One service might want to take a ticket and do one thing with it.
Another service White might want to take a ticket and do another thing with it.
So we're only taking the first for inside of you're going to copy all this.
I'll go to the events directory we just created and paste those four files in
if we then go into that say base listener file we're gonna see right away that we get an error.
So this is base listener inside of common we're getting an error because we have an import for node
and that's streaming that's really fine.
We have not installed no net streaming into the common module.
That's why you're seeing the air right now.
I do want to immediately add in one or two more events that I know that we're going to need right away
when we start to make use of this common module or the update to it back inside our tickets service.
So we've got a event here for ticket created.
We're definitely going to need a event for a ticket update as well.
So let's put together a event to describe that to to do so.
We're going to first open up our subjects file.
We're going to add in a new type to the thing of ticket.
Updated and I'll use a subject name of ticket.
Colon updated.
Now we are not actually using order updated so I am going to delete that one just so we don't get confused
on what we have and haven't implemented it's now I only have to get created and ticket update it.
I'll then say this file and close it then also inside of events I'm going to make a new file called
Ticket updated event not to yes inside of ticket updated we're gonna write out some code that looks
very similar to what we just did inside of ticket created so inside of updated at the very top we will
import subjects from subjects well then export an interface called Ticket updated event will say that
this thing is going to have a subject of subject start ticket updated and will have some data as well.
Now we've been kind of just assuming that these tickets and the data around them was going to be just
the I.T. title and price.
I think that still stands for right now until we realize that we need some extra information.
I think we'll just stick with saying we're going to emit information about the I.D. title and price
of the ticket.
So if we emit an updated event well we probably want to include the updated information about this ticket.
So once again just idea of string title of string and price of number.
There is one other property that we might want to immediately add in however.
Back inside of our tickets project if we open up that model's directory and take a look at our definition
of what a ticket is.
You might recall that a ticket also has a user I.D. property.
We might want to add that into these two event definitions right away because there might eventually
be some service that cares about who owns a ticket in particular.
So let's add that into the event definition or ticket updated and ticket created in both them are going
to add in a user I.D. That is a string so there it is inside of updated.
I'll then go over to created at an user I.D. That is a string as well.
ALEX Good Now one other comment I want to throw out there inside this coming module.
We basically have everything just mixed up inside of this event's directory.
So we've got the base listener base publisher we got a listing of subjects and then eventually we'll
have a lot of different files inside of here as well to describe all the different kinds of events.
If you want to come up with a different structure for this directory definitely go for it.
I think that it doesn't make a lot of sense to mix all these folders or all these files together especially
since we're going to eventually have several others in here as well.
So if you could think of a better way of organizing this directory certainly feel free to do so.
Just remember whenever we do an import statement you will have to adjust some parts.
If you start to nest these files inside of some other folders All right.
So before we do a republish of our coming module let's remember we have to go into our index not t yes
file at the roots s our C folder and we have to export the contents of all these events files so we
can easily import them into other services so inside of here we'll do an export star from events base
listener and then just gonna copy paste that down a couple of times I think five ought to do it the
next one will be based publisher then subjects ticket created event and ticket updated event and that
should be at now last step.
We're gonna go back over George terminal we're going to install no Nat streaming into our company module
we're then going to republish this module and then update for right now just our ticket service so I'm
gonna go back to my terminal I'm going to close down everything I'm running around us Nat's test stuff
most going to stop the cubes TTL port forwarding stuff I'm then going to change over to our common directory
I'm going to install node that's streaming
and then finally I'm going to do an NPM run hub that was what our script was right was just simply pub
let's take a look inside of common module Yep it was just pub will do NPM run pub that will do the commit
the build the version delete the build do the publish all that stuff and it looks like I'm now on version
1 0 1 3.
Now we'll go back over to our ticket service also inside of our terminal and we'll do that update I'll
go back or you tickets and NPM run me at NPM updates.
That's better SGA tickets Bowman now going to expect to see some update message saying that this thing
has been updated to one point 0 1 3 for me in particular your version is probably different at this
point Yep there we go.
All set.
All right.
Well we are pretty much done for right now anyways with this common module.
We now have our listing of events inside there and as I mentioned over time we're going to come back
to this thing and add in some other types of events.
So let's take a pause right here.
When we come back the next video we're going to go back to working on our ticket service.
We'll make sure that any time someone creates a new ticket or anytime someone updates a ticket we will
publish an event saying hey ticket update it so quick pause and I'll see you in just a minute.