WEBVTT 00:04.480 --> 00:10.480 We have just successfully created the basic producer using technology and we have produced a single 00:10.480 --> 00:11.080 message. 00:11.150 --> 00:11.950 Hello, Kafka. 00:12.020 --> 00:16.840 Yes, you are to test Dobek and this topic was created automatically. 00:17.290 --> 00:22.750 Now, let's expand this example further and let's create another topic called animals. 00:22.930 --> 00:27.040 And afterwards, we will use a package called Chance. 00:27.160 --> 00:34.270 And using this package, we will generate random names of animals and produce them in every separate 00:34.270 --> 00:37.270 message using our NOGs application. 00:37.330 --> 00:38.050 That's the plan. 00:38.450 --> 00:45.300 Let's start by defining a topic name here on the topic, and it will be equal to animals like this. 00:45.610 --> 00:50.540 And next, let me copy this section where we call producer docent method. 00:50.740 --> 00:57.280 Let me actually call it and let's use set interval and we will create a separate function that will 00:57.280 --> 00:59.290 be called, let's say every second. 00:59.590 --> 01:07.870 Let's use that interval and here will be a function producer message and the let's call this function 01:07.870 --> 01:10.540 every one thousand milliseconds like that. 01:10.690 --> 01:12.940 And let's define this function here above. 01:12.970 --> 01:19.140 It will be a synchronous function const produce message, equal sign. 01:19.150 --> 01:25.230 I'll use the arrow function expression, syntax, async without any parameters, error or function. 01:25.390 --> 01:30.910 And here inside I could use that right here in order to catch any errors if any. 01:31.090 --> 01:36.130 And if I die Putri, I am able to select a track from dropdown. 01:36.130 --> 01:38.410 It will allow complete the track block. 01:38.680 --> 01:44.920 This functionality is available in visuals to the code out of the box and here in a dry section. 01:45.100 --> 01:47.380 Let me call producer doesn't. 01:47.560 --> 01:52.120 And here, in case of an error, let's simply look to the council. 01:52.130 --> 01:54.040 This error like this. 01:54.490 --> 01:55.810 Great and the null. 01:55.810 --> 02:00.280 Let's modify this function call and the Hill will be simply a topic. 02:00.640 --> 02:03.640 I could remove this part and reuse the topic variable. 02:03.640 --> 02:06.400 Here it is property shorthand for objects. 02:06.670 --> 02:09.640 And the next day we need to modify message value. 02:09.730 --> 02:14.530 And according to our plan, we need to generate random names of animals. 02:14.690 --> 02:20.980 So let me remove this string from here and now let's install additional and B.M. package and we will 02:20.980 --> 02:25.660 use Janns package and we could install it simply like that and install. 02:26.470 --> 02:33.480 Let's go to Visual Studio Code to open up and by the terminal and the here in the project, use NPM, 02:33.490 --> 02:35.380 install Chens. 02:37.180 --> 02:42.760 Package was installed and now we are able to use it, let's go to documentation and let me find out 02:42.850 --> 02:44.450 how to use it, actually. 02:44.800 --> 02:48.030 Let me open up a full docs from here. 02:49.520 --> 02:57.350 Let's find out how to use this package in Nagus Select here in the user section, NOLDE And we have 02:57.350 --> 03:02.810 already installed the chance like that and now we need to lower the chance like this and afterwards 03:02.810 --> 03:05.540 initialize gels using new keyword. 03:05.870 --> 03:06.190 Great. 03:06.200 --> 03:10.490 Let's go to our application and let's require it. 03:10.640 --> 03:14.360 Gon's the chance equals sign a require. 03:15.990 --> 03:16.530 Jens. 03:17.400 --> 03:21.900 And afterwards, initialise new instance of Jenniskens, the Genz. 03:22.880 --> 03:30.230 Equals sign new chants, and now we are good to go and we should be able to use methods of the chance, 03:30.590 --> 03:39.310 let's use it here on the place of the value and here will be chance that and now we are able to generate 03:39.410 --> 03:44.410 any random values like random address or random age, random avatar and so on. 03:44.720 --> 03:52.040 But our goal is to generate the name of animals and the here we would use method animal like this and 03:52.040 --> 03:53.560 we need to call it like soul. 03:53.960 --> 04:00.460 And after calling this method, we should have random names of different animals actually extract that 04:00.470 --> 04:03.110 this value here, let's call it simply. 04:03.140 --> 04:04.280 Well, like so. 04:04.430 --> 04:10.370 And its value will be a result of called to annual method of the chance object. 04:10.370 --> 04:12.990 And here I'll use proper shorthand like that. 04:13.280 --> 04:15.560 So here, let's use it like so. 04:15.680 --> 04:17.800 And also let's bring to the council here. 04:17.810 --> 04:21.830 Well, in order to see meaningful dialogue here in this producer. 04:22.190 --> 04:29.450 And it seems that now we are good to go and this producer should produce messages every one second here 04:29.450 --> 04:35.930 with this set and we set interval and every message will have a value that is equal to random value 04:35.930 --> 04:38.690 of any animal, let's say, of this code. 04:38.690 --> 04:41.380 And let's actually create the topic animals. 04:41.570 --> 04:44.600 Let's go to our magic file with all commands. 04:44.600 --> 04:51.050 Let's find a command that will create a new topic and I'll create Dobek, let's say, with five partitions 04:51.050 --> 04:52.970 and replication of phase three. 04:53.150 --> 04:55.580 And the topic name will be animals. 04:56.600 --> 05:03.240 Let's copy this command to go to time and I'll make sure that you are in Kafka folder. 05:03.500 --> 05:09.770 Let me actually open up new terminal window Sinitta Kafka and here is a good command that will create 05:09.770 --> 05:10.620 a new topic. 05:11.900 --> 05:18.560 Topic was successfully created, let's now verify that and let's simply list all topics created in our 05:18.560 --> 05:19.560 coffeecake last hour. 05:19.820 --> 05:22.970 Let's execute this command with least option. 05:24.070 --> 05:30.790 And yes, I see Animal Storbeck here on the list and we also see test topic that was created automatically 05:30.940 --> 05:32.240 in a previous lecture. 05:32.470 --> 05:33.040 Wonderful. 05:33.250 --> 05:37.410 Now we're able to switch to our producer and produce some messages. 05:37.720 --> 05:40.790 But before that, let's start calling for consumer. 05:41.020 --> 05:43.360 It should be run here in this step. 05:43.360 --> 05:47.410 But let's start with topic animals as argument like. 05:47.410 --> 05:51.690 So replace this topic with animals and let's start calling consumer. 05:51.700 --> 05:55.840 Let's now go to our producer and let's started let's open up. 05:55.840 --> 06:03.400 And by the time animal control back and let's clear it and enter old producer dogs. 06:04.480 --> 06:12.490 And it works, we see that every second some random animal name is generated and is sent to our coffeecake, 06:12.520 --> 06:13.080 Glassboro. 06:13.390 --> 06:17.100 Let's go to our consumer and verify whether it receives messages. 06:17.110 --> 06:22.080 And yes, it successfully receives a new message every second grade. 06:22.210 --> 06:28.180 That's how we were able to adjust our producer and generate different messages every second. 06:28.450 --> 06:30.910 I think that that's all for this producer. 06:30.910 --> 06:36.250 And now we're able to proceed and create the consumer using North Jersey. 06:36.490 --> 06:41.260 Let me stop this application controversy and I'll see you in the next lecture. 06:41.290 --> 06:41.770 Bye bye.