Let's go ahead and put our events handlers together for the Postal Service and the common service.
So I'm going to get started by going first to my post service.
I'll find the index such as file and then turn the very bottom the file but right above the apt listen
line I'll add in a new post request handler.
So this will be asked post to slash events.
We'll get our rack and rest in their
and then remember this end point is going to receive any event that is coming over from our event bus.
So right now inside of our postal service we don't really care about any events that are coming over.
But let's just go ahead and log any events that we receive just to say hey this event exists I'll do
a console dot log of received event
and we'll just print out the type of the event.
How about wreck dot body that's gonna be the actual event.
And remember every event that we receive we said that it was going to have a type property dial up print
out the type of event that we just got after that.
I'll make sure that I still respond to the request that was issued just to say hey we got this.
We'll do a red dot send of empty object just to say yeah we got this event.
Everything's good to go so now repeat the same process over inside of our common service as well.
They'll find my comments directory index dot J.S. inside of there we'll go down towards the bottom and
right above the apt Atlas in line.
I'll do an app dot post for events
we'll do a console log of event received and wreck dot body type
and we'll do our resource sent empty object OK.
So that should be enough to test this stuff out.
Now we're going to really see the entire process here.
We're going to see everything from start to finish if we take a look at our terminal after we start
to we met some events we should see some console log coming from our post service and the comment service
and they should say every single time they receive some kind of event so let's try to test this out.
I'll go backwards the browser and find my application.
I'm going to refresh the page once again.
Remember every single time we make a change to our code we dump all of our data.
I'll go ahead and create a post of say new post and submit if I refresh.
Yep there's the post.
But more importantly let's go over to our terminal.
Here's my terminal window and I can see that we've received an event for post created inside of our
postal service.
This terminal window right here is from my comment.
And we've also received an event of post created or event bus is still during an air down here.
That's OK because remember it's trying to send a request or this event over to our query service which
does not yet exist let's also try to create a comment and just make sure that the event of comment created
is being sent to the post common service as well so back inside my browser.
I'll put in a comment here of a comment submitted I'll refresh.
Just make sure I see the comment right there.
And then finally I go back or maternal.
There we go.
So I've got my event of common created and common created.
OK.
So that is it.
That is the full communication cycle.
We have our postal service sending events over the event bus takes that event and sends it off to service
one and two and then a little bit.
Not quite yet but in a little bit I'll try to send off to the query service as well.
So in theory if we had any kind of data dependency or more strict data dependency between our post service
and common service we could watch those incoming events and deal with them in some way.
As I've said several times down the last couple of videos the post and comment service don't really
care about the events that are being emitted right now.
But now that we've got these events coming out let's start to put this query service together we'll
make sure that the query service listens for a post created or a limit created event starts to take
that data and assemble it into some kind of usable data structure in the exact same way that we've discussed
over all these last couple of diagrams.
Where are they like this one.
Yeah.
Here we go like this one right here.
Remember we're going to take all these events and assemble them into some usable data structure.
So we're going to take more than just a moment.
So see you.
And just a little bit.