We have just briefly reviewed the most important parameters that you are able to set up on a consumer
level, and now let's proceed and let's have a look at another example where we will not use all the
commit and instead we will commit messages manually.
And also let's instead of writing messages just to terminal, let's try to write them, for example,
to file.
And this will actually simulate the some time consuming cooperation.
And actually, instead of writing to file, you are able to write messages to database to send them
to any other services or something like that.
Let's know, actually quickly rename this The Glass and the or name it to consumer with all the commit
consumer with on it like that.
And also let's rename our file, let's go to project and let's remember this consumer digital file.
Right Miles click or a factor.
And here select or a name file and let's give it name consumer with all the commit and click refactor.
Great.
Let's not create one more consumer and actually let me copy contents of this file.
And the last great consumer was manual commit and the Hills create new Java class and here will be consumer
with manual gumede like this.
And here let's remove this section and let's based on what we have copied from consumer was to commute
and here will be the name of the glass consumer with manual commit like this.
Let's hide this left brain and let's Glaus consumer with auto commit and let's actually stop it.
Here was go to run.
Stop it from here and let's close this step.
We don't need it anymore.
Great.
Let's now adjust settings for this consumer.
Well we will use manual commitment and we don't need to commit intervale like that.
And also actually we're able to get rid of a consumer group.
But let's leave it in place and let's name it the second group like this.
Also, let's leave a bootstrap servers, the serializer and the through lines are unchanged.
And let's also work with the topic numbers, same as before.
Also, we will initialize consumer the same as in the first example.
And here subscribe to all topics supplied here in this list.
Great.
Also, we will use a track approach, same as before.
And here in the previous example, we have simply looped through all the records that we receive from
the Breuker and we have pulled for new records every one hundred milliseconds and for each message.
We have actually created this formatted and printed such thing to the timing.
No, no.
Let's adjust the behavior and write messages to the Baffour.
And as soon as specific amount of Forsys for this buffer is reached, we will write messages in bulk
to specific file.
And afterwards, when messages will be read into the file, we will send the message to the Breuker.
Let's now go back to documentation and here I'll show you how to find the similar example.
Let's go to Consumer API here, Waties, and click here on Javadoc.
Let me open it up in a new tab.
We have actually looked at the first example here, and let's have a look at the next one with a manual
of state controlled this one and actually, let's agree, the minibike size similar to this.
Let me copy this line from here and it will be Sayas in Byatt's and go here and let's define it here
above.
And also let's actually write first messages to Baffour like this and afterwards we will check whether
a bar or size is greater than minibike size.
And if so, we will riot control of the buffer to the file instead of right in to the beam and afterwards
we will commit sinc send the message to Breuker and afterwards we will clear buffer.
Great.
Let's do that.
Let's in this fall loop where we loop through all the records and let's add the record to the buffer
like this buffer at and here with the record and of course about we need to define buffer with me,
copy and paste here below definition of mean rightsized like that.
And afterwards we are able to check away.
Whales are buffer or size is greater than min size.
And if so, we will perform some actions with buffer.
OK, if buffer size is greater than or equal M.H. size, then let's write the barrier to the file right
to file and we could use here file right or class and let's create a new file.
Right or here file right like this.
Let's press step and it will be important from Java dot either.
Here it is.
And the next list name very simply file Riata and let's create new file writer.
And here will be two arguments.
First one is file name and let's write the contents of the messages to the file located simply on the
desktop.
We can go to Tamino and open up new tab here, Sinitta desktop and the healthiest command print Rokan
directory.
And let's copy this path and let's write messages to the file named nom de text to get it on the desktop.
So let me copy this path go here Pei's this path here and the next after.
Let's add the name of the file numbers like this and also let's apply here second argument and let's
simply here type through.
And with this argument in place we will be able to append contents to existing file.
OK file right.
Or was created and we could use here append the method of the file lyoto.
So file right dot append and here let's as argument possible for a converted to string.
So Baffour to string like this.
Also you may notice that the intelligence underlines file.
Right.
And that means that we need to add exception to Mathilde's signature.
Let's do that.
And here you'll see that thralls IO exception will be added to definition of our main method and the
next.
After writing batho to the file, let's commit the offset.
And for that let's use method of the consumer consumer dot to commit and lets us commit sin like this.
And this will actually send a message to the broker of the contents of the buffer will be returned to
the file.
And afterwards, let's clear the for here in this if statement bar for clear like this.
And also let's close file writer and the we could close it here where we close our consumer.
File writer Dot glows like this, and it seems we are good to go and everything is set up and let's
try to start our consumer with the manual commit.
And for that, let's scroll up and find a definition of the main method and run consumer with the manual
commit domain.
Compiling and consumer will started, let me make it a bit larger and here let's go to our producer
and the star producer as well and produce some messages to the topic numbers.
Here it is.
Let's start the main method here.
On producer LogMeIn, OK?
One hundred messages were sent.
Let's go to consumer and it seems that we see those messages here in the terminal and that's because
we have left in our consumer those two lines.
Let me scroll down.
Here they are.
And I have left them here on purpose in order to see the contents of the messages in a terminal.
And now let's go and see whether some contents have appeared in the file called No Duty, still located
on the desktop.
Let me go to the terminal here and let's else files here.
And this file was created here.
And let's actually have a look at the numbers, dot the extreme and it is empty.
Probably the reason for that is that the buffer size was not yet reached 200 bytes like in this setting.
Let's no actually try to produce some just more go to producer started over again, produce hundreds
more messages.
Let's now go and verify contents of the numbers, the text file.
And yes, here are some comments now.
And that means that the process science has reached its limit specified here.
And actually we are able to track the size of the buffer.
For example, let's as odd here, buffer our size and let's add some meaningful log buffer size is and
let's use plus and concatenate bar for those size like that.
Let's save.
And let's roll around, the consumer actually started over.
And here you'll see those logs, barrel size zero.
Now let's go to producer and sand, the 100 meter just again.
Now we see that barrel size is one hundred.
Let's send more massages.
And now I see that the process is zero again, and if I stop by consumer and scroll up, you will see
that at some moment of time before size became 200.
And after that, the consumer has written the contents of the Balfa to file and afterwards BofA was
cleared.
Let's now go back to the terminal and again read contents of the numbers, the text file, and here
you'll see actually contents of every message.
And in the same way, you are able to write messages, for example, the database or perform any hours
of actions and only after that bathroom commit and commitment is done here on this line.
And actually, let me remove this line and we are done with this example in the next example with consumer.
I want to show you how you are able to assign consumer to specific partitions, because in this example
and in the previous example, we have subscribed to the entire topic.
No Storbeck in our examples, but you are able to assign consumer just to selected partitions and less
divided in the next example.
I will see you next.
By by.