We have just successfully created the basic producer using technology and we have produced a single
message.
Hello, Kafka.
Yes, you are to test Dobek and this topic was created automatically.
Now, let's expand this example further and let's create another topic called animals.
And afterwards, we will use a package called Chance.
And using this package, we will generate random names of animals and produce them in every separate
message using our NOGs application.
That's the plan.
Let's start by defining a topic name here on the topic, and it will be equal to animals like this.
And next, let me copy this section where we call producer docent method.
Let me actually call it and let's use set interval and we will create a separate function that will
be called, let's say every second.
Let's use that interval and here will be a function producer message and the let's call this function
every one thousand milliseconds like that.
And let's define this function here above.
It will be a synchronous function const produce message, equal sign.
I'll use the arrow function expression, syntax, async without any parameters, error or function.
And here inside I could use that right here in order to catch any errors if any.
And if I die Putri, I am able to select a track from dropdown.
It will allow complete the track block.
This functionality is available in visuals to the code out of the box and here in a dry section.
Let me call producer doesn't.
And here, in case of an error, let's simply look to the council.
This error like this.
Great and the null.
Let's modify this function call and the Hill will be simply a topic.
I could remove this part and reuse the topic variable.
Here it is property shorthand for objects.
And the next day we need to modify message value.
And according to our plan, we need to generate random names of animals.
So let me remove this string from here and now let's install additional and B.M. package and we will
use Janns package and we could install it simply like that and install.
Let's go to Visual Studio Code to open up and by the terminal and the here in the project, use NPM,
install Chens.
Package was installed and now we are able to use it, let's go to documentation and let me find out
how to use it, actually.
Let me open up a full docs from here.
Let's find out how to use this package in Nagus Select here in the user section, NOLDE And we have
already installed the chance like that and now we need to lower the chance like this and afterwards
initialize gels using new keyword.
Great.
Let's go to our application and let's require it.
Gon's the chance equals sign a require.
Jens.
And afterwards, initialise new instance of Jenniskens, the Genz.
Equals sign new chants, and now we are good to go and we should be able to use methods of the chance,
let's use it here on the place of the value and here will be chance that and now we are able to generate
any random values like random address or random age, random avatar and so on.
But our goal is to generate the name of animals and the here we would use method animal like this and
we need to call it like soul.
And after calling this method, we should have random names of different animals actually extract that
this value here, let's call it simply.
Well, like so.
And its value will be a result of called to annual method of the chance object.
And here I'll use proper shorthand like that.
So here, let's use it like so.
And also let's bring to the council here.
Well, in order to see meaningful dialogue here in this producer.
And it seems that now we are good to go and this producer should produce messages every one second here
with this set and we set interval and every message will have a value that is equal to random value
of any animal, let's say, of this code.
And let's actually create the topic animals.
Let's go to our magic file with all commands.
Let's find a command that will create a new topic and I'll create Dobek, let's say, with five partitions
and replication of phase three.
And the topic name will be animals.
Let's copy this command to go to time and I'll make sure that you are in Kafka folder.
Let me actually open up new terminal window Sinitta Kafka and here is a good command that will create
a new topic.
Topic was successfully created, let's now verify that and let's simply list all topics created in our
coffeecake last hour.
Let's execute this command with least option.
And yes, I see Animal Storbeck here on the list and we also see test topic that was created automatically
in a previous lecture.
Wonderful.
Now we're able to switch to our producer and produce some messages.
But before that, let's start calling for consumer.
It should be run here in this step.
But let's start with topic animals as argument like.
So replace this topic with animals and let's start calling consumer.
Let's now go to our producer and let's started let's open up.
And by the time animal control back and let's clear it and enter old producer dogs.
And it works, we see that every second some random animal name is generated and is sent to our coffeecake,
Glassboro.
Let's go to our consumer and verify whether it receives messages.
And yes, it successfully receives a new message every second grade.
That's how we were able to adjust our producer and generate different messages every second.
I think that that's all for this producer.
And now we're able to proceed and create the consumer using North Jersey.
Let me stop this application controversy and I'll see you in the next lecture.
Bye bye.