Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,140 --> 00:00:05,520
We've now got an initial implementation of our event plus but together we're not going to start to go
2
00:00:05,520 --> 00:00:08,460
through our Postal Service and our common service.
3
00:00:08,610 --> 00:00:13,320
Anytime something interesting happens inside those services such as creating a new post or creating
4
00:00:13,320 --> 00:00:19,170
a new comment we're gonna make sure that we send a request over to this events and point in our event
5
00:00:19,170 --> 00:00:26,470
bus and in that request we're going to include the event event plus we'll then take that event and echo
6
00:00:26,470 --> 00:00:32,260
it out to all the different services running inside of our application at present are different services
7
00:00:32,290 --> 00:00:35,510
do not have this post events and point wired up.
8
00:00:35,590 --> 00:00:40,400
So when the event bus tries to send that request over the request is going to fail due to a for a for
9
00:00:41,200 --> 00:00:46,150
as soon as we make sure that the event bus can emit this event will then go back over and start to implement
10
00:00:46,150 --> 00:00:51,050
these end points that the other services can listen to these events that are being emitted.
11
00:00:51,280 --> 00:00:55,560
But again right now we're just gonna make sure that the Postal Service is going to meet this event anytime
12
00:00:55,570 --> 00:00:58,830
someone creates a new post so let's get to it.
13
00:00:59,830 --> 00:01:05,200
Between the last video and this one I opened up my code editor inside of my roots blog project directory.
14
00:01:05,320 --> 00:01:10,270
We're going to start to have to change between all for these different services very quickly and so
15
00:01:10,270 --> 00:01:15,190
it's just a lot easier to maneuver between them if we have all of our projects open inside of one editor
16
00:01:15,220 --> 00:01:17,370
as opposed to four separate editors.
17
00:01:18,490 --> 00:01:23,720
I'm going to find the post directory inside there I'll find the next dot J File at the very top.
18
00:01:23,720 --> 00:01:33,210
I'll immediately require an axis like so and then going to scroll down to our post end point.
19
00:01:33,370 --> 00:01:37,500
So this is the code that gets executed every single time someone tries to create new post.
20
00:01:37,540 --> 00:01:44,380
So this would be a perfect time to try to emit an event saying hey someone just made a new post right
21
00:01:44,410 --> 00:01:47,530
after we add the new post to our post collection.
22
00:01:47,740 --> 00:01:52,630
I'll use axioms to make a post request over to age TTP.
23
00:01:52,640 --> 00:01:58,220
Colin flash flash local host in four thousand five.
24
00:01:58,240 --> 00:02:01,800
Because remember that is where a broker is running flash events
25
00:02:05,090 --> 00:02:09,540
and then as the second argument we'll put in the actual event that we want to send over.
26
00:02:09,680 --> 00:02:13,560
So for right now we'll say that every event that we met is going to have two properties.
27
00:02:13,730 --> 00:02:19,020
The first one is going to be a type and that type describes that event that just occurred the second
28
00:02:19,020 --> 00:02:23,670
property will be a data property and that will have some information that further clarifies exactly
29
00:02:23,670 --> 00:02:29,250
what happened in the case of creating a post we'll probably include the actual post that was just created
30
00:02:29,340 --> 00:02:31,170
as the data property.
31
00:02:31,170 --> 00:02:35,910
Remember that event that we send out throughout our application can have any structure we want.
32
00:02:36,030 --> 00:02:39,050
It doesn't have to be an object it can be a string or a number.
33
00:02:39,060 --> 00:02:40,580
Any data you want to have.
34
00:02:40,980 --> 00:02:45,080
But usually we're going to make sure that all these events have a very consistent structure.
35
00:02:45,090 --> 00:02:49,530
We'll talk more about the design and sort of schema of events quite a bit over time.
36
00:02:49,550 --> 00:02:51,950
Right now we're just gonna say that every event will have a type.
37
00:02:51,990 --> 00:02:59,480
And data gets us the object right here is essentially the event that I want to have emitted or my entire
38
00:02:59,480 --> 00:03:07,120
application going to give it a type of post created and then a data and data is going to be the post
39
00:03:07,150 --> 00:03:08,350
that we just made.
40
00:03:08,380 --> 00:03:11,040
I remember all of our posts have an I.D. and title.
41
00:03:11,170 --> 00:03:12,980
That's essentially what our post is.
42
00:03:13,030 --> 00:03:17,830
So we pretty much want to take that style of object right there included as the data property.
43
00:03:17,830 --> 00:03:25,980
We'll say I.D. and title then finally this is an asynchronous operation making the network request.
44
00:03:25,980 --> 00:03:36,350
So we will add on async and await like so that I'm going to say this we're gonna flip back over to our
45
00:03:36,350 --> 00:03:39,480
browser and find our running react application.
46
00:03:39,550 --> 00:03:43,940
I'm going to refresh this page and as soon as I do you'll notice that all the posts go away.
47
00:03:43,940 --> 00:03:48,830
That is totally fine it's because remember all of our posts are being stored in memory with that post
48
00:03:48,830 --> 00:03:49,640
service.
49
00:03:49,640 --> 00:03:54,860
So as soon as we restart that server all of our posts just disappear.
50
00:03:54,870 --> 00:04:00,710
All right I'll go ahead and try to create a post we'll call this new post and submit it.
51
00:04:00,780 --> 00:04:05,790
We don't have any kind of live reload on the react application so I have to refresh the page as soon
52
00:04:05,790 --> 00:04:08,330
as I do so I do see the new post appear.
53
00:04:08,420 --> 00:04:09,930
What happened to that event.
54
00:04:09,930 --> 00:04:11,740
Well let's go take a look at our terminal.
55
00:04:11,760 --> 00:04:13,410
We'll take a look at our server logs.
56
00:04:13,410 --> 00:04:20,730
We'll just make sure that the postal service did try to send that event over to the event plus that.
57
00:04:20,740 --> 00:04:23,300
So here are my terminal logs right here.
58
00:04:23,350 --> 00:04:25,180
This second window that I have right here.
59
00:04:25,210 --> 00:04:27,850
That's kind of highlighted is the postal service.
60
00:04:27,850 --> 00:04:30,430
I don't see any information there that's very interesting.
61
00:04:30,430 --> 00:04:34,720
If I go down to the bottom window right here that is where might event broker or event plus is living
62
00:04:34,780 --> 00:04:37,100
or actually running at present.
63
00:04:37,130 --> 00:04:42,540
It looks like there was a couple of errors here so all these errors are identical in nature.
64
00:04:42,570 --> 00:04:46,140
They'll say request failed with status for 0 4.
65
00:04:46,140 --> 00:04:47,660
So that is actually good.
66
00:04:47,730 --> 00:04:53,490
Remember as I mentioned just a moment ago our post service comment service and query service that doesn't
67
00:04:53,490 --> 00:04:57,680
exist did it exist yet does not have this post slash events end point.
68
00:04:57,690 --> 00:05:00,440
You don't have any way of actually receiving these events.
69
00:05:00,660 --> 00:05:03,900
So even though the event bus is trying to send that event off.
70
00:05:04,200 --> 00:05:08,050
Well there's nothing receive it which is why we're getting that forum for error.
71
00:05:08,100 --> 00:05:09,720
So overall I'd say this looks good.
72
00:05:09,720 --> 00:05:13,740
We are definitely emitting an event to the event bus anytime something interesting happens inside the
73
00:05:13,740 --> 00:05:15,270
post service.
74
00:05:15,270 --> 00:05:17,460
Let's take a pause right here and continue in just a moment.
8226
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.