WEBVTT 00:04.500 --> 00:10.470 Before we have finished with our producer that the producers of random animal names are each second 00:10.470 --> 00:15.290 and the no, let's create the consumer that will consume those messages from animal storbeck. 00:15.540 --> 00:23.100 And for this, let's create another file here in front of our project and let's name it consumer dogs. 00:23.290 --> 00:26.970 And let's now go be a part of the code from producer Dodgiest File. 00:27.000 --> 00:28.020 Let me go here. 00:28.050 --> 00:36.750 Let me temporarily closed terminal and let me select the entire section like soul based in consumer 00:36.750 --> 00:37.440 dogs. 00:37.740 --> 00:43.470 And next, let me actually remove this entire produce message function like this. 00:43.830 --> 00:50.400 Also, we don't need the chance here and we don't need the new instance of chance. 00:50.400 --> 00:59.130 Let's remove it like so let's replace client ideal with my consumer, like this broker or that will 00:59.130 --> 01:00.390 be unchanged here. 01:00.390 --> 01:03.390 We still have three different brokers in the cluster. 01:03.570 --> 01:10.200 And here let's create the new consumer that will be the result of the call to consumer method of the 01:10.200 --> 01:11.190 Kafka Object. 01:11.400 --> 01:13.680 And the topic will be still animals. 01:13.830 --> 01:19.150 And here we will consume messages consuming here. 01:19.170 --> 01:26.790 Let's first connect to consumer like this, and afterwards we need to subscribe to specific topic and 01:26.790 --> 01:28.250 read messages from the topic. 01:28.620 --> 01:33.060 Let's actually go to example for Kafka G.S. package. 01:33.060 --> 01:36.690 This one, scroll down to the section with Sample Consumer. 01:37.690 --> 01:44.350 Here it is, and we're able to use subscribe method like so, and afterwards we could use one method 01:44.350 --> 01:48.850 of the consumer and, for example, print each message to the council. 01:48.970 --> 01:49.540 Let's do that. 01:49.780 --> 01:56.470 Let me copy this part like so go to the housecoat and pasted here and here. 01:56.470 --> 01:58.780 We will subscribe to Typic. 01:58.930 --> 02:04.720 Let's use again property shorthand because we have defined the topic here above and we don't need to 02:04.720 --> 02:05.980 use from beginning fleg. 02:05.980 --> 02:08.280 But if you want, you could leave it in place. 02:08.620 --> 02:16.060 Let's use simply subscribe to topic and the here for each message we will bring to the console partition 02:16.060 --> 02:20.720 idea of offset idea of every message and well you convert it to string. 02:21.040 --> 02:22.880 Let's save this file. 02:22.930 --> 02:25.460 Let's start first producer goal here. 02:25.660 --> 02:26.320 Open up. 02:26.320 --> 02:31.960 Time in and let's again run it using node producer dirigibles. 02:32.910 --> 02:39.090 Let's start now with this produce and a random animal names, and now let's open up new terminal window 02:39.100 --> 02:42.310 like so we are still located in our Kafka project. 02:42.400 --> 02:49.230 Let's clear terminal and let's start consumer by end to note consumer dot Gere's. 02:50.180 --> 02:52.200 It seems that there was an error. 02:52.430 --> 02:55.850 Let me scroll up and verify what is that? 02:56.070 --> 02:59.210 And it seems that we need to specify a consumer group idea. 02:59.210 --> 03:00.720 Without that, it will not work. 03:00.950 --> 03:05.930 Let me go to consumer and find a place where we should actually do that. 03:06.590 --> 03:13.020 Maybe here, but probably it should be added somewhere here in the instance of the Kafka. 03:13.250 --> 03:20.240 Let me try to edit here, group I.D. and here will be a consumer group like. 03:20.240 --> 03:25.640 So let's save the file and let's try to rerun our application. 03:26.060 --> 03:31.700 We still get the same error and it seems that the group idea should be specified in a call to consumer 03:31.700 --> 03:32.150 method. 03:32.160 --> 03:36.050 Here, let me copy it from here and afterwards. 03:36.050 --> 03:43.370 Let's add new configuration object for consumer and based property group ID that will be equal to consumer 03:43.370 --> 03:43.690 group. 03:44.120 --> 03:49.670 Let's save the file and let's try to run our consumer, not consumer logs. 03:50.330 --> 03:56.900 And now it works and we are receiving your messages every second and notice that we are getting actually 03:57.170 --> 04:03.140 messages not every second, but instead we are getting them in batches after a specific amount of time. 04:03.230 --> 04:06.350 And we have discussed that in a previous section in details. 04:06.680 --> 04:12.830 And here in the console we see partition ID request that we have created the topic animals with file 04:12.830 --> 04:13.550 partitions. 04:13.820 --> 04:20.480 Also we see of said that is unique for every partition and we see values that are actually random names 04:20.480 --> 04:21.620 for different animals. 04:21.890 --> 04:24.620 And that means that our consumer works as well as. 04:25.040 --> 04:28.940 And now there is a producer that produces messages to our coffeecake. 04:28.970 --> 04:30.560 Last topic, animals. 04:30.770 --> 04:34.850 And also there is a consumer that consumers massages regularly. 04:35.360 --> 04:36.890 That's all for this lesson. 04:36.890 --> 04:42.380 And that's all actually for this section where we have reviewed how you are able to create the coproducer 04:42.380 --> 04:43.490 and Kafka consumer. 04:43.640 --> 04:50.300 You know, I guess I'll see you in the next section where we will try to create consumers and producers 04:50.300 --> 04:51.260 using Python. 04:51.620 --> 04:53.210 Have a break and they will see you next. 04:53.240 --> 04:53.650 Bye bye.