WEBVTT 00:04.180 --> 00:09.730 We have just briefly reviewed the most important parameters that you are able to set up on a consumer 00:09.730 --> 00:16.060 level, and now let's proceed and let's have a look at another example where we will not use all the 00:16.060 --> 00:19.740 commit and instead we will commit messages manually. 00:19.990 --> 00:25.960 And also let's instead of writing messages just to terminal, let's try to write them, for example, 00:25.960 --> 00:26.890 to file. 00:27.010 --> 00:30.310 And this will actually simulate the some time consuming cooperation. 00:30.430 --> 00:36.100 And actually, instead of writing to file, you are able to write messages to database to send them 00:36.250 --> 00:38.530 to any other services or something like that. 00:39.100 --> 00:46.000 Let's know, actually quickly rename this The Glass and the or name it to consumer with all the commit 00:46.150 --> 00:49.000 consumer with on it like that. 00:49.180 --> 00:55.690 And also let's rename our file, let's go to project and let's remember this consumer digital file. 00:55.930 --> 00:57.610 Right Miles click or a factor. 00:57.610 --> 01:05.180 And here select or a name file and let's give it name consumer with all the commit and click refactor. 01:05.560 --> 01:05.950 Great. 01:06.230 --> 01:10.900 Let's not create one more consumer and actually let me copy contents of this file. 01:11.050 --> 01:18.700 And the last great consumer was manual commit and the Hills create new Java class and here will be consumer 01:18.700 --> 01:22.450 with manual gumede like this. 01:22.930 --> 01:28.720 And here let's remove this section and let's based on what we have copied from consumer was to commute 01:28.960 --> 01:34.780 and here will be the name of the glass consumer with manual commit like this. 01:35.110 --> 01:41.590 Let's hide this left brain and let's Glaus consumer with auto commit and let's actually stop it. 01:41.590 --> 01:43.330 Here was go to run. 01:43.330 --> 01:46.480 Stop it from here and let's close this step. 01:46.480 --> 01:47.650 We don't need it anymore. 01:48.040 --> 01:48.430 Great. 01:48.670 --> 01:51.310 Let's now adjust settings for this consumer. 01:51.310 --> 01:56.140 Well we will use manual commitment and we don't need to commit intervale like that. 01:56.350 --> 01:59.950 And also actually we're able to get rid of a consumer group. 01:59.950 --> 02:05.140 But let's leave it in place and let's name it the second group like this. 02:05.620 --> 02:11.470 Also, let's leave a bootstrap servers, the serializer and the through lines are unchanged. 02:11.710 --> 02:15.840 And let's also work with the topic numbers, same as before. 02:16.510 --> 02:21.190 Also, we will initialize consumer the same as in the first example. 02:21.190 --> 02:25.810 And here subscribe to all topics supplied here in this list. 02:26.200 --> 02:26.620 Great. 02:26.830 --> 02:29.840 Also, we will use a track approach, same as before. 02:29.980 --> 02:35.320 And here in the previous example, we have simply looped through all the records that we receive from 02:35.320 --> 02:41.780 the Breuker and we have pulled for new records every one hundred milliseconds and for each message. 02:41.800 --> 02:46.240 We have actually created this formatted and printed such thing to the timing. 02:46.240 --> 02:47.080 No, no. 02:47.080 --> 02:50.410 Let's adjust the behavior and write messages to the Baffour. 02:50.530 --> 02:57.700 And as soon as specific amount of Forsys for this buffer is reached, we will write messages in bulk 02:57.880 --> 02:58.990 to specific file. 02:59.140 --> 03:04.810 And afterwards, when messages will be read into the file, we will send the message to the Breuker. 03:05.290 --> 03:10.900 Let's now go back to documentation and here I'll show you how to find the similar example. 03:11.050 --> 03:16.830 Let's go to Consumer API here, Waties, and click here on Javadoc. 03:16.840 --> 03:18.760 Let me open it up in a new tab. 03:19.760 --> 03:25.670 We have actually looked at the first example here, and let's have a look at the next one with a manual 03:25.670 --> 03:32.030 of state controlled this one and actually, let's agree, the minibike size similar to this. 03:32.240 --> 03:40.040 Let me copy this line from here and it will be Sayas in Byatt's and go here and let's define it here 03:40.040 --> 03:40.490 above. 03:40.790 --> 03:48.450 And also let's actually write first messages to Baffour like this and afterwards we will check whether 03:48.450 --> 03:52.070 a bar or size is greater than minibike size. 03:52.070 --> 03:59.270 And if so, we will riot control of the buffer to the file instead of right in to the beam and afterwards 03:59.270 --> 04:05.870 we will commit sinc send the message to Breuker and afterwards we will clear buffer. 04:06.200 --> 04:06.530 Great. 04:06.540 --> 04:07.070 Let's do that. 04:07.310 --> 04:12.980 Let's in this fall loop where we loop through all the records and let's add the record to the buffer 04:12.980 --> 04:19.440 like this buffer at and here with the record and of course about we need to define buffer with me, 04:19.450 --> 04:24.170 copy and paste here below definition of mean rightsized like that. 04:24.560 --> 04:27.290 And afterwards we are able to check away. 04:27.290 --> 04:30.830 Whales are buffer or size is greater than min size. 04:30.950 --> 04:34.820 And if so, we will perform some actions with buffer. 04:35.030 --> 04:46.760 OK, if buffer size is greater than or equal M.H. size, then let's write the barrier to the file right 04:46.940 --> 04:52.100 to file and we could use here file right or class and let's create a new file. 04:52.100 --> 04:55.730 Right or here file right like this. 04:55.730 --> 04:59.530 Let's press step and it will be important from Java dot either. 04:59.540 --> 05:00.230 Here it is. 05:00.620 --> 05:06.290 And the next list name very simply file Riata and let's create new file writer. 05:06.290 --> 05:08.030 And here will be two arguments. 05:08.390 --> 05:14.810 First one is file name and let's write the contents of the messages to the file located simply on the 05:14.810 --> 05:15.380 desktop. 05:15.770 --> 05:23.690 We can go to Tamino and open up new tab here, Sinitta desktop and the healthiest command print Rokan 05:23.690 --> 05:24.350 directory. 05:24.560 --> 05:32.200 And let's copy this path and let's write messages to the file named nom de text to get it on the desktop. 05:32.480 --> 05:37.430 So let me copy this path go here Pei's this path here and the next after. 05:37.820 --> 05:45.440 Let's add the name of the file numbers like this and also let's apply here second argument and let's 05:45.440 --> 05:47.420 simply here type through. 05:47.750 --> 05:53.930 And with this argument in place we will be able to append contents to existing file. 05:54.470 --> 05:56.240 OK file right. 05:56.240 --> 06:00.690 Or was created and we could use here append the method of the file lyoto. 06:00.830 --> 06:07.820 So file right dot append and here let's as argument possible for a converted to string. 06:07.820 --> 06:10.280 So Baffour to string like this. 06:10.940 --> 06:14.600 Also you may notice that the intelligence underlines file. 06:14.600 --> 06:14.930 Right. 06:15.080 --> 06:18.950 And that means that we need to add exception to Mathilde's signature. 06:18.950 --> 06:19.580 Let's do that. 06:19.760 --> 06:26.600 And here you'll see that thralls IO exception will be added to definition of our main method and the 06:26.600 --> 06:26.990 next. 06:26.990 --> 06:31.070 After writing batho to the file, let's commit the offset. 06:31.070 --> 06:38.480 And for that let's use method of the consumer consumer dot to commit and lets us commit sin like this. 06:38.750 --> 06:44.330 And this will actually send a message to the broker of the contents of the buffer will be returned to 06:44.330 --> 06:45.050 the file. 06:45.290 --> 06:52.130 And afterwards, let's clear the for here in this if statement bar for clear like this. 06:52.370 --> 06:59.120 And also let's close file writer and the we could close it here where we close our consumer. 07:00.130 --> 07:08.890 File writer Dot glows like this, and it seems we are good to go and everything is set up and let's 07:08.890 --> 07:12.120 try to start our consumer with the manual commit. 07:12.490 --> 07:19.180 And for that, let's scroll up and find a definition of the main method and run consumer with the manual 07:19.180 --> 07:20.200 commit domain. 07:22.700 --> 07:28.850 Compiling and consumer will started, let me make it a bit larger and here let's go to our producer 07:28.850 --> 07:33.840 and the star producer as well and produce some messages to the topic numbers. 07:34.010 --> 07:34.700 Here it is. 07:35.000 --> 07:36.980 Let's start the main method here. 07:38.120 --> 07:40.400 On producer LogMeIn, OK? 07:40.700 --> 07:42.320 One hundred messages were sent. 07:42.350 --> 07:49.130 Let's go to consumer and it seems that we see those messages here in the terminal and that's because 07:49.130 --> 07:53.300 we have left in our consumer those two lines. 07:53.330 --> 07:54.770 Let me scroll down. 07:54.770 --> 07:55.550 Here they are. 07:55.790 --> 08:00.140 And I have left them here on purpose in order to see the contents of the messages in a terminal. 08:00.320 --> 08:08.600 And now let's go and see whether some contents have appeared in the file called No Duty, still located 08:08.600 --> 08:09.330 on the desktop. 08:09.620 --> 08:13.430 Let me go to the terminal here and let's else files here. 08:13.430 --> 08:15.710 And this file was created here. 08:15.710 --> 08:20.590 And let's actually have a look at the numbers, dot the extreme and it is empty. 08:20.840 --> 08:29.050 Probably the reason for that is that the buffer size was not yet reached 200 bytes like in this setting. 08:29.390 --> 08:36.570 Let's no actually try to produce some just more go to producer started over again, produce hundreds 08:36.570 --> 08:37.280 more messages. 08:37.610 --> 08:41.240 Let's now go and verify contents of the numbers, the text file. 08:41.270 --> 08:43.340 And yes, here are some comments now. 08:43.640 --> 08:47.780 And that means that the process science has reached its limit specified here. 08:47.990 --> 08:51.430 And actually we are able to track the size of the buffer. 08:51.430 --> 09:00.950 For example, let's as odd here, buffer our size and let's add some meaningful log buffer size is and 09:01.250 --> 09:05.930 let's use plus and concatenate bar for those size like that. 09:06.840 --> 09:07.620 Let's save. 09:08.650 --> 09:13.030 And let's roll around, the consumer actually started over. 09:14.390 --> 09:17.010 And here you'll see those logs, barrel size zero. 09:17.030 --> 09:20.980 Now let's go to producer and sand, the 100 meter just again. 09:21.650 --> 09:23.950 Now we see that barrel size is one hundred. 09:23.960 --> 09:26.180 Let's send more massages. 09:27.100 --> 09:33.790 And now I see that the process is zero again, and if I stop by consumer and scroll up, you will see 09:33.790 --> 09:36.720 that at some moment of time before size became 200. 09:36.940 --> 09:44.140 And after that, the consumer has written the contents of the Balfa to file and afterwards BofA was 09:44.140 --> 09:44.560 cleared. 09:44.920 --> 09:50.830 Let's now go back to the terminal and again read contents of the numbers, the text file, and here 09:50.860 --> 09:53.650 you'll see actually contents of every message. 09:53.890 --> 09:59.620 And in the same way, you are able to write messages, for example, the database or perform any hours 09:59.620 --> 10:06.210 of actions and only after that bathroom commit and commitment is done here on this line. 10:06.610 --> 10:12.370 And actually, let me remove this line and we are done with this example in the next example with consumer. 10:12.520 --> 10:19.180 I want to show you how you are able to assign consumer to specific partitions, because in this example 10:19.180 --> 10:23.410 and in the previous example, we have subscribed to the entire topic. 10:23.410 --> 10:30.550 No Storbeck in our examples, but you are able to assign consumer just to selected partitions and less 10:30.550 --> 10:31.960 divided in the next example. 10:31.990 --> 10:32.860 I will see you next. 10:32.860 --> 10:33.340 By by.