Now, let's get started, though, with consumer configuration, and for that, we will create new glass
in our product, please navigate to SLC Main and Java and change our folder, create new glass and let's
give a name to this glass.
Simply a consumer like this.
Let's create the glass.
And here let's create quickly main method for that.
Simply diamine and press that wonderful.
And now let's create basic consumer that will consume messages from particular topic.
And at the moment we have actually two topics strings and the numbers.
And we're able to get messages from any of those topics before doing that.
Let's get back to the communication and find the how are you actually able to create a consumer?
Please go to capture dot org documentation back again.
Scroll down to Consumer API and let's observe what we need in order to start the consumer with Java.
And as you see here, we need to use the same Mavin dependency as we actually use them in producer API.
It is coffeecake lines in Abargil, that Kafka package.
So same package here.
We have already imported it to our project and you can verify that here in form that XML file here was
this dependency and that's the way we are good to go and we are able to start the creation of consumer.
Let's get back to documentation and let's open up in a new type of this.
Java docs lean open link in a new tab and here you'll see details for Kafka consumer class.
Let's go down and find the example that we could start actually with.
Let me scroll down.
And here was a basic example with automatic offset committing, you know, from previous sections that
the consumers commit messages that they are receiving and you are able to enable all to commit or you
are able to commit the method just manually.
And for example, if on a consumer or site you perform some actions with messages, for example, you
install them into a database or send to another service or something else, and you need to get confirmation
of that operation, for example, that you have successfully written messages into the database.
Then you could enable manual committing and send confirmation to brokers only when all operations on
consumer side were successfully completed, for example, when records were successfully returned to
database.
And with such manual, you may be sure that the old messages in the topic were successfully returned
to database.
But for now, in the first example, let's actually use all the competing and you could enable it to
the appropriate to enable us to commit and set up to do.
And also with the next set in the interval, you are able to specify how often the consumer will send
out to commit messages to brokers.
And in this example, they will be sent every second one thousand milliseconds.
Also, we need to use the key and while you're there, serializable.
And before I have explained you that every producer actually uses a specific serializer and Dinara example,
we use the students realize our FAKIE and Waialua, and that means that on consumer side you need to
use corresponding their serializer.
If you want to read messages from a specific topic where this producer has produced messages to and
in this case, we need to use corresponding serializer for strings.
And they are Goldust doing the serializer like this.
And also, of course, in order to create the consumer, you need to specify bootstrap severals.
And this option is the same.
As for producers, we need simply list all brokers in the class.
Of course, again, you are able to specify just a single several like in this example.
But it's not recommended if you have an entire class or with multiple zeros.
In such case, you should specify all zeroth in a class for redundancy grade.
And afterwards, after setting properties, you need to create a consumer from a consumer class and
to pass your properties.
Similarly, we have created the coproducer like that and afterwards we will subscribe to specific topic.
In this example, you'll see that we subscribe to a couple of topics and borrow.
And basically in our example, we will subscribe just to one topic and afterwards we start infinite
the while loop and pull consumer and try to get new messages every 100 milliseconds.
And if some messages are received in this example, we bring them to Tamino.
Please notice also that in this example there is group ID parameter at present and it is set to test
itself actually consumer group ID.
We will try to create consumer without group ID, but afterwards you'll see that the group ID is actually
required and.
We will set it like this great, let's go to our consumer configuration and let's create properties.
Properties.
Brewpubs.
Equals sign new properties and next.
Let's set up a broker or at least give you the serializer and enable us to commit with specific how
to commit inter-modal.
And let me actually go to producer and copy those three lines from here like this.
Go here to consumer based this property properties here.
This first line will remain unchanged.
Same list of brokers.
And here we need to replace Serializer with their serializer like this for key and value.
And also here we will use their serializer and here we'll be doing the serializer as well.
Great.
And afterwards, let's enable us to commit.
And let me actually go here to this example and copy those two properties from here in order to speed
up this process.
And actually, in example, set property method is used instead of let me replace it with put here and
put here as well.
Great.
Here we have all necessary properties for this first example.
And next, let's declare our topic variable like this and set it equal to Lombroso.
We were the first read from no storbeck like this.
And afterwards, let's create new consumer.
COFCO consumer here will be the types of parameters to industry, let's give a name to our consumer
or simply consumer, and let's create an instance of consumer class and health properties.
Variable as argument.
Great, our consumer was created and the next DELYTH subscribe to one of the topics and we have specified
already topic here.
And for that let's use consumer dot subscribe method and here as argument, let's pass formatted as
least array of topics.
And for that let's use a method of iRace class with type arrays.
Don't forget to press enter in order to import it.
And afterwards, let's use this method as least like this.
And here let's pass our topic as argument.
Actually, instead of a single topic, let's adjust to variable name to topics here and make it as array
of strings like this.
And here let's create an array of strings like soap.
And with such configuration in place, you will be able to add additional topics here to this array
if you want to create afterwards.
Let's actually start our infinite loop and let's start consumption from the topic specified here in
this topic array.
Let's not make a quick break and go on after the balls.