WEBVTT 00:04.250 --> 00:09.890 In the previous example, we agreed that the consumer was a manual commit, and we have read messages 00:09.890 --> 00:16.980 from the same topic as before it was numbers, but we have agreed that the bar for that contains actually 00:16.980 --> 00:18.880 a list of consumer records. 00:19.070 --> 00:25.850 And while looping through records that we received from brokers, we have added records to the bathroom. 00:26.000 --> 00:34.850 And as soon as the bar size reaches this minimum limit that is set here by each size, then we write 00:34.850 --> 00:37.570 the contents of the bathroom to file. 00:37.810 --> 00:41.030 Actually, you are able to perform any other operations you want. 00:41.360 --> 00:45.880 And afterwards we sent manual commit the message to the broker. 00:45.890 --> 00:50.910 We confirm that we have received a set of messages and afterwards weekly our bathroom. 00:51.320 --> 00:53.880 That's what we have done in the previous example. 00:54.170 --> 00:59.840 Now let's go back to our first example, this one consumer with all the commit. 01:00.050 --> 01:06.410 And based on this example, let's create the consumer that will connect only two particular partitions 01:06.410 --> 01:07.780 instead of entire topic. 01:07.940 --> 01:12.860 And for that, we will use here a sign method instead of subscribe method. 01:13.280 --> 01:16.790 OK, let me quote the contents of this entire file. 01:16.790 --> 01:21.770 And I don't need the consumer was manual commit and they don't need to do this as well. 01:21.890 --> 01:23.090 Let's create new glass. 01:23.090 --> 01:24.980 Right, Miles, click continue. 01:24.980 --> 01:32.900 And the Java class and name for this class will be consumer with the partitions assignment like this. 01:33.980 --> 01:40.190 And now let me select this deleted and paste of what I have copied from consumer without a comment, 01:40.400 --> 01:48.140 and let's rename this glass to Consumer with Partitions assignment like so no, let me hide those windows, 01:48.260 --> 01:49.430 this one and this one. 01:49.550 --> 01:52.550 And no, let's modify this consumer class. 01:52.880 --> 01:58.100 And instead of subscribing here, we will use consumer assign method. 01:58.100 --> 02:02.630 And if you'll go to the recommendation, you will be able to find a similar example here. 02:02.900 --> 02:09.770 In this example, there are two partitions and we create a new topic, partitions like so, and afterwards 02:09.770 --> 02:12.560 we use them in a method like this. 02:13.070 --> 02:14.360 OK, let's go here. 02:14.360 --> 02:22.550 And first of all, let's remove these topics variable and simply keep numbers variable as doing it will 02:22.550 --> 02:23.140 be topic. 02:23.420 --> 02:27.200 And here we will not use consumer to subscribe. 02:27.200 --> 02:30.280 Instead, we will use consumer to assign method. 02:30.560 --> 02:37.900 And here we will pass the array of partitions like this, and here we will use the topic protection 02:37.910 --> 02:38.330 class. 02:38.510 --> 02:46.400 If you'll press step here, it will be imported from Aperture Kafka dot com on and here will be an array 02:46.400 --> 02:48.020 of partitions like this. 02:48.380 --> 02:53.600 And let's first assign this consumer only to a single partition with a deep will say two. 02:54.020 --> 02:59.980 For this you need to use here assignment operator and here will be Array and the Hills create a new 02:59.990 --> 03:06.440 instance of topic partition and first argument here will be strewing and the second argument will be 03:06.440 --> 03:07.130 partition. 03:07.370 --> 03:14.390 Here we will use the topic variable as a topic name and the partition will be simpler to like solve 03:14.750 --> 03:18.110 and notice that the label will be added automatically. 03:18.230 --> 03:24.710 And now we are actually good to go and we are able to start this consumer and see whether it will read 03:24.710 --> 03:25.640 messages or not. 03:25.850 --> 03:31.280 Notice that the remaining part in this example, I'll leave unchanged and the we will be able to see 03:31.280 --> 03:31.790 partition. 03:31.790 --> 03:33.680 No, actually here in time. 03:34.260 --> 03:38.120 OK, let's open up terminal and froster, please close. 03:38.120 --> 03:41.330 And also consumers that are running will stop this one. 03:42.080 --> 03:46.070 Glos this and now let's around the consumer with partitions assignment. 03:46.070 --> 03:52.520 But before that, let me adjust the group idea and let's make it equal to the old group like that. 03:52.760 --> 03:56.780 And now let's go to run and run consumer with partitions. 03:56.780 --> 03:58.040 Assignment, main method. 03:59.860 --> 04:05.890 It seems that the consumer is now up and running and now let's go to our producer and generate some 04:05.890 --> 04:12.090 messages and we should expect that we will see the messages from Partition with Editta. 04:12.390 --> 04:19.170 So let's start our producer around producer, that main it has produced 100 messages. 04:19.390 --> 04:20.700 Let's go to consumer type. 04:20.710 --> 04:27.040 And if you scroll up, you'll see that it has received messages only from competition with Ideato, 04:27.340 --> 04:29.920 and that's what we actually expected. 04:30.430 --> 04:37.570 Let's also modify this array and let's assign one more partition to do the consumer and you could use 04:37.570 --> 04:38.440 the syntax like. 04:38.440 --> 04:41.830 So let me split it to different lines like this. 04:42.130 --> 04:45.900 And here on the next line will be new topic partition. 04:46.060 --> 04:47.710 And here will be a topic. 04:47.710 --> 04:52.180 And let's assign a partition with a let's say for like this. 04:52.570 --> 04:58.300 And let's now rerun the consumer with partitions assignment and produce some messages more. 04:58.840 --> 05:00.040 So let's restarted started. 05:00.850 --> 05:08.110 Consumer was that let's go to producer, run it over again, go back to consumer, and now we should 05:08.110 --> 05:12.310 expect to see messages from two partitions with Editta and with a default. 05:12.460 --> 05:14.200 And yes, it is the case here. 05:14.740 --> 05:19.420 This is how you are able to assign consumer to particular partitions. 05:19.750 --> 05:22.960 For that, you should use a sign method instead of subscribe. 05:23.290 --> 05:29.160 But please know that you are not able to combine, assign and subscribe method. 05:29.170 --> 05:31.390 You are not able to use them simultaneously. 05:31.690 --> 05:33.210 You will get an error and such case. 05:33.490 --> 05:34.720 This also this example. 05:34.720 --> 05:36.280 And I will see you next guys by.