In the last video we put together some sync code inside of our query.
Before we test this out we did try to make use of axial sin here but unfortunately our query service
does not yet have axles installed.
We haven't even required it into this index dot J as file so I got gonna go up to the very top of this
file.
I'm going to require in axioms I'll save this all then go back over to my terminal.
I'm gonna find the terminal window that is running my memory service I'm going to stop that thing I'll
install axles really quickly and they'll start that server backup OK.
ALEX Good.
So now we need to make sure that we can actually test this out effectively.
So I'm going to just go ahead and stop that server even though we just started it up.
So now we do not have any access to query.
It just doesn't exist but hopefully we can try to create some posts comments and whatever else those
events will be cached or stored by our event bus and then as soon as we launch query hopefully query
should be precinct and get all the different events that it has missed over time.
Let's try this out making sure that the query service is not running.
I'm going to go over to my browser I'm gonna refresh the page.
You'll notice I've gotten error inside my console right now and that is to be expected because the query
service does not exist.
Right now it's not running at all but I should be able to create a post so I'll go ahead and create
a post something like new post and submit now in theory this post has been created and we've gone through
that entire process of storing it on the post service and so on.
If I refresh right now I get another error again because the query server is done doesn't exist.
So now let's go back over to our terminal.
We'll go ahead and launch the query service and as soon as we do so it should reach out to our event
bus.
You'll notice there are some errors here you could ignore them.
It should reach out to our event bus and try to receive all the different events that it has missed.
It's going to start up the query service and you'll notice right away its process in event of post created
that's the event that it had missed.
So if I now go back with the browser I can refresh and there's my post.
Now they benefit to this approach.
If I kill my query service once again.
So now it's dead again.
Now I can start to maybe create some comments I can say comment no one I can create a comment.
Number two I can create even an invalid comment something with the word orange in it.
Something is going to get rejected.
Now if I refresh again once again I don't see anything because the query services down in the query
service has completely missed all these different events.
It hasn't seen any of the come and created any of the comment moderated or the common updated events.
Now let's relaunch query and instantly it's going to process all those different events that it just
missed out on.
Now if I go back to the browser I can refresh looks like the C and taking just a moment chances are
it's gonna refresh way faster for you.
There we go.
And now we can see that the query service is online and 100 percent up to date.
We've got our post we've got those comments and the comment that was rejected as well.
All right so you gotta admit that's pretty neat.
So this 100 hundred percent really deals with this issue of a service being brought online at some point
in time the future or possibly the case in which a service goes down for some very small period of time
and misses out on a couple of that events.
We're going to use this strategy very heavily as we start to work on our next application.
Now if you see some issues with this approach and there are some problems inside of here without a doubt
don't sweat it.
There are corner cases and we are going to cover these corner cases particularly around the possibility
of having like persistent data.
Right now none of our data is persistent we store it inside of some in-memory data structure that's
lost instantly whenever a service goes down but if we were using a database where we were storing these
posts and comments inside of some database would say that query service you might be thinking Hey we'll
get into some trouble here if we try to run the same event or process in the same event twice.
Again if you're thinking that don't sweat it.
There are solutions to it that we're going to implement in our next application.
Okay.
So this entire idea of sinking events looks like it's pretty handy.
So pause right here continue in just a minute.