YouTube2Text

πŸš€ Apache Kafka Crash Course With Spring Boot 3.0.x | @Javatechie β€” Transcript

by Java Techie Β· 41,182 words Β· 6,162 segments Β· language en Β· Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:14[Music]
  3. 0:26[Music]
  4. 0:50[Music]
  5. 0:57hi everyone welcome to Java techi as I
  6. 1:00announced before I'm going to start
  7. 1:02capka series from beginner level to
  8. 1:04advanc level and this is the part one
  9. 1:06video of capka series and asend of this
  10. 1:08tutorial to understand what is kapka
  11. 1:12where does kapka come from why do we
  12. 1:14need kapka how does it work with high
  13. 1:17level overview okay so without any
  14. 1:20further delay let's get
  15. 1:22[Music]
  16. 1:28started
  17. 1:30[Music]
  18. 1:42so let's start with what is capka if you
  19. 1:46open the official page of kapka you will
  20. 1:48find this definition Apachi kapka is an
  21. 1:51open-source distributed event streaming
  22. 1:54platform what does it mean so let's
  23. 1:58break down this words to understand
  24. 1:59understand in better way when I say
  25. 2:02event streaming it points to two
  26. 2:04different task create realtime stream
  27. 2:08process the realtime stream let me
  28. 2:11explain this to word with an example
  29. 2:14okay so I hope everyone uses PTM in this
  30. 2:18digital world if anyone does not know
  31. 2:20PTM PTM is a Epi payment method let's
  32. 2:24assume I am using that PTM application
  33. 2:27to do some payment or I am booking the
  34. 2:30flight ticket or I'm just booking some
  35. 2:32movie ticket okay because PTM providers
  36. 2:35feature to do n type of transaction now
  37. 2:38when I'll do any transaction that event
  38. 2:41will go to the capka server but I'm not
  39. 2:44the only one PTM user who is doing the
  40. 2:47transaction at this time since people
  41. 2:49uses this across Globe This capka Server
  42. 2:53receives million or billions of event in
  43. 2:56each minute or each second or even in
  44. 3:00each millisecond right so sending the
  45. 3:03stream of continuous data from PTM to
  46. 3:07the capka server is called creating
  47. 3:11realtime event stream or generating
  48. 3:14realtime stream of data now once capka
  49. 3:18server receives the data he need to
  50. 3:22process it right so the PTM team or PTM
  51. 3:25developer created one client application
  52. 3:29which will read the data from the kka
  53. 3:31server and do some process for example
  54. 3:35let's say PTM want to restrict marks 10
  55. 3:39transaction per day I mean a user can
  56. 3:42only do 10 transaction per day using PTM
  57. 3:46method okay if it exceed the limit then
  58. 3:50client application wants to send a
  59. 3:52notification to the user in such
  60. 3:55scenario my client application needs to
  61. 3:59continuously face the data and need to
  62. 4:02do the validation to check the
  63. 4:04transaction count for a specific user in
  64. 4:07each and every seconds or millisecond
  65. 4:10right so this continuously listens to
  66. 4:13the capka messages and processes
  67. 4:15processes them is called processing Real
  68. 4:19Time Event stream okay so if you combine
  69. 4:23these two term this will give you the
  70. 4:25answer what is event streaming in simple
  71. 4:29wordss continuously sending the message
  72. 4:32or even to the capka server and reading
  73. 4:35and process them is called realtime
  74. 4:38event
  75. 4:40streaming now let's move to the next
  76. 4:43word called distributed in microservices
  77. 4:46World distributed means distribute
  78. 4:49multiple computers to different node or
  79. 4:52region to balance the load and to avoid
  80. 4:55the downtime similarly as you know capka
  81. 4:59is a distributed event streaming
  82. 5:01platform we can also distribute our
  83. 5:04capka server if you can observe here we
  84. 5:07have three Capa server running in
  85. 5:09different region to perform event
  86. 5:12streaming operation in case if any
  87. 5:15server goes down another server will
  88. 5:18come up to pick up the traffic to avoid
  89. 5:21application downtime okay hope you
  90. 5:24understand what capka is or why it is
  91. 5:27called a distributed event streaming
  92. 5:31platform now let's move to the next
  93. 5:33point that is where does capka come from
  94. 5:37capka was originally developed at
  95. 5:40LinkedIn and was subsequently open
  96. 5:43sourced in early 2011 now this capka
  97. 5:46software comes under Apachi software
  98. 5:49Foundation okay now let's move to the
  99. 5:51next Point why do we need capka so let
  100. 5:56me walk you through an example to
  101. 5:58demonstrate this particular Point let's
  102. 6:00say I have some parcel on my name so
  103. 6:03Postman come to my door to deliver the
  104. 6:06parcel unfortunately I was not there in
  105. 6:09my home and went for vacation so he
  106. 6:13returned back again next time he came
  107. 6:15but I'm not there in home he tried two
  108. 6:18three attempt to deliver the parcel and
  109. 6:20every time I am not there in my home
  110. 6:23after some day he might forgot about the
  111. 6:26parcel or he return the parcel to the
  112. 6:28main office in this case I lost the data
  113. 6:33or I was I will not able to receive the
  114. 6:35information what Postman bring to my
  115. 6:38door that parcel could contain some
  116. 6:41important information or money related
  117. 6:44stuff but I missed it because I was not
  118. 6:46available during the period when the
  119. 6:48postman came to my door this could be a
  120. 6:51huge loss for me Isn't it how can I
  121. 6:55overcome this no worries I'm very smart
  122. 6:58I have installed a letter box near to my
  123. 7:01door so when next time parcel Postman
  124. 7:04brings for me and if he found I am not
  125. 7:08there in home or I'm not available in my
  126. 7:10home then simply he can put that parcel
  127. 7:13to my letter box so whenever I will be
  128. 7:16back to my home it can be a day after or
  129. 7:19a week after I can go to my letter box
  130. 7:22and I can collect the parcel of the
  131. 7:24messages what Postman dropped in my
  132. 7:27letter box in that case I will not lost
  133. 7:31the data data will be there in my letter
  134. 7:33box until I pick it up here the letter
  135. 7:37box acts as a middleman between the
  136. 7:39postman and me how cool is this isn't it
  137. 7:44let's try to relate this understanding
  138. 7:46with one real time example let's say I
  139. 7:50have two application application one and
  140. 7:52application two Now application one
  141. 7:55wants to send the data to application
  142. 7:57two but if if application 2 is not
  143. 8:01available to receive the data then again
  144. 8:04he will lost the data like me which
  145. 8:07might impact to the business of
  146. 8:09application to so to overcome this
  147. 8:12communication failure we might need to
  148. 8:14install something similar to the letter
  149. 8:17box between these two application right
  150. 8:20that is where capka comes into the
  151. 8:23picture you can add a messaging system
  152. 8:26between application one and application
  153. 8:28two and that messaging system can be a
  154. 8:31capka or it can be a rabbit mq or it can
  155. 8:34be a redies okay but we are going to
  156. 8:37focus on the capka messaging system so
  157. 8:41in case application 2 is not available
  158. 8:44he can collect the message from capka
  159. 8:47whenever he will come online this capka
  160. 8:50again will act as a letter box between
  161. 8:52application one and application two that
  162. 8:56is how he won't lost the data right hope
  163. 9:00now you understand why we need capka or
  164. 9:04messaging system now let's understand
  165. 9:07the need of kka with more complex
  166. 9:10scenario okay let's say you have four
  167. 9:14application who wants to produce
  168. 9:16different types of data to the database
  169. 9:20server this looks simple what is the
  170. 9:22problem here nothing as of now but in
  171. 9:26future your application can grow you
  172. 9:28might have n number of service to
  173. 9:30communicate with each other in that
  174. 9:33situation it's really tough to manage
  175. 9:36these many connections between the
  176. 9:39services there could be a lot of
  177. 9:41challenges what could be the possible
  178. 9:43challenges data format connection type
  179. 9:47or number of connection when I say data
  180. 9:50format this front end app may be want to
  181. 9:54produce some different type of data to
  182. 9:57each different type of app application
  183. 10:00maybe front end want to send some
  184. 10:02payload structure to database server and
  185. 10:04some different payload structure to
  186. 10:06security system similarly Hardo also
  187. 10:09might to do or might to send some
  188. 10:11different type of data there could be a
  189. 10:13complexity to handle the data format or
  190. 10:17schema and next connection type so there
  191. 10:20could be different type of connection I
  192. 10:23mean when I say different type of
  193. 10:25connection it could be a HTTP connection
  194. 10:27or it could be a TCP connection
  195. 10:29connection or it could be a jdbc
  196. 10:31connection like the connection type will
  197. 10:34be complex to maintain with multiple
  198. 10:37Services okay and second is number of
  199. 10:40connection when I say number of
  200. 10:42connection if you observe carefully
  201. 10:44front end connect to the five different
  202. 10:47destination
  203. 10:48Services hard connected to different
  204. 10:52five database SL connected to five and
  205. 10:54chart server also connected to five
  206. 10:57different services so so if you count
  207. 11:00the number of connection here the total
  208. 11:02count will be 20 so to just
  209. 11:06maintain left side is four application
  210. 11:09and right side is five application so
  211. 11:11just to maintain nine application or to
  212. 11:14just communicate between the nine
  213. 11:17application we need to manage the 20
  214. 11:21Connection in Enterprise application
  215. 11:24really it's kind of a bottleneck
  216. 11:26situation to handle above challenges
  217. 11:29then how to overcome it that is where
  218. 11:31this messaging system like capka came
  219. 11:34into picture so if You observe this
  220. 11:37particular diagram carefully now front
  221. 11:39end Hardo database lab chart server
  222. 11:42whatever the data type they want to send
  223. 11:45or whatever the schema structure they
  224. 11:46want to send or which type of connection
  225. 11:49they want to make they'll simply send
  226. 11:52the payload or information to this
  227. 11:54particular Kafka server or my messaging
  228. 11:58system now which kind of data this data
  229. 12:01server need he will go to the capka
  230. 12:04server and he'll directly get it from
  231. 12:05this kapka server similarly let's say
  232. 12:08security systems want to face some data
  233. 12:11given by either Hardo or database slave
  234. 12:14he can simply go there and check the
  235. 12:16data what he was looking for is there or
  236. 12:19not if it is there he can simply get
  237. 12:22those data and he can play with those
  238. 12:24data in this approach we are maintaining
  239. 12:27a centralized or similar to the letter
  240. 12:29box all the frontend hardw database laab
  241. 12:32chart server they will drop the messages
  242. 12:35and other five Downstream services will
  243. 12:39go to those kavka server and they will
  244. 12:41pick the messages as for their need and
  245. 12:43in this approach we are also reducing
  246. 12:46the connection count Can You observe
  247. 12:49here the total number of connection here
  248. 12:511 2 3 4 1 2 3 4 5 total nine Connection
  249. 12:55in previous approach we found 20
  250. 12:57connection but when we centralized using
  251. 13:00the capka we are reducing the connection
  252. 13:03count as well okay so this is the
  253. 13:06advantages of using the messaging system
  254. 13:09like
  255. 13:10capka I hope you understand why do we
  256. 13:14need capka server or capka as a
  257. 13:18messaging system now let's move to the
  258. 13:20next point that is how does it work I
  259. 13:24will just give high level overview to
  260. 13:27understand how this capka or messaging
  261. 13:29system works in real time okay so this
  262. 13:33specifically works on pops sub model
  263. 13:36when I say pop up pop stands for
  264. 13:38publisher sub stands for subscriber
  265. 13:41model okay so usually there should be
  266. 13:43three component publisher subscriber
  267. 13:46messaging system or you can say message
  268. 13:49broker okay publisher is the person who
  269. 13:52will publish the event or messages to
  270. 13:55the messaging system like capka okay and
  271. 13:59the message will go and sit in the
  272. 14:01message broker now the subscriber will
  273. 14:05go to that particular message broker and
  274. 14:07will ask for the messages or subscriber
  275. 14:10will simply listen to that message
  276. 14:12broker to get the messages okay so this
  277. 14:16is just 50,000 high level overview of
  278. 14:19the pops up model don't worry we'll
  279. 14:22understand in details how the message is
  280. 14:25getting processed inside the broker and
  281. 14:27what all components helps to process the
  282. 14:30message in my coming session okay so
  283. 14:33this is just a heads up tutorial to just
  284. 14:36get basic information about capka and
  285. 14:40its need in real
  286. 14:48time this is part two video of our capka
  287. 14:51Series in this tutorial we are going to
  288. 14:54discuss about capka architecture and its
  289. 14:57components okay all right if you
  290. 15:00understand the capka terminology and its
  291. 15:02purpose then you can picturize
  292. 15:05internally how a message is going to
  293. 15:07flow from producer to the consumer via
  294. 15:10broker or capka server okay so without
  295. 15:14any further delay let's get started so
  296. 15:17these are the capka components or you
  297. 15:19can say core concept of capka here each
  298. 15:22component play a different role in the
  299. 15:24capka ecosystem no or is we'll discuss
  300. 15:27one by one okay so let's begin with the
  301. 15:30first one that is producer if you
  302. 15:33understand the popup model in our
  303. 15:34previous video the producer is the
  304. 15:37source of data who will publish the
  305. 15:39messages or events the consumer act as a
  306. 15:44receiver it is responsible for receiving
  307. 15:47or consuming a messages but they won't
  308. 15:50directly communicate with each other to
  309. 15:53process the messages from producer to
  310. 15:55the consumer there should be one
  311. 15:57middleman between them that is what
  312. 15:59called capka server or broker in pop sub
  313. 16:03model usually producer will publish or
  314. 16:06push the messages to the broker then
  315. 16:09broker will store that messages and then
  316. 16:11consumer will consume it from the broker
  317. 16:14in other word you can say a broker is
  318. 16:17just an intermediate entity that helps
  319. 16:20in message exchange between a producer
  320. 16:23and a consumer okay so this is what the
  321. 16:27basic key component of your pops sub
  322. 16:29model and producer consumer and broker
  323. 16:33let's move to the next one that is
  324. 16:35cluster so I believe everyone heard the
  325. 16:38word called cluster if not a cluster is
  326. 16:42a common terminology in the distributed
  327. 16:44computing system it is nothing but just
  328. 16:46a group of computers or servers that are
  329. 16:49working for a common purpose since capka
  330. 16:52is also a distributed system it can have
  331. 16:55a multiple capka server or Brokers
  332. 16:58inside a single capka cluster so there
  333. 17:01can be one or more capka Brokers inside
  334. 17:04a single capka cluster let's assume your
  335. 17:08producer is publishing huge volume of
  336. 17:10data then a single Capa broker may not
  337. 17:12able to handle the load right so you
  338. 17:15might need to add additional capka
  339. 17:16server or additional broker so you can
  340. 17:19group multiple broker using a capka
  341. 17:22cluster fine so next let's Deep dive
  342. 17:25inside the Brokers to understand what
  343. 17:28all core components it has to store the
  344. 17:31messages okay so let's move to the next
  345. 17:34component that is topic so before I
  346. 17:37explain the theory what is the topic
  347. 17:40let's find out why it is there inside a
  348. 17:42broker let me walk you through the same
  349. 17:45PTM example as you understand the PTM
  350. 17:48application will keep sending different
  351. 17:50type of activity to the capka server and
  352. 17:54The paytm Client app will continuously
  353. 17:56listen the messages from the capka
  354. 17:59server right so here the left part is my
  355. 18:04producer and the right side is my
  356. 18:06consumer and the middleman is the broker
  357. 18:09or you can say capka server so broker
  358. 18:13receives different type of messages or
  359. 18:15events here it can be a payment
  360. 18:18transaction or it can be a ticket
  361. 18:20booking or it can be a specific to the
  362. 18:22mobile rearch related message right now
  363. 18:26consumer needs to read all the messages
  364. 18:29to process them so the consumer ask to
  365. 18:32the broker hey give me all the messages
  366. 18:35you have received then the broker checks
  367. 18:38his storage and replies to the consumer
  368. 18:41hey consumer I have a lot of messages
  369. 18:43with me which one you need again
  370. 18:47consumer ask hey broker give me all
  371. 18:51payment specific
  372. 18:52messages again broker attack with the
  373. 18:55counter question hey buy I have
  374. 18:58different type of payment messages with
  375. 19:00me which one you need now it's gone
  376. 19:04right the consumer Hurts by broker
  377. 19:06counter question this is obvious right
  378. 19:09then how we can overcome this back and
  379. 19:12forth conversation that is where topic
  380. 19:15came into picture to categorize
  381. 19:18different type of messages so how topic
  382. 19:22can help here you can simply create
  383. 19:26multiple topic to store different type
  384. 19:29of messages even you can rename the
  385. 19:32topic payment topic booking topic and
  386. 19:34insurance topic if producer sending
  387. 19:37payment specific messages then the
  388. 19:39message will push to this particular
  389. 19:41payment topic If the message type or
  390. 19:44producer is sending booking related
  391. 19:46messages you can keep those messages
  392. 19:49inside this booking topic or similarly
  393. 19:52if producer is sending some mobile re
  394. 19:55specific information you can keep it
  395. 19:56separate topic this is how you can
  396. 19:59segregate different event type to
  397. 20:02different topic so here consumers have
  398. 20:06no need to have a back and forth
  399. 20:07communication with Brokers whatever
  400. 20:10messages consumer want he will simply
  401. 20:13needs to subscribe that specific topic
  402. 20:15for example I have a consumer who needs
  403. 20:18only the booking specific messages then
  404. 20:21I'll tell him hey consumer you go and
  405. 20:23check directly in the booking topic you
  406. 20:25no need to ask to the broker to give me
  407. 20:28booking specific messages you simply go
  408. 20:30to the booking topic or you simply
  409. 20:32subscribe to the booking topic and get
  410. 20:35all the messages what you need this is
  411. 20:37very simple right alternatively you can
  412. 20:40consider the topic act as a database
  413. 20:43table in Capa ecosystem so usually we
  414. 20:47store employee information in the
  415. 20:49employee table and payment information
  416. 20:51in the payment table in database world
  417. 20:54right similarly when producer send
  418. 20:57employee specific event or messages we
  419. 21:00need to store them in the employee topic
  420. 21:02and similarly if producer is publishing
  421. 21:05payment specific information then we
  422. 21:07need to store it into the payment topic
  423. 21:10right now if you have multiple consumer
  424. 21:13then they can go to a specific topic and
  425. 21:16consume the messages as for their need
  426. 21:19for example if consumer one wants to
  427. 21:22read all employee messages he can go and
  428. 21:25collect the messages from the employee
  429. 21:28topic Direct ly he know need to ask to
  430. 21:30the broker hey broker give me the
  431. 21:31employee specific messages he know that
  432. 21:35employee topic contains all the employee
  433. 21:37specific messages consumer one can come
  434. 21:40to the employee topic and can get the
  435. 21:42info similarly all the consumers can
  436. 21:45subscribe to the corresponding topic
  437. 21:47what information they want to listen
  438. 21:50Okay so if you look into its actual
  439. 21:52definition topic specifies the category
  440. 21:55of the messages or the classification of
  441. 21:58the message
  442. 21:59listeners can then just respond to the
  443. 22:01message that belongs to the topic they
  444. 22:03are listening on so consumer one want
  445. 22:07the payment info he can go and listen to
  446. 22:10the payment topic that is what the need
  447. 22:13of topic or this topic play a critical
  448. 22:15role in capka ecosystem okay so let's
  449. 22:19move to the next key component that is
  450. 22:22partition now we know that PTM producer
  451. 22:26sends data to the broker and the broker
  452. 22:29store the message inside a topic now
  453. 22:32consider you have a huge volume of data
  454. 22:35when I say huge volume of data let's
  455. 22:38assume your producer is publishing
  456. 22:41millions or billions of messages per
  457. 22:43second to the topic then will my topic
  458. 22:46be able to handle those many messages
  459. 22:49obviously no there could be a storage
  460. 22:52challenges or it can be very challenging
  461. 22:54for the topic to store data on a single
  462. 22:57machine right then how to handle this
  463. 23:00situation solution is very simple as we
  464. 23:04already know capka is a distributed
  465. 23:06system in such a scenario we can break
  466. 23:09the capka topic into multiple parts and
  467. 23:13distribute those parts into different
  468. 23:16machines this concept is called topic
  469. 23:20partitioning and each part is called
  470. 23:23Partition in capka terminology okay so
  471. 23:26this partitioning will give give you
  472. 23:28better performance and high availability
  473. 23:31because if You observe we split our
  474. 23:34topic to multiple partitions so when
  475. 23:37producer publish bulk messages then each
  476. 23:40partition concurrently accept the
  477. 23:43messages that will definitely improve
  478. 23:45the performance right even in case if
  479. 23:49any partition goes off then other
  480. 23:51partitions are available to handle the
  481. 23:54loads without any application downtime
  482. 23:57this is the reason topic partitioning is
  483. 23:59the key aspect in the capka ecosystem
  484. 24:02and we can decide the number of
  485. 24:04partitions for a topic during capka
  486. 24:07topic creation okay no worries we'll
  487. 24:10hands on with these terms in our coming
  488. 24:12videos so now let's move to the next
  489. 24:15component that is offset so far we
  490. 24:19understand a capka cluster can have one
  491. 24:21or more capka server then a capka server
  492. 24:25can have multiple topics and each topic
  493. 24:28can have multiple partitions right now
  494. 24:32when producer send a message then it
  495. 24:35will go and sit in any partition inside
  496. 24:38a topic that we don't have any control
  497. 24:41on it it will work based on the round
  498. 24:43robin principle so if You observe as
  499. 24:46soon as message arrives in a partition a
  500. 24:49number is assigned to that message that
  501. 24:52is called offset 0 1 2 3 4 5 these are
  502. 24:56the sequence number as send to each and
  503. 24:59every messages that is called offset so
  504. 25:02the purpose of offset is to keep a track
  505. 25:06of which message have already been
  506. 25:08consumed by the consumer for example
  507. 25:11let's consider after reading four
  508. 25:14messages from the partition consumer
  509. 25:17went down okay then when consumer will
  510. 25:20back to the online then this offset
  511. 25:23value would help him to know exactly
  512. 25:26from where the consumer has to start
  513. 25:28consuming the messages now Here If You
  514. 25:31observe consumers should start reading
  515. 25:33message from offset 4 not from the zero
  516. 25:37again right this is what the key role of
  517. 25:41offset fine now let's move to the next
  518. 25:44component that is consumer group so I
  519. 25:49believe we all are clear up to this
  520. 25:51producer will push huge volume of
  521. 25:53messages to the capka topic and message
  522. 25:56will again split to different different
  523. 25:58partitions and inside partition each
  524. 26:01message have their own identity with
  525. 26:04offset number so now let's go one step
  526. 26:08ahead who will listen to the messages
  527. 26:10from the partitions the single statement
  528. 26:13is consumer right but if You observe
  529. 26:16here I have three partitions and a
  530. 26:19single consumer is reading from each and
  531. 26:22every partition which will definitely
  532. 26:24leads the performance issue because
  533. 26:27there is no concurrency you can see here
  534. 26:30a single consumer is playing with all
  535. 26:32the three partition so definitely it
  536. 26:35won't give us the better throughput
  537. 26:37right then how we can overcome this
  538. 26:39situation it's very simple just share
  539. 26:43the workload how can I share the
  540. 26:45workload so what I will do simply I'll
  541. 26:48Define n number of consumer instance now
  542. 26:52I can group all the three consumer what
  543. 26:54I Define into a single unit by specific
  544. 26:58speing the group name that is called
  545. 27:00consumer group now payment consumer
  546. 27:03group have the three consumer instance
  547. 27:06now since I have multiple consumer with
  548. 27:08me I can divide the workload to each and
  549. 27:11every consumer to achieve better
  550. 27:13throughput so simply now my consumer one
  551. 27:17can read from partition zero consumer 2
  552. 27:20can read all the messages from partition
  553. 27:22one and consumer 3 can read from the
  554. 27:25partition two then in this approach all
  555. 27:28the three consumer instance read
  556. 27:31parallely from each and every partition
  557. 27:33which will definitely give me the better
  558. 27:35performance or we can get the better
  559. 27:39response right just keep a note we can't
  560. 27:42guarantee about consumer and partition
  561. 27:44order any consumer can talk to any
  562. 27:48partition that will be decided by the
  563. 27:51coordinator okay so you can say consumer
  564. 27:54one might listen from partition two or
  565. 27:57any order okay we don't have any control
  566. 28:00on it cool now you might have a question
  567. 28:03hey I have three partition so three
  568. 28:06consumer so they will talk to each other
  569. 28:08that's correct but what if I have a
  570. 28:11fourth consumer added to my consumer
  571. 28:13group then what will be the behavior of
  572. 28:15this consumer 4 what he will do right
  573. 28:18there is no change that consumer 4 will
  574. 28:22sit ideal because there is no work for
  575. 28:25him now since all the three partitions
  576. 28:28assigned to three different consumer
  577. 28:30instance there is no partition left for
  578. 28:33him so he'll simply sit ideal but in
  579. 28:36case if any consumer instance is
  580. 28:39rejected or goes off then C4 will get a
  581. 28:42chance to connect with any partition
  582. 28:45this concept is called consumer
  583. 28:47rebalancing don't worry I'll cover this
  584. 28:50part in the coming session okay fine now
  585. 28:53let's move to the next component that is
  586. 28:57Juke keeper
  587. 28:58so zuke keeper is a key component for
  588. 29:01capka capka is a distributed system and
  589. 29:04it uses zuke keeper for coordination and
  590. 29:08to track the status of your capka
  591. 29:10cluster okay it also keeps the track of
  592. 29:13capka topics partitions offset and all
  593. 29:17the component of the capka ecosystem so
  594. 29:20in single word you can say this
  595. 29:22particular jeeper will act as a manager
  596. 29:26for your broker or for your capka
  597. 29:29cluster okay so this is what all the key
  598. 29:33component of capka we have seen the
  599. 29:35concept of capka architecture moreover
  600. 29:37we discussed capka components and basic
  601. 29:40concept so furthermore for any query
  602. 29:43regarding architecture of capka please
  603. 29:45feel free to ask in the comment section
  604. 29:48we'll discuss more internal of each
  605. 29:50components in our coming session
  606. 29:57okay
  607. 29:58so before we install capka let me tell
  608. 30:01you that we have different kind of capka
  609. 30:03server available in Market with
  610. 30:05different type of flavor like Apachi
  611. 30:08capka which is open source commercial
  612. 30:11distribution managed capka service so
  613. 30:14let me give you some heads up about
  614. 30:16above three capka flavor so that you can
  615. 30:18able to understand which capka service
  616. 30:20need to choose based on the situation or
  617. 30:23based on the scenario okay so the first
  618. 30:26one is open source version of Apachi
  619. 30:28kapka this you can easily download from
  620. 30:31Apachi portal and then you can install
  621. 30:34and use it in case if you face any
  622. 30:37operational issue or open bug on capka
  623. 30:40then you need to manage it by your own
  624. 30:42or you might need to upgrade if needed
  625. 30:45so maximum Company still use this open
  626. 30:48source with proper infrastructure setup
  627. 30:50and also they have dedicated developers
  628. 30:53or experts to handle any kind of infr
  629. 30:56related issue so the second one is the
  630. 30:59commercial distribution that comes with
  631. 31:02a lot of tools and utility to perform
  632. 31:05your day-to-day capka operation this
  633. 31:08will add cost to your organization or to
  634. 31:10the project and conflent capka is one of
  635. 31:14the best commercial distribution to use
  636. 31:17which simplifies connecting data source
  637. 31:19to the capka building streaming
  638. 31:21application as well as securing
  639. 31:23monitoring and managing your capka infra
  640. 31:26so today if if you will observe conflent
  641. 31:29platform is used for a wide array of use
  642. 31:32case across numerous Industries and
  643. 31:35conflent capka also provide a Community
  644. 31:37Edition for developers which is
  645. 31:40completely free don't worry I will show
  646. 31:43you how to use the community edition of
  647. 31:45confluent capka next is managed capka
  648. 31:49service this comes with everything you
  649. 31:52need you just create instance as per
  650. 31:54required configuration let everything
  651. 31:57managed by the the Capa provider all
  652. 31:59infrastructure will be ready for you and
  653. 32:02it really easy to scale when needed as
  654. 32:04similar as Cloud infra so Amazon msk and
  655. 32:08conflent are best managed capka service
  656. 32:10provider to use So based on the project
  657. 32:13requirement and budget availability you
  658. 32:15need to decide which capka service need
  659. 32:17to choose okay but as part of this
  660. 32:20course we'll use the open source apachi
  661. 32:23kapka but don't worry I will also
  662. 32:25demonstrate how to use the community
  663. 32:28edition of Kafka confluent okay so let's
  664. 32:32begin with the installation steps so
  665. 32:34I'll walk you through the steps to
  666. 32:36install Apachi capka which is open
  667. 32:39source also we'll install the community
  668. 32:41edition of confident capka then at the
  669. 32:44end we'll install capka upset Explorer
  670. 32:47which will helps us to monitor our capka
  671. 32:49messaging system okay so let's begin
  672. 32:52with the first one that is installation
  673. 32:54of apachi kapka so we are going to
  674. 32:57download the open source of apachi kapka
  675. 32:59so for that go to the Chrome
  676. 33:02browser and then you can search
  677. 33:05here
  678. 33:07capka go to the official page of apachi
  679. 33:11kapka then you can find the option to
  680. 33:13the download click on download capka so
  681. 33:16the latest version you can find your
  682. 33:193.4.0 okay so you can download any of
  683. 33:22them this is the binary distribution so
  684. 33:24let me click on the first one
  685. 33:29the file size is 102 MB so it will take
  686. 33:32few second to
  687. 33:33download So once the download will be
  688. 33:36completed go to that particular
  689. 33:38folder so you need to extract this
  690. 33:41particular
  691. 33:44folder you can see here the version we
  692. 33:47downloaded
  693. 33:493.4.0 now go inside this particular
  694. 33:51folder you can find bin config leaps
  695. 33:55license and side docks okay so inside
  696. 33:59the bin you'll find all the Sal script
  697. 34:02file for mac and all the batch file for
  698. 34:05Windows so if I open this you can see
  699. 34:08here all the sh extension is being used
  700. 34:12for the Linux or Mac operating system
  701. 34:14and in the windows you can find the
  702. 34:17batch file to start the Juke keeper or
  703. 34:20to start the capka server or to start
  704. 34:22the topic or to create the topic all the
  705. 34:25things whatever we have discussed before
  706. 34:27you can can play by executing this batch
  707. 34:29file or by executing the Sal script file
  708. 34:32so once you will download the binary
  709. 34:34distribution you will find the support
  710. 34:36for both operating system this is for
  711. 34:39Windows and this C script is for Mac or
  712. 34:42Linux okay and if you'll go inside the
  713. 34:45config it contains the properties file
  714. 34:48okay so you can see here server.
  715. 34:51properties which holds the capka
  716. 34:54property specification and you can see
  717. 34:56here jer. properties okay so these are
  718. 34:59the properties file you will understand
  719. 35:00once we'll play with those properties
  720. 35:02file now if you'll go here inside the
  721. 35:06leaves there are couple of Jar that's it
  722. 35:09okay you just need to download this
  723. 35:11binary distribution then all set in
  724. 35:14upcoming session I will show you how you
  725. 35:17can play with the capka component by
  726. 35:19executing this script okay so let's move
  727. 35:22to the next one that Community Edition
  728. 35:26of conflent capka okay so to install the
  729. 35:29confluent capka what you can do you can
  730. 35:32go to the confluent
  731. 35:37doio then you can click on get started
  732. 35:42free and you want to install the
  733. 35:45software which is community edition of
  734. 35:47confluent capka we don't want any
  735. 35:49managed capka service so navigate the
  736. 35:52tab to the
  737. 35:53softwares next you can fill this form
  738. 35:57and then just acknowledge these two
  739. 36:00click on start
  740. 36:04free here we go so if You observe here
  741. 36:08there is a local install confident
  742. 36:11platform on a single local Machine by
  743. 36:14using G tar archive or Docker images so
  744. 36:16we don't need this what do we need we
  745. 36:18need the Community Edition okay there is
  746. 36:21something called distributed confident
  747. 36:23for
  748. 36:23kubernetes and there are few more so we
  749. 36:26need to focus on this community which is
  750. 36:29completely free so you can see here use
  751. 36:32it for free forever okay so we want to
  752. 36:36install the Jeep or we just want to
  753. 36:38download the Jeep just click on this
  754. 36:43download this is the size 46 MB okay so
  755. 36:47let's wait it to complete so once it
  756. 36:51downloaded just show in the folder and
  757. 36:55again you need to extract this
  758. 37:03you can see this right the lest version
  759. 37:06of Community Edition of conflent capka
  760. 37:09is
  761. 37:107.3.2 fine now go inside this particular
  762. 37:13folder you can find the same structure
  763. 37:16that is B and you can find the file
  764. 37:20which is the Sal script for mac and
  765. 37:22Linux and for Windows you can file this
  766. 37:25batch file okay and and if you will move
  767. 37:28further inside this Etc as I already
  768. 37:32mentioned once you are playing with the
  769. 37:34conflent capka apart from capka you'll
  770. 37:37find lot of utility when I say utility
  771. 37:40you will find kapka rest kql DV rest
  772. 37:44utils schema registry so we'll
  773. 37:47understand about this particular utility
  774. 37:49in our upcoming session okay now if
  775. 37:51you'll go inside the capka you'll find
  776. 37:54the properties file Okay so
  777. 37:58whatever files you downloaded through
  778. 38:00the Apachi kapka open source and
  779. 38:03conflent each file is similar only the
  780. 38:06structure is changed so let me compare
  781. 38:09this so that it will be easy for you to
  782. 38:11understand okay let me open the capka
  783. 38:14and meanwhile I'll open the another
  784. 38:18window
  785. 38:19for confluent capka
  786. 38:25okay now let me
  787. 38:29so this is the capka and this is the
  788. 38:31conflent capka folder now if we compare
  789. 38:34these two folder if you'll go inside bin
  790. 38:38you'll find the script file and Windows
  791. 38:40File and again if you'll go inside this
  792. 38:43you'll find the same okay now if we go
  793. 38:46back and if you'll check about the
  794. 38:48config you'll find all the properties
  795. 38:50file but in conflent capka since it
  796. 38:53supports for multiple utility methods in
  797. 38:57inside the ETC you will find a folder
  798. 38:59called capka inside that capka you can
  799. 39:02find the properties okay and these are
  800. 39:05the utility fine this is the only
  801. 39:09structure changed you will find between
  802. 39:11these two capka and conflct kapka okay
  803. 39:14so as I mention I will just show you how
  804. 39:18you can play with both okay that is my
  805. 39:21next session I will just demonstrate
  806. 39:23using the command line interface how we
  807. 39:26can play with all the capka component in
  808. 39:29open source Apachi capka and in
  809. 39:31confident capka fine now the next we
  810. 39:35need to install the capka upset Explorer
  811. 39:38to monitor our capka messaging system so
  812. 39:41what you can do for that go to the
  813. 39:44Chrome and just search here capka upset
  814. 39:48Explorer the first link you can find
  815. 39:50something called capka tool okay so just
  816. 39:53open this
  817. 39:55link and then let me Zoom this for
  818. 39:59you you can see here right offset
  819. 40:02Explorer this is the caput tool is a GUI
  820. 40:05application for managing and using aaji
  821. 40:07capka cluster okay so just click on the
  822. 40:11download you'll find the option to
  823. 40:14download for Windows and Mac so download
  824. 40:18Based on your operating system so since
  825. 40:20I'm using the Mac I'll download this
  826. 40:23particular Mac
  827. 40:25OS so those size will be 60.2 MB so once
  828. 40:31it will be download you just need to
  829. 40:33double click to install it okay so let's
  830. 40:36wait it to
  831. 40:38complete so it downloaded just show in
  832. 40:42the
  833. 40:43folder and you just need to double click
  834. 40:46on it okay so that it will be installed
  835. 40:48to your
  836. 40:49machine drag and drop I have already
  837. 40:53installed it so it is asking me whether
  838. 40:55you want to replace or you want to keep
  839. 40:56the book
  840. 40:57so I'll just stop for now okay because
  841. 41:00already I installed it so I'll also
  842. 41:02remove for
  843. 41:03now fine so this is what about the
  844. 41:06installation steps in my coming tutorial
  845. 41:09I will show you how you can play with
  846. 41:12the capka component using the common
  847. 41:14line interface we'll create the consumer
  848. 41:16and producer we'll publish the event to
  849. 41:18the topic and we'll add the partition
  850. 41:20and we'll show the various type of
  851. 41:22behavior in this particular producer and
  852. 41:24consumer flow okay
  853. 41:33so we already downloaded kka binary
  854. 41:35distribution right now what next first
  855. 41:38we need to create or start a capka
  856. 41:40ecosystem for that we need to start a
  857. 41:43capka server or broker okay but to
  858. 41:46manage This capka Server we need a
  859. 41:48manager which is Zookeeper so the steps
  860. 41:51we need to follow start the Juke keeper
  861. 41:54then next we need to start the capka
  862. 41:56server or broker once you have the capka
  863. 41:59ecosystem ready with you then we can
  864. 42:01start producer and consumer since we are
  865. 42:04playing with common line interface we'll
  866. 42:06use the command to create producer and
  867. 42:08consumer for now but in my upcoming
  868. 42:10session I will create two different
  869. 42:12application for producer and consumer
  870. 42:15okay cool next producer wants to send a
  871. 42:19message to the consumer but they can't
  872. 42:21directly communicate with each other so
  873. 42:24we need another component called topic
  874. 42:27so that producer can push the message to
  875. 42:30the topic and consumer can consume it
  876. 42:33okay once you have created the topic
  877. 42:35next you can Define n number of
  878. 42:37partitions to distribute the load coming
  879. 42:39from producer for example let's say my
  880. 42:42producer wants to send 10 messages then
  881. 42:45those message will distribute to all
  882. 42:47three partitions assigning with upset
  883. 42:49number so while creating a topic you
  884. 42:52need to specify the partition count you
  885. 42:55need to take the decision based on the
  886. 42:57load coming to your application how many
  887. 42:59partition will be perfect fit for your
  888. 43:02topic okay that decision you need to
  889. 43:04take while creating the topic once a
  890. 43:07message reach to the partition then
  891. 43:09immediately whoever consumer listen to
  892. 43:12it they can happily consume it so this
  893. 43:14is the typical producer and consumer
  894. 43:16flow we'll follow the same steps to Deep
  895. 43:19dive further okay so using the common
  896. 43:22line interface we'll start the Juke
  897. 43:24keeper capka server we'll create the
  898. 43:26topic then I'll will show you how you
  899. 43:28can Define the partition then also we'll
  900. 43:30understand how the bulk message is being
  901. 43:33distributed to the multiple partition
  902. 43:35and how it is being consumed by the
  903. 43:37consumer okay so to play with the
  904. 43:39command line interface you need to go to
  905. 43:41the folder where you install the capka
  906. 43:44so it is there in my download folder I
  907. 43:47have created a folder called softwares
  908. 43:50inside this I have kept these two capka
  909. 43:53okay so I'll show you how you can do
  910. 43:55using capka also I will demonst
  911. 43:57how we can do using the confluent capka
  912. 44:00Okay cool so first step what we
  913. 44:03understand first we need to start the
  914. 44:07Juke keeper right then you need to start
  915. 44:09the capka server so what you can do go
  916. 44:13to the folder then go to the capka open
  917. 44:16a new
  918. 44:18terminal fine then I will also create
  919. 44:22couple of
  920. 44:26terminal
  921. 44:29just go
  922. 44:31here new terminal fine let's go with
  923. 44:35this three let me minimize this
  924. 44:43okay fine so first I need to start the
  925. 44:48Juke keeper so how can I start the Juke
  926. 44:50keeper you need to fire the command so
  927. 44:53there is a cell script file you will
  928. 44:55find inside the cap B directory so if
  929. 44:58you'll go inside kapka if you'll go
  930. 45:01inside B you can find your something
  931. 45:04called Juke keeper server hyphen
  932. 45:07start.sh okay so what we can do we'll
  933. 45:11run this particular command so this is
  934. 45:14inside B folder Juke
  935. 45:17keeper start
  936. 45:20server
  937. 45:21start.sh okay now to start the Juke
  938. 45:24keeper it needs to read the zuke keeper.
  939. 45:27properties file so again if you'll go
  940. 45:30inside the config you'll find a property
  941. 45:34called Juke keeper. properties can you
  942. 45:36see here this properties it needs to
  943. 45:39start the Juke keeper server so you just
  944. 45:42need to Simply give the path of it it is
  945. 45:45inside
  946. 45:46config let me Zoom this for you it is
  947. 45:51inside
  948. 45:53config and the file name is Juke keeper
  949. 45:56do properties file now just enter
  950. 46:02it it will take few second to start the
  951. 46:04Juke keeper and the default Port it will
  952. 46:07run
  953. 46:082181 okay so I can show you that let me
  954. 46:12filter it
  955. 46:142181 can you see here the default Port
  956. 46:17is
  957. 46:182181 now as per the presentation we
  958. 46:22understand after start the Juke keeper
  959. 46:24we need to start the capka server so so
  960. 46:27go to another terminal let me use the
  961. 46:29second one here you need to start the
  962. 46:32capka server how can you start the capka
  963. 46:35server again if you'll go and check in
  964. 46:37your B
  965. 46:40folder you can find something called
  966. 46:43capka server start.sh this is the Sal
  967. 46:47script file if you're using Windows you
  968. 46:49can go insert the windows and you can
  969. 46:51search
  970. 46:53for capka where is the capka server
  971. 46:59yeah this one you can run this capka Hy
  972. 47:02server start. batch file okay since I'm
  973. 47:05in the windows sorry I'm in the Mac I'm
  974. 47:08using the s file so just go to
  975. 47:12the
  976. 47:14terminal and just run it is inside bin
  977. 47:19okay capka hen
  978. 47:21server
  979. 47:23start.sh and to start the capka server
  980. 47:26it needs to read the properties file
  981. 47:28called server. properties so if you'll
  982. 47:31go inside the properties file or config
  983. 47:33folder you'll find something called
  984. 47:35server. properties okay so you need to
  985. 47:38give this properties file to start the
  986. 47:40capka server so again give the path
  987. 47:43config
  988. 47:44SL server. properties just enter
  989. 47:53it yeah it take few second to start your
  990. 47:57capka
  991. 47:58server now to check which Port This
  992. 48:01capka Server is running you can filter
  993. 48:04something
  994. 48:069092 can you see here this is the
  995. 48:09default Port of capka server so just
  996. 48:13keep a note the default Port of Juke
  997. 48:22keeper is
  998. 48:242181 and capka
  999. 48:28server or
  1000. 48:31broker is
  1001. 48:339092 okay so that's it now our capka
  1002. 48:37ecosystem is ready now what is the next
  1003. 48:40step if you understand correctly then
  1004. 48:42the next step producer and consumer need
  1005. 48:45to communicate with each other using the
  1006. 48:47topic so you need to create a topic and
  1007. 48:50we need to specify the partition and
  1008. 48:52replication Factor okay so to run a
  1009. 48:55topic again I'll take the help from this
  1010. 48:58common line
  1011. 48:59interface okay now if we go inside the B
  1012. 49:04folder you'll find something capka Hy
  1013. 49:08topic.sh okay so what I can do I'll just
  1014. 49:12run here I need to go inside bin then
  1015. 49:15capka hyen topic. SS also I need to tell
  1016. 49:21here while creating the topic I need to
  1017. 49:24give my bootstrap server host and put
  1018. 49:27when I say bootstrap server it's about
  1019. 49:29your capka server okay now I'll
  1020. 49:33Define
  1021. 49:36bootstrap
  1022. 49:37stap do server my bootstrap server is
  1023. 49:42running on host Local Host and Port is
  1024. 49:469092 this is where my capka server is up
  1025. 49:49and running right so let me make this
  1026. 49:53white so that we can type in a single
  1027. 49:55line okay I have ran the capka hyen
  1028. 49:58topic.sh and I giving where is my capka
  1029. 50:00server is up and running the host is
  1030. 50:02Local Host and Port is
  1031. 50:059092 now what action you want to do I
  1032. 50:08want to create a
  1033. 50:11topic okay and what is the topic name
  1034. 50:14you want to give let's say I want to
  1035. 50:17give JT topic or let's give a valid name
  1036. 50:23Java underscore or
  1037. 50:28topic okay now how many partition you
  1038. 50:32want to Define so if you want Define
  1039. 50:34anything it will take the default
  1040. 50:36partition as a one but you have option
  1041. 50:38to Define n number of partition so as of
  1042. 50:42now I just want to Define three
  1043. 50:44partition
  1044. 50:46okay
  1045. 50:48partition count equal to three now how
  1046. 50:52many copy you want to keep that is
  1047. 50:54called replication Factor right since we
  1048. 50:56are running on a single broker so let's
  1049. 50:59keep the replication Factor as one so
  1050. 51:01you can
  1051. 51:03Define
  1052. 51:06replication Factor equal to 1 so there
  1053. 51:10is nothing complex to remember this
  1054. 51:12command or this particular command
  1055. 51:15whatever you have type here I'm just
  1056. 51:17running my topic by giving the
  1057. 51:19information where is my Capa server is
  1058. 51:21up and running by defining the host and
  1059. 51:23port and what action you want to perform
  1060. 51:26I want to create a topic and the name of
  1061. 51:28the topic is Java hen topic and the
  1062. 51:31number of partition I want to assign as
  1063. 51:33three to this particular topic and I
  1064. 51:35want to keep a single clone of this
  1065. 51:38particular broker so that is the reason
  1066. 51:40I have defined replication Factor as one
  1067. 51:42now click on
  1068. 51:45enter so the mistake we have done we
  1069. 51:49know need
  1070. 51:51to add the dot it need to be hyphen okay
  1071. 51:55so let me Zoom this for
  1072. 51:58you now let me drag this yeah now let me
  1073. 52:03enter
  1074. 52:06it can you see here it created the topic
  1075. 52:10Java hyen topic you can Define n number
  1076. 52:13of topic if you want so let me create
  1077. 52:16another
  1078. 52:18topic topic one
  1079. 52:25okay now now we have created two topic
  1080. 52:28so to list down all the topic available
  1081. 52:31inside your capka server what you can do
  1082. 52:35you can simply run bin I mean same
  1083. 52:38command capka topic.sh in this
  1084. 52:41particular server just give me the list
  1085. 52:43of topic okay so I can happily copy this
  1086. 52:48command
  1087. 52:49then you can run it here and just ask
  1088. 52:53him to give me the list of
  1089. 52:55topic now if you'll enter we'll find the
  1090. 52:58two topic javate topic javat topic one
  1091. 53:03now if you want to describe this topic
  1092. 53:05to know what is the number of partition
  1093. 53:08replication Factor who is the leader so
  1094. 53:10if you want to describe this topic that
  1095. 53:13is also straightforward you can run a
  1096. 53:16command so what you can do run the same
  1097. 53:19command and ask him to describe the
  1098. 53:24topic name so I just want to describe
  1099. 53:27javat hyphen topic okay this is what the
  1100. 53:31topic name we have right I just want to
  1101. 53:33describe this run
  1102. 53:39it what is the
  1103. 53:42error okay I need to Define that I want
  1104. 53:46to describe a topic right so describe
  1105. 53:50then you can tell him what you want to
  1106. 53:51describe I want to describe
  1107. 53:55topic
  1108. 53:59there is something
  1109. 54:00wrong I might be doing some spelling
  1110. 54:03mistake let's see kka event topic.sh
  1111. 54:06bootstrap server
  1112. 54:099092 okay I don't want this list because
  1113. 54:13I want to describe so this is the
  1114. 54:15mistake I mean you need to understand
  1115. 54:18this particular command okay you just no
  1116. 54:20need to remember it just understand what
  1117. 54:23you want to perform okay now just enter
  1118. 54:26it
  1119. 54:28can you see here okay let me take the
  1120. 54:31background as
  1121. 54:34different fine now if You observe
  1122. 54:37here the topic name is this and the
  1123. 54:41number of partition we have Define three
  1124. 54:430 1 and two okay and replica is zero so
  1125. 54:49you can see here partition count equal
  1126. 54:51to three replication Factor equal to 1
  1127. 54:54there is no additional config given so
  1128. 54:56this is empty okay you can describe the
  1129. 54:59topic if you want and also we have
  1130. 55:02defined the number of partition so we
  1131. 55:05are done up to the creation of topic and
  1132. 55:08defining the partition now we want to
  1133. 55:10play with the producer and consumer so
  1134. 55:13since we are playing with the common
  1135. 55:14line interface I will run the consumer
  1136. 55:16and producer application using the
  1137. 55:19common line interface or using the
  1138. 55:21command okay so we'll run the producer
  1139. 55:24we'll push some message to the top pick
  1140. 55:26and we'll see whether it is being
  1141. 55:27consumed by the consumer or not next
  1142. 55:30step we'll push bulk number of messages
  1143. 55:33from the producer to the topic and we'll
  1144. 55:36see whether the bulk messages is being
  1145. 55:39getting distributed to the different
  1146. 55:41partition or not how we can monitor
  1147. 55:44those things we have installed the
  1148. 55:45offset Explorer right so what I can do I
  1149. 55:49will open the offset
  1150. 55:55Explorer
  1151. 55:58so what you can do here very simple step
  1152. 56:02you just need to create a connection and
  1153. 56:05to create a connection you just need to
  1154. 56:07give a name of your cluster and where is
  1155. 56:10your zookeeper is up and running and
  1156. 56:12Port of your zookeeper so to not confuse
  1157. 56:16you what I'll do I will create a new
  1158. 56:21connection let's say JT I'll give the
  1159. 56:25cluster name
  1160. 56:26JT hyen con okay Local Host 2181
  1161. 56:31everything it will take by default okay
  1162. 56:33so I'll give Java techy hyphen new
  1163. 56:37that's it click on
  1164. 56:40test
  1165. 56:42yes now if I open this I have the
  1166. 56:46connection to the cluster so that I can
  1167. 56:48monitor everything going on this
  1168. 56:50specific cluster okay now if I expand
  1169. 56:53this how many topic we can see here Java
  1170. 56:57topic and Java topic one so this is the
  1171. 57:00two topic we created and we can able to
  1172. 57:03see inside this particular Juke keeper
  1173. 57:05okay now if you'll go and click on the
  1174. 57:08data and if you'll hit this particular
  1175. 57:10thing there is no data is getting
  1176. 57:13filtered if you'll check the topic one
  1177. 57:16there is no data right we want to push
  1178. 57:19the data and we want to verify whether
  1179. 57:21it is going to the topic or not if it is
  1180. 57:24going to the topic then we'll verify
  1181. 57:25whether is being consumed by a consumer
  1182. 57:27or not okay so what we can do quickly we
  1183. 57:32just need to start a producer and then
  1184. 57:34we just need to start a consumer fine so
  1185. 57:37what we can do to start a producer
  1186. 57:40you'll find something called Capa
  1187. 57:42console producer. given by the capka
  1188. 57:45binary go inside the bin and if you will
  1189. 57:49search
  1190. 57:50here can you see here there is something
  1191. 57:53called capka console producer. to just
  1192. 57:57kicked up by producer application and
  1193. 57:59capka console
  1194. 58:01consumer. to run this command to behave
  1195. 58:03as a consumer okay so we'll run these
  1196. 58:06two command okay so what you can do go
  1197. 58:09to the
  1198. 58:11terminal this
  1199. 58:13guy now I'll clear everything what I
  1200. 58:17want to do here I want
  1201. 58:19to let me what okay I'll minimize these
  1202. 58:23two okay we started the Juke keeper and
  1203. 58:25we started the capka server let's
  1204. 58:27minimize it now to make it clear I'm
  1205. 58:31just running the producer application
  1206. 58:33here so you just need to run go inside
  1207. 58:37bin
  1208. 58:40capka console right console hyen
  1209. 58:44producer Dosh and then you need to give
  1210. 58:49all the list of kka server available
  1211. 58:51okay so you can Define broker hyen list
  1212. 58:55current ly we have a single broker which
  1213. 58:58is running on Local Host
  1214. 59:019092 but in real time you can find n
  1215. 59:04number of Brokers right so that is the
  1216. 59:06reason you need to Define them inside
  1217. 59:08this list now to which topic you want to
  1218. 59:11push your messages from producer you
  1219. 59:14need to Define that topic name so our
  1220. 59:17topic name is javat
  1221. 59:19hyphen topic okay that's it just enter
  1222. 59:25it
  1223. 59:27now it is asking you to push some
  1224. 59:29messages so we can push the messages and
  1225. 59:32we can verify in the uh capka upset
  1226. 59:36Explorer but meanwhile let me start the
  1227. 59:38consumer application so that parall we
  1228. 59:41can push the messages from here it will
  1229. 59:43go to the topic then consumer will
  1230. 59:45consume from it so I want to demonstrate
  1231. 59:47the complete pops of flow so what I'll
  1232. 59:50do I'll open a new terminal to start a
  1233. 59:54consumer so go go here and I just want
  1234. 59:57to open a new
  1235. 59:59terminal to start a consumer what you
  1236. 1:00:02can do go inside B then simply let me
  1237. 1:00:06Zoom this for you go insert bin then
  1238. 1:00:10run
  1239. 1:00:12capka console consumer Dosh okay now
  1240. 1:00:17where is your bootstrap to whom you want
  1241. 1:00:19to listen you can
  1242. 1:00:22Define
  1243. 1:00:23bootstrap hyen server
  1244. 1:00:28which is running on
  1245. 1:00:29Port Local Host
  1246. 1:00:349092 and to which topic you want to
  1247. 1:00:36listen I want to listen from the topic
  1248. 1:00:41javat hyphen topic whether you want to
  1249. 1:00:44listen from the beginning if yes just
  1250. 1:00:47Define I want to listen from
  1251. 1:00:54beginning okay don't do any spelling
  1252. 1:00:57mistake while typing the command
  1253. 1:00:58otherwise it will give you the error
  1254. 1:01:01fine now let's run this
  1255. 1:01:06consumer there is no messages being
  1256. 1:01:09showing here so what I'll do to make it
  1257. 1:01:13simple let me split into the
  1258. 1:01:17two terminal so that we can see whether
  1259. 1:01:21what we are sending we are able to
  1260. 1:01:23receive it from the consumer or not so
  1261. 1:01:25let me split these two
  1262. 1:01:28tab
  1263. 1:01:30cool now the left side is my producer
  1264. 1:01:34and the right side is my consumer and
  1265. 1:01:37they both can connected using this
  1266. 1:01:40particular topic javat H topic okay
  1267. 1:01:43producer is publishing to this topic and
  1268. 1:01:46my consumer also listening to this
  1269. 1:01:48particular topic if you'll do the
  1270. 1:01:50spelling mistake in the syntax or in the
  1271. 1:01:53command it don't work so let's see
  1272. 1:01:56whether we are correct or not let me
  1273. 1:01:58send some messages
  1274. 1:02:00hi can you see here we're able to see
  1275. 1:02:02the messages in right side let me Zoom
  1276. 1:02:05this for
  1277. 1:02:06you let me send something
  1278. 1:02:09hello we can see here let me send
  1279. 1:02:12something Java
  1280. 1:02:15TIY we can see here let's send
  1281. 1:02:22welcome let me some random number okay
  1282. 1:02:27so this is my producer application from
  1283. 1:02:29producer I'm sending the messages okay
  1284. 1:02:33and this is the right part is my
  1285. 1:02:35consumer let me minimize right part is
  1286. 1:02:38my consumer he's able to consume it now
  1287. 1:02:41whether this message is being passed
  1288. 1:02:43through the topic or not how you can
  1289. 1:02:45verify go to the offset Explorer now
  1290. 1:02:49just refresh your topic okay we have
  1291. 1:02:53these two topic Java topic and topic one
  1292. 1:02:56but we are dealing with this javat topic
  1293. 1:02:59and there is a consumer offset okay I
  1294. 1:03:01mean it will just assign the offset and
  1295. 1:03:04it will just set up to what your
  1296. 1:03:06consumer read okay now what I want to
  1297. 1:03:09show you I want to show you the data in
  1298. 1:03:12this topic Java topic just run it can
  1299. 1:03:17you see here how many messages we have
  1300. 1:03:19send five messages so the offset count
  1301. 1:03:23being getting increased by one 0 1 2 3 4
  1302. 1:03:27and all the messages what we have been
  1303. 1:03:30sent to this particular topic now from
  1304. 1:03:33this topic consumer is able to listen
  1305. 1:03:36the messages and we can able to see here
  1306. 1:03:40right now if you'll Deep dive one step
  1307. 1:03:43ahead this particular topic we have
  1308. 1:03:45created the partitions how many
  1309. 1:03:47partitions we have created three 0 1 and
  1310. 1:03:51two now if you check the
  1311. 1:03:54messages in the
  1312. 1:03:56topic let me show you the messages
  1313. 1:03:59inside the
  1314. 1:04:02topic I'll go to the
  1315. 1:04:04data all the messages went to partition
  1316. 1:04:08zero but still we have two more
  1317. 1:04:10partition partition one and partition
  1318. 1:04:12two but why all the messages is going to
  1319. 1:04:15partition zero that is not in our hand
  1320. 1:04:19that will be taken care by Juke keeper
  1321. 1:04:22and coordinator okay now we are playing
  1322. 1:04:25with the
  1323. 1:04:26very less messages so all the messages
  1324. 1:04:28is going to a single partition now let's
  1325. 1:04:31say I want to push thousand of row in
  1326. 1:04:34single sh from the producer then maybe
  1327. 1:04:37the Thousand row could be distribute to
  1328. 1:04:40different partition okay this what we
  1329. 1:04:43understand from the theoretically now
  1330. 1:04:45let's prove it what I will do I will
  1331. 1:04:48send a bulk file CSV data through the
  1332. 1:04:52capka and we'll see whether the data is
  1333. 1:04:54being uh pass to the different partition
  1334. 1:04:56or not so for that what I can do I'll
  1335. 1:05:00will cancel the producer okay Let It Be
  1336. 1:05:06My Consumer is keep listening I'm not
  1337. 1:05:08sending anything from the producer that
  1338. 1:05:10is fine you won't find anything but once
  1339. 1:05:12I will start publishing the message will
  1340. 1:05:14keep my My Consumer will keep listening
  1341. 1:05:16to it so what I want to do I want to
  1342. 1:05:19publish a bulk messages so what I have
  1343. 1:05:23done in my download section I have
  1344. 1:05:26downloaded a user. CSV file if I'll open
  1345. 1:05:33this it's loading if you'll observe
  1346. 1:05:37here the total number of row present
  1347. 1:05:39inside the CSV file is th000 okay this
  1348. 1:05:43is triple9 and this is th000 including
  1349. 1:05:46the header it is th1 okay so I want to
  1350. 1:05:50push this particular
  1351. 1:05:52messages from the Capa producer I want
  1352. 1:05:55want to push this user. CSV file how you
  1353. 1:05:58can do that that is very simple so you
  1354. 1:06:01can simply
  1355. 1:06:03Define the path of your file it is there
  1356. 1:06:06in my download folder so I just need a
  1357. 1:06:10path of my download folder so what I can
  1358. 1:06:12do I'll just take the path of
  1359. 1:06:17it
  1360. 1:06:24PWD close it I want to send the enter
  1361. 1:06:30users. CSV file from my producer just
  1362. 1:06:34enter
  1363. 1:06:38it can you see here if I zoom My
  1364. 1:06:41Consumer we can see all the Thousand
  1365. 1:06:44messages in my consumer section it means
  1366. 1:06:47the CSV file the bulk CSV file is being
  1367. 1:06:50loaded to my topic can you see here all
  1368. 1:06:53the messages including the header we can
  1369. 1:06:55able to see the total number of row
  1370. 1:06:58total number of row is 1,1 so let's
  1371. 1:07:01verify it in our upset Explorer now we
  1372. 1:07:05are seeing only the five messages I
  1373. 1:07:07didn't refresh it Let me refresh it can
  1374. 1:07:11you see here there are so many messages
  1375. 1:07:13see these are the CSP data ID first name
  1376. 1:07:17last name email and this is the IP
  1377. 1:07:19address that is what we have there in
  1378. 1:07:21our uh CSV file okay now
  1379. 1:07:26all messages went to single partition or
  1380. 1:07:28different partition let's verify it
  1381. 1:07:31partition
  1382. 1:07:34zero the
  1383. 1:07:37data okay now let's go to the partition
  1384. 1:07:40one it didn't receive any data the count
  1385. 1:07:43is zero partition two also didn't
  1386. 1:07:45receive anything okay so all the
  1387. 1:07:48messages went to the partition zero but
  1388. 1:07:51that is not always the same behavior
  1389. 1:07:54what we can verify I will send it
  1390. 1:07:57again or I have another file called
  1391. 1:08:02customers. CSV okay it is not there let
  1392. 1:08:05me send the same users.
  1393. 1:08:11CSV fine all the messages again being
  1394. 1:08:14send here we how we can
  1395. 1:08:17verify let me go to the
  1396. 1:08:21topic fine now if you'll see in the
  1397. 1:08:23partition zero the to total number of
  1398. 1:08:26record received by partition zero is
  1399. 1:08:301546 so first we published five messages
  1400. 1:08:34then we publish thousand messages then
  1401. 1:08:36again we publish next th000 messages so
  1402. 1:08:39partition zero all total received 1546
  1403. 1:08:43messages now if you open the partition
  1404. 1:08:45one it receives 461 messages okay
  1405. 1:08:49partition two didn't receive anything so
  1406. 1:08:52whoever partition will get the messages
  1407. 1:08:54is not in our our hand this will be
  1408. 1:08:56handled by the Juke keeper or
  1409. 1:08:58coordinator okay now partition zero and
  1410. 1:09:01partition one have the messages so don't
  1411. 1:09:04worry we'll demonstrate this behavior
  1412. 1:09:06from our application once we'll create
  1413. 1:09:09the producer app and consumer app this
  1414. 1:09:11is what we are just trying to understand
  1415. 1:09:13the behavior of partition and
  1416. 1:09:15distributing the messages to multiple
  1417. 1:09:17partition through the common line
  1418. 1:09:19interface okay so I believe we are very
  1419. 1:09:22clear about the producer consumer
  1420. 1:09:24workflow and we have discussed
  1421. 1:09:26everything what we have covered in this
  1422. 1:09:29particular slide we have started the
  1423. 1:09:30Zookeeper we created the capka server we
  1424. 1:09:33create the topic Define the partition
  1425. 1:09:35and also we understand how the load is
  1426. 1:09:37getting distributed to the partition how
  1427. 1:09:39the offset is being assigned how the
  1428. 1:09:41message is being published from producer
  1429. 1:09:43to the topic from the topic to the
  1430. 1:09:46consumer the entire workflow we have
  1431. 1:09:48covered just now okay the next whatever
  1432. 1:09:52we have discussed everything on open
  1433. 1:09:54source apach AP now the next I will walk
  1434. 1:09:57you through a small steps how you can
  1435. 1:10:00play with the conflent capka okay so
  1436. 1:10:03which is the Community Edition we have
  1437. 1:10:05installed or we have downloaded
  1438. 1:10:06yesterday right so if you'll go to the
  1439. 1:10:09desktop if you'll go to the
  1440. 1:10:12downloads software we have this conflent
  1441. 1:10:16right conflent capka now to start this
  1442. 1:10:20confident capka you need to stop the
  1443. 1:10:22open source aaji capka because theuk ER
  1444. 1:10:25server and capka server both are using
  1445. 1:10:28the same port the configuration is same
  1446. 1:10:30right so you need to stop them first
  1447. 1:10:34what I'll do I'll stop everything contrl
  1448. 1:10:36C I stop my producer I stop my consumer
  1449. 1:10:41which I ran in open source API capka
  1450. 1:10:45then I need to stop this capka
  1451. 1:10:48server then I need to stop my jke
  1452. 1:10:54keeper
  1453. 1:10:58where it
  1454. 1:11:04is this
  1455. 1:11:06guy yeah just stop it fine so I'll clear
  1456. 1:11:14everything anyway I need to close this
  1457. 1:11:16particular terminal because we we want
  1458. 1:11:18to play with the confr capka now so what
  1459. 1:11:21you can do go inside this folder just
  1460. 1:11:25open a new terminal atart folder
  1461. 1:11:27everything is same each and every
  1462. 1:11:29command is same only you need to give
  1463. 1:11:32the different path of your config okay
  1464. 1:11:36so what I mean I'll show you we'll
  1465. 1:11:39follow the same first we'll start the
  1466. 1:11:41Juke keeper then we'll start the capka
  1467. 1:11:43server then we'll create the topic by
  1468. 1:11:45defining the partition then we'll see
  1469. 1:11:47the messages so for that what I can
  1470. 1:11:51do I will just go to the folder and I
  1471. 1:11:55will open a
  1472. 1:11:57terminal new terminal let me open couple
  1473. 1:12:00of
  1474. 1:12:04terminal
  1475. 1:12:08okay fine I have created four terminal
  1476. 1:12:12now first let me start the bootstrap
  1477. 1:12:14server sorry zookeeper right so to start
  1478. 1:12:17the Juke keeper I will run the same
  1479. 1:12:20command see here this is what we have
  1480. 1:12:21run in let me Zoom this for
  1481. 1:12:23you the same command we have ran for
  1482. 1:12:27open source Apachi kapka only thing you
  1483. 1:12:30need to Define instead of this config
  1484. 1:12:33you need to give the actual path of your
  1485. 1:12:36Juke keeper. properties file so if you
  1486. 1:12:38check here the Juke keeper. properties
  1487. 1:12:41file is inside
  1488. 1:12:43Etc capka and then the property file
  1489. 1:12:47right so you need to give that path
  1490. 1:12:50instead of config just change it to
  1491. 1:12:54the
  1492. 1:12:55it is inside Etc hyen capka and jer.
  1493. 1:13:00properties just run
  1494. 1:13:03it
  1495. 1:13:05okay so I'm already there inside ban no
  1496. 1:13:09right okay so what I'll do I'll clear it
  1497. 1:13:14let me copy the command okay I've
  1498. 1:13:16already documented the command so let me
  1499. 1:13:19run this particular command I mean see
  1500. 1:13:21here the command is same I'll Zoom this
  1501. 1:13:24for you only we are changing
  1502. 1:13:26the path of your config properties okay
  1503. 1:13:29jer. properties so let's see what is the
  1504. 1:13:33mistake we are
  1505. 1:13:36doing great I've run the same command
  1506. 1:13:39there is no change okay now all good
  1507. 1:13:43Juke keeper server is up and running now
  1508. 1:13:45what is the next step we need to start
  1509. 1:13:47the capka server so to start the capka
  1510. 1:13:50server the command is same here see be
  1511. 1:13:54hyphen b/ capka server start only we're
  1512. 1:13:58changing the path of server.
  1513. 1:14:01properties just copy
  1514. 1:14:03this open a new
  1515. 1:14:07terminal just run
  1516. 1:14:16it cool it started the capka server now
  1517. 1:14:20we need to create a topic so what I will
  1518. 1:14:23do I will copy the same command I mean
  1519. 1:14:26the same command you can use which we
  1520. 1:14:28used in open source Apachi Capa to
  1521. 1:14:30create the topic only the Juke keeper
  1522. 1:14:34and capka server changes to this
  1523. 1:14:36particular config path rest all are same
  1524. 1:14:39because on top of bootstrap or on top of
  1525. 1:14:42your broker you are creating the topic
  1526. 1:14:44so what I'll do let's copy the same
  1527. 1:14:47command anyway it is same right just
  1528. 1:14:49copy
  1529. 1:14:50this go to the terminal any terminal
  1530. 1:14:55just run it we're creating the topic
  1531. 1:14:58with name new topic one okay all good
  1532. 1:15:02we're able to create the topic now if I
  1533. 1:15:05list down all the
  1534. 1:15:07topic just see the command see already I
  1535. 1:15:10explained in open source apka purpose of
  1536. 1:15:13each word right so I'm even I'm using
  1537. 1:15:17the same again for the conflent capka so
  1538. 1:15:21let's run it I just want to describe the
  1539. 1:15:24top iic I mean I just want to list out
  1540. 1:15:28all the topics available in this
  1541. 1:15:329092 can you see here new topic one
  1542. 1:15:36we're able to see this Java topic and
  1543. 1:15:38Java topic one as well because they both
  1544. 1:15:40are using the same 9092 and host I mean
  1545. 1:15:45earlier where it started my open source
  1546. 1:15:48Apachi kapka and this conflent Capa they
  1547. 1:15:51are using the same configuration okay so
  1548. 1:15:53that is the reason you can able to see
  1549. 1:15:55but don't focus on that can you see the
  1550. 1:15:58topic which you just created new topic
  1551. 1:16:00one cool now if you want you can
  1552. 1:16:03describe your new topic again the
  1553. 1:16:06command is same let me copy this and go
  1554. 1:16:10to the terminal ran it okay I did a
  1555. 1:16:16mistake contrl
  1556. 1:16:21C I just want to describe it
  1557. 1:16:25can you see here there is a one
  1558. 1:16:28replication factor and we have defined
  1559. 1:16:29the three partition we can able to see
  1560. 1:16:32that okay all cool now let's start a
  1561. 1:16:35producer message I mean producer
  1562. 1:16:37application and consumer application
  1563. 1:16:39then just publish a message to visualize
  1564. 1:16:42whether we are able to push the messages
  1565. 1:16:44in conflent capka or not okay so I'll
  1566. 1:16:48just copy this
  1567. 1:16:50command to start a producer go to the
  1568. 1:16:54terminal I mean I can use the same right
  1569. 1:16:57I can use
  1570. 1:16:59this control sorry command
  1571. 1:17:04K now meanwhile I need to start a
  1572. 1:17:13consumer I don't want to read it from
  1573. 1:17:15the beginning I want to read it because
  1574. 1:17:18we have not sent anything right now I
  1575. 1:17:21will go to the new
  1576. 1:17:23terminal this one this will my consumer
  1577. 1:17:27now this is my producer cool just run
  1578. 1:17:33it both are pointing to the same topic
  1579. 1:17:36he will publish to the topic one I mean
  1580. 1:17:39this is the producer will publish to the
  1581. 1:17:40topic one consumer will read from the
  1582. 1:17:43topic one I'll send
  1583. 1:17:47something welcome to
  1584. 1:17:52javat or I'll open my post man I'll take
  1585. 1:17:55any payload I'll send in the form of
  1586. 1:17:57Json okay I mean Json
  1587. 1:17:59string you can send any type of data
  1588. 1:18:02okay so let's open
  1589. 1:18:06it I'll take
  1590. 1:18:11something let me take this
  1591. 1:18:15okay I'm sending some Json
  1592. 1:18:21string
  1593. 1:18:23fine some random
  1594. 1:18:26messages can you see here now if you'll
  1595. 1:18:30verify we have sent three messages to
  1596. 1:18:33this particular topic right if you'll go
  1597. 1:18:36and check the topic is not listed here I
  1598. 1:18:39need to refresh
  1599. 1:18:41it refresh the
  1600. 1:18:43topic can you see here we can able to
  1601. 1:18:45see our new topic and we have three
  1602. 1:18:47partition 01
  1603. 1:18:502 0 1 and 2 okay go to this new topic
  1604. 1:18:56one run it can you see here all the
  1605. 1:19:00messages I mean whatever the messages we
  1606. 1:19:03send in the Json string each line is
  1607. 1:19:07published as a individual messages so
  1608. 1:19:09this is not the way we can send the Json
  1609. 1:19:12to just show you that we can able to
  1610. 1:19:14communicate producer and consumer I
  1611. 1:19:17randomly copy paste the Json string and
  1612. 1:19:19I'm sending it okay so now what I'll do
  1613. 1:19:23total number of mess mes is N9 the
  1614. 1:19:26offset count is reached up to eight okay
  1615. 1:19:28and all messages went to the partition
  1616. 1:19:31zero one and two is empty right so what
  1617. 1:19:35I'll do I'll publish I mean we can give
  1618. 1:19:37a try to publish a bulk messages to see
  1619. 1:19:40whether in conflent capka the load is
  1620. 1:19:43being distribut to multiple partition or
  1621. 1:19:45not okay so I'll just copy
  1622. 1:19:53this
  1623. 1:19:58I need a new okay I can use the same
  1624. 1:20:05producer top Pi one and then I need the
  1625. 1:20:10location of my download right because
  1626. 1:20:12that is where my file is present so CD
  1627. 1:20:15come
  1628. 1:20:20out this is
  1629. 1:20:22right close it
  1630. 1:20:29users. CSP just enter
  1631. 1:20:32it can you see here it sent all the rows
  1632. 1:20:38now we'll verify whether thousand row
  1633. 1:20:39went to the topic one in conflent capka
  1634. 1:20:43or
  1635. 1:20:44not let me refresh this
  1636. 1:20:47topic now if you'll run it you can see
  1637. 1:20:51so many messages now did you observe one
  1638. 1:20:54thing some messages went to the
  1639. 1:20:56partition one some messages went to the
  1640. 1:20:59partition
  1641. 1:21:00two some messages went to the partition
  1642. 1:21:02Z now if you see in the partition Z
  1643. 1:21:05total nine messages received to the
  1644. 1:21:07partition Z One received
  1645. 1:21:10925 now rest 75 will be there in the
  1646. 1:21:13partition two all good
  1647. 1:21:1676 okay the messages will or the events
  1648. 1:21:21will be distribute to the number of
  1649. 1:21:23partitions okay okay again we can't
  1650. 1:21:26guarantee who will get the more messages
  1651. 1:21:28or who will get the less messages that
  1652. 1:21:30will be again managed by the coordinator
  1653. 1:21:32okay and this behavior is also same in
  1654. 1:21:34the open source aaji kapka only few of
  1655. 1:21:38the utility you will find in the
  1656. 1:21:39conflent capka okay now in my all the
  1657. 1:21:43upcoming videos I will use the open
  1658. 1:21:45source Apachi kapka but if you are
  1659. 1:21:47familiar now about the confluent capka
  1660. 1:21:50of Community Edition I mean I already
  1661. 1:21:52show you right how we can play with each
  1662. 1:21:55component in open source Apachi capka
  1663. 1:21:58and conflent capka now it is up to you
  1664. 1:22:00when we're doing any program using the
  1665. 1:22:03open source Apachi capka if you want you
  1666. 1:22:05can give a try with this confident capka
  1667. 1:22:07as well
  1668. 1:22:09[Music]
  1669. 1:22:15okay you can install capka on any
  1670. 1:22:18operating system like Windows Mac or
  1671. 1:22:20Linux but the installation process is
  1672. 1:22:23somewhat different different for every
  1673. 1:22:25operating system so instead you will use
  1674. 1:22:28Docker I think it's an even better
  1675. 1:22:30option since you don't have to install
  1676. 1:22:32the tools manually instead you just need
  1677. 1:22:35to write one simple Docker compos file
  1678. 1:22:37which will take care of everything and
  1679. 1:22:40the best part is it will work
  1680. 1:22:42irrespective of any operating system so
  1681. 1:22:44it does not matter what operating system
  1682. 1:22:47you using everything will still work or
  1683. 1:22:50in other word you can say this will act
  1684. 1:22:52as a platform independent okay and I
  1685. 1:22:54would say this will be a quick way to
  1686. 1:22:57get started with capka so without any
  1687. 1:22:59further delay let's move into the
  1688. 1:23:01installation process so in order to
  1689. 1:23:03install capka on the docker container we
  1690. 1:23:06need two things we need an instance of a
  1691. 1:23:09jeeper and an instance of capka
  1692. 1:23:12therefore we are going to create a
  1693. 1:23:14Docker ipen compass. yml file and we are
  1694. 1:23:17going to Define two different service
  1695. 1:23:19one is Juke keeper service and other one
  1696. 1:23:21is the capka service and we'll ask
  1697. 1:23:23Docker to create create these two
  1698. 1:23:25instance for us okay so let's have a
  1699. 1:23:27look how we can Define the docker hpen
  1700. 1:23:29compost. yl file and how we can Define
  1701. 1:23:32the services inside that particular yml
  1702. 1:23:35file okay let's go to the intellig idea
  1703. 1:23:38or you can create in the any editor I'll
  1704. 1:23:42go to the intellig idea I have just
  1705. 1:23:44created one simple folder capka hyen
  1706. 1:23:47installation I'll create a file called
  1707. 1:23:49new click on file and I will give the
  1708. 1:23:52file name as docker hyphen compose do
  1709. 1:23:57yml okay you can keep the extension
  1710. 1:24:00either yml or Y ml it is up to you okay
  1711. 1:24:06I'll just define y ml just click on
  1712. 1:24:11enter now in this Docker compos file you
  1713. 1:24:14can Define what all services you need as
  1714. 1:24:18part of our scenario we need two
  1715. 1:24:20Services zuke keeper and capka okay and
  1716. 1:24:23to start any capka server first we need
  1717. 1:24:26to start the zeper that is what we learn
  1718. 1:24:28before right we have tried multiple
  1719. 1:24:31example using the common line interface
  1720. 1:24:33so we need to first start the Juke
  1721. 1:24:34keeper then we need to start the capka
  1722. 1:24:37correct so I need to define those two
  1723. 1:24:40services so first I will Define the
  1724. 1:24:43version which is
  1725. 1:24:453.1 then I will Define the services you
  1726. 1:24:48can Define n number of services here
  1727. 1:24:51okay so that Docker will create the
  1728. 1:24:53instance for for these Services whatever
  1729. 1:24:55you will Define in this compos file in
  1730. 1:24:58our case we need the services called
  1731. 1:25:00Juke
  1732. 1:25:01keeper okay now how can I get these
  1733. 1:25:04Services simply you need to specify the
  1734. 1:25:07image name of zeper but I don't know
  1735. 1:25:09what is the image name simply go to the
  1736. 1:25:12Chrome browser and you can type
  1737. 1:25:16Ducker
  1738. 1:25:19zeper you can find there will be so many
  1739. 1:25:22Ducker images from the Ducker Hub but
  1740. 1:25:25I'm using the stable one this one
  1741. 1:25:30okay if you'll Zoom this this is the
  1742. 1:25:34image name copy this name just paste it
  1743. 1:25:39Define the image I want this image as a
  1744. 1:25:42zookeeper so that Docker will start this
  1745. 1:25:46zookeeper instances by pulling the image
  1746. 1:25:48from this okay now once you have defined
  1747. 1:25:51the images you can Define the name of
  1748. 1:25:54the container so I'll give the same name
  1749. 1:25:56as a Juke keeper okay now once you have
  1750. 1:26:00defined the image name and container
  1751. 1:26:02name next you can Define the ports where
  1752. 1:26:05this zeper will run hostport and your
  1753. 1:26:09machine Port so I Define 2181 this is
  1754. 1:26:13the default one so I'll specify the
  1755. 1:26:15same fine we have defined one Services
  1756. 1:26:19similarly we need to Define another
  1757. 1:26:20services that is capka so let me copy
  1758. 1:26:23this
  1759. 1:26:24and I will simply paste
  1760. 1:26:28it second service name is kapka and
  1761. 1:26:32images name you can search the
  1762. 1:26:36image just simply change the name of
  1763. 1:26:39your service what you want to use this
  1764. 1:26:41particular tag having this zuke keeper
  1765. 1:26:44and capka so if you want I can show you
  1766. 1:26:49that in this repository if you will
  1767. 1:26:52filter see here we have the capka okay
  1768. 1:26:55I'm using the same now just change the
  1769. 1:26:58container name as a capka and the
  1770. 1:27:01default Port of the capka
  1771. 1:27:049092
  1772. 1:27:079092 once you have defined the service
  1773. 1:27:09zeper and capka then you just need to
  1774. 1:27:12define the environment by telling to the
  1775. 1:27:15capka where is your Juke keeper up and
  1776. 1:27:17running okay so simply just Define the
  1777. 1:27:22environments or environment
  1778. 1:27:24attribute just Define here capka
  1779. 1:27:28advertised host name and the host is
  1780. 1:27:31Local
  1781. 1:27:33Host okay now we just need to Define
  1782. 1:27:36capka Juke keeper connect where is your
  1783. 1:27:39Juke keeper up and running you just need
  1784. 1:27:41to Define that okay so let me quickly
  1785. 1:27:43Define
  1786. 1:27:49it now just
  1787. 1:27:52Define Juke keeper
  1788. 1:27:55it is on Port
  1789. 1:27:572181 okay all looks
  1790. 1:27:59good next once we have created this
  1791. 1:28:03Docker compose file we can execute it
  1792. 1:28:06using the docker compose command Okay
  1793. 1:28:08Docker compose up but before that I just
  1794. 1:28:11want to show you the feature in ID if
  1795. 1:28:14you want to run The Individual Services
  1796. 1:28:16go to that particular service name and
  1797. 1:28:19here you can see the option called
  1798. 1:28:20Docker compos of zeper okay similarly if
  1799. 1:28:23you want to start only capka just go to
  1800. 1:28:26this service I mean this icon here
  1801. 1:28:28you'll find the option to Docker compose
  1802. 1:28:30of capka if you want to run all the
  1803. 1:28:33services what you have defined in your
  1804. 1:28:35file just run on the I mean just click
  1805. 1:28:38on this particular icon okay it will
  1806. 1:28:40execute all the services defined inside
  1807. 1:28:43this compos file okay but I just want to
  1808. 1:28:46run it explicitly in the command prop so
  1809. 1:28:50that you will be aware about the command
  1810. 1:28:52so what I'll do I'll go to this
  1811. 1:28:54particular directory
  1812. 1:28:56first CD capka
  1813. 1:29:00installation
  1814. 1:29:01okay now if I check the ls I have this
  1815. 1:29:04Docker compos yl file so what I want to
  1816. 1:29:08do here I'll simply run the command
  1817. 1:29:12Docker compose then give the file name
  1818. 1:29:16which is Docker compose yml and up that
  1819. 1:29:20particular compos file in the background
  1820. 1:29:22so that is the reason I have defined
  1821. 1:29:24Das D okay so the main command you just
  1822. 1:29:28need to run Docker compose give the file
  1823. 1:29:30name and define up okay just run
  1824. 1:29:34it can you see here it's pulling the
  1825. 1:29:38capka pulling the Juke keeper it will
  1826. 1:29:41take few second to download those two
  1827. 1:29:53images
  1828. 1:29:55okay if You observe here container Juke
  1829. 1:29:58keeper started and container capka
  1830. 1:30:01started also Network UPA installation
  1831. 1:30:03default created it created the default
  1832. 1:30:05Network and it started these two
  1833. 1:30:08container so we didn't ran this Juke
  1834. 1:30:11keeper and capka from our local binary
  1835. 1:30:13distribution rather we asked to the
  1836. 1:30:15docker to create these two instance for
  1837. 1:30:17us okay now to verify whether these two
  1838. 1:30:21container is running or not what I can
  1839. 1:30:24do first let me check the
  1840. 1:30:28images can you see here it created the
  1841. 1:30:31image called capka and you'll also find
  1842. 1:30:33the image called Juke keeper okay now
  1843. 1:30:37we'll verify whether these two instance
  1844. 1:30:38is running or not so simply you can run
  1845. 1:30:41Docker
  1846. 1:30:43PS can you see here let me Zoom
  1847. 1:30:51this so container ID is this and the
  1848. 1:30:54name of the container we have
  1849. 1:30:56defined Juke keeper and capka okay these
  1850. 1:31:01two instances up and running now what
  1851. 1:31:04we'll do let's move ahead one step into
  1852. 1:31:08the Ducker container or capka container
  1853. 1:31:11and we'll execute the command to see
  1854. 1:31:13whether the capka is up or not okay so
  1855. 1:31:17for that what I can do you need to fire
  1856. 1:31:19the
  1857. 1:31:21command let me clear it
  1858. 1:31:26Docker
  1859. 1:31:28execute integrated terminal and name of
  1860. 1:31:32your container ID in our case the
  1861. 1:31:35container ID is capka right that is what
  1862. 1:31:38we have defined our container name next
  1863. 1:31:40just Define slash
  1864. 1:31:43bin
  1865. 1:31:45slsh before that just add a dash here
  1866. 1:31:50okay now if you'll enter it now if
  1867. 1:31:53you'll do the ls you can find these many
  1868. 1:31:56folder okay just go inside CD
  1869. 1:32:00opt now if you'll do the ls you can find
  1870. 1:32:04your capka binary distribution installed
  1871. 1:32:07by the docker itself okay now go inside
  1872. 1:32:10this particular folder I'll copy
  1873. 1:32:15this now we are inside the if you'll
  1874. 1:32:18check the directory we inside SL opt
  1875. 1:32:22capka and the binary version okay now if
  1876. 1:32:26you'll do the ls you'll find license
  1877. 1:32:29notice B everything now if you go inside
  1878. 1:32:32the
  1879. 1:32:35bin you'll find all the script file sell
  1880. 1:32:38script file or batch file for Windows
  1881. 1:32:41can you see here all the Sal script file
  1882. 1:32:45to start the cap card to create the
  1883. 1:32:46topic to produce the messages to consume
  1884. 1:32:50the messages everything you will find
  1885. 1:32:52now what we'll do we'll quickly end of
  1886. 1:32:55this we'll just create a topic and we'll
  1887. 1:32:58publish a message and we'll just consume
  1888. 1:33:00it or we'll just publish a message and
  1889. 1:33:02we'll verify that in upset capka
  1890. 1:33:04Explorer okay so to create a topic you
  1891. 1:33:07know the command so let me enter
  1892. 1:33:11it simply just run this capka
  1893. 1:33:15topic.sh we want to create the topic and
  1894. 1:33:18give the host and the service name of
  1895. 1:33:20Juke keeper replication factor and we
  1896. 1:33:22need partition one topic name is Quick
  1897. 1:33:25Start okay let me Zoom
  1898. 1:33:27this quick start now just enter
  1899. 1:33:33it it created the topic called quick
  1900. 1:33:36start so we'll verify whether this topic
  1901. 1:33:38is created or not so what I can do I'll
  1902. 1:33:41open the upset
  1903. 1:33:46Explorer then just click on this I mean
  1904. 1:33:50you just need to give the see here if
  1905. 1:33:52you'll see the connection property I'm
  1906. 1:33:54giving where is my juke keeper up and
  1907. 1:33:55running now if you open the topic we can
  1908. 1:33:58see the topic got created name quick
  1909. 1:34:01start so there will be no data since we
  1910. 1:34:03didn't publish anything to this topic so
  1911. 1:34:06to publish to the topic what I can do
  1912. 1:34:09I'll go to the
  1913. 1:34:13terminal then I'll simply run the
  1914. 1:34:16producer command capka consult
  1915. 1:34:19producer. to which topic you want to
  1916. 1:34:21produce the messages and what is the
  1917. 1:34:25host and put where your bootstrap server
  1918. 1:34:27or capka server is up and running right
  1919. 1:34:30this is the basic command we already
  1920. 1:34:31tried this many times in our capka
  1921. 1:34:33Series so I'll just enter
  1922. 1:34:36it then I'll send few message hi
  1923. 1:34:41hello Java
  1924. 1:34:45TIY then install kupka using Docker and
  1925. 1:34:52Docker comp
  1926. 1:34:56okay or anything some
  1927. 1:34:59number some random
  1928. 1:35:01messages now how can we verify whether
  1929. 1:35:04the messages what I produce is there in
  1930. 1:35:08the capka server or not or it is there
  1931. 1:35:10in the topic or not simply go to the
  1932. 1:35:13upset
  1933. 1:35:16Explorer now just go to the data I want
  1934. 1:35:21to see all the latest data just execute
  1935. 1:35:24this can you see here all the messages
  1936. 1:35:27what we have just produces is there in
  1937. 1:35:29the topic now what I want to verify that
  1938. 1:35:32is fine producer is able to publish the
  1939. 1:35:35messages to the topic now I want to
  1940. 1:35:38verify whether consumer is able to
  1941. 1:35:41consume this messages or not okay so
  1942. 1:35:44that is again Quick Step what I'll do
  1943. 1:35:46I'll just open a new
  1944. 1:35:48terminal then I will just um it's fine I
  1945. 1:35:52can run from this command also so I'll
  1946. 1:35:55just execute the command
  1947. 1:35:57this then I'll go to the
  1948. 1:36:00directory CD
  1949. 1:36:03opt
  1950. 1:36:04LS I want to go to this particular
  1951. 1:36:07directory
  1952. 1:36:11CD go inside the bin LS that's it right
  1953. 1:36:16now we just need to start a consumer app
  1954. 1:36:19so that it will read whatever the
  1955. 1:36:21messages we have published to this
  1956. 1:36:22particular topic
  1957. 1:36:24so simply go to the
  1958. 1:36:26terminal what I'll do I'll open the
  1959. 1:36:29background here
  1960. 1:36:32okay now let me clear
  1961. 1:36:34everything I'll just run this command
  1962. 1:36:37capka console consuma Dosh read the
  1963. 1:36:41messages from this topic from the
  1964. 1:36:43beginning read it and where is my capka
  1965. 1:36:45server okay just enter
  1966. 1:36:49it can you see here it take few second
  1967. 1:36:52and we able to to consume all the
  1968. 1:36:55messages okay so in real time you can
  1969. 1:36:58follow this approach where you can
  1970. 1:37:00install the Capa Juke keeper MySQL
  1971. 1:37:03redish whatever the services you don't
  1972. 1:37:06want to install on your machine and you
  1973. 1:37:08want to play with them or you are hosted
  1974. 1:37:11to the server where you don't want to
  1975. 1:37:13install them physically but rather you
  1976. 1:37:15are you want to get it from the docker
  1977. 1:37:17so you can go with this particular
  1978. 1:37:19approach all the services you can
  1979. 1:37:21install through this particular Docker
  1980. 1:37:23compose approach okay and this is really
  1981. 1:37:26needed if your application hosted to the
  1982. 1:37:29cloud infrastructure and if you are not
  1983. 1:37:31using the managed service given by the
  1984. 1:37:33cloud provider then you must need to
  1985. 1:37:35play with this container platform using
  1986. 1:37:37this Docker compose so do let me know in
  1987. 1:37:40a comment section if you guys have any
  1988. 1:37:42[Music]
  1989. 1:37:49doubts so in this tutorial we'll
  1990. 1:37:52understand how to produ produce or
  1991. 1:37:54publish a message to the capka topic
  1992. 1:37:55using spring Boot and also we'll Deep
  1993. 1:37:58dive further to understand how the
  1994. 1:38:00messages are getting distributed to
  1995. 1:38:02multiple partitions okay all right so
  1996. 1:38:05let's quickly create a new project to
  1997. 1:38:07demonstrate capka using springboard
  1998. 1:38:09first let me create a new project from
  1999. 1:38:11the intellig
  2000. 1:38:13itself
  2001. 1:38:16project Define the group ID artifact ID
  2002. 1:38:19version all the
  2003. 1:38:22things
  2004. 1:38:25change it to
  2005. 1:38:26Maven let it be jdk 17 is required since
  2006. 1:38:29we using the spring boot
  2007. 1:38:323.0 then specify this project
  2008. 1:38:38name next here you need to choose the
  2009. 1:38:40correct dependency so I'm going to use
  2010. 1:38:43the web dependency because I want to
  2011. 1:38:45expose on endpoint if I'll trigger that
  2012. 1:38:47endpoint it will publish message to the
  2013. 1:38:48capka okay that is what I want to design
  2014. 1:38:51I need web and the main dependency you
  2015. 1:38:54need to add is capka dependency now if
  2016. 1:38:57You observe here there are two
  2017. 1:38:58dependency you are getting for capka one
  2018. 1:39:00is for capka stream one one is for
  2019. 1:39:03spring for aaji kapka okay so we are
  2020. 1:39:05going to use this since we are not going
  2021. 1:39:07to use the capka stream for now we'll go
  2022. 1:39:09with the spring capka dependency okay I
  2023. 1:39:13believe that's enough now click on
  2024. 1:39:18next so next Once the project is
  2025. 1:39:21imported successfully since we are
  2026. 1:39:23playing with the capka first we need to
  2027. 1:39:25start the capka server and already I
  2028. 1:39:28explained the order to start the capka
  2029. 1:39:30first you need to start the Juke keeper
  2030. 1:39:32then you need to start the capka server
  2031. 1:39:34then as for your need whether you want
  2032. 1:39:35to create a topic and you want to
  2033. 1:39:37configure partition count replication
  2034. 1:39:39Factor all these steps you can do but to
  2035. 1:39:41start the capka server first you need to
  2036. 1:39:43start the Juke keeper okay so what I'll
  2037. 1:39:46do I'll go to the directory where I
  2038. 1:39:48install my capka this is what the
  2039. 1:39:50directory then I'll open the terminal
  2040. 1:39:53okay so I'll start the Juke keeper first
  2041. 1:39:56so I already shared the GitHub link
  2042. 1:39:58where I have defined all the command for
  2043. 1:40:00the capka so the first command to start
  2044. 1:40:02the Juke keeper I will copy this then
  2045. 1:40:05I'll go to the
  2046. 1:40:06terminal fine then I will just start the
  2047. 1:40:09Juke keeper
  2048. 1:40:12okay once I start the Juke keeper then
  2049. 1:40:15immediately I'll start my capka server
  2050. 1:40:18so for that I will go to the terminal
  2051. 1:40:20and I will take the command to start the
  2052. 1:40:23C
  2053. 1:40:25server then I'll open a new
  2054. 1:40:30terminal okay I can start the capka
  2055. 1:40:33server
  2056. 1:40:36here fine so if You observe my capka
  2057. 1:40:40server is started on Port 9092 that is
  2058. 1:40:44the default Port okay I just highlight
  2059. 1:40:47here if you can see this let me Zoom
  2060. 1:40:49this for you 9092 is the default Port of
  2061. 1:40:52my kapka server okay and this is my juke
  2062. 1:40:56keeper fine now all good all our kapka
  2063. 1:41:01ecosystem is ready to start the
  2064. 1:41:02development go to your intellig idea and
  2065. 1:41:05first I will go to application.
  2066. 1:41:07properties file or you can create the
  2067. 1:41:09application. yml file to tell to this
  2068. 1:41:12application where is your capka server
  2069. 1:41:14is up and running if you'll not specify
  2070. 1:41:16that how your application is know that
  2071. 1:41:19where is your capka is running so that
  2072. 1:41:20you will publish the message right so
  2073. 1:41:22that's Theon
  2074. 1:41:23you need to specify in your application
  2075. 1:41:26that where is your bootstrap server of
  2076. 1:41:28Capa producer is running okay so I'll
  2077. 1:41:30create a file I'll name it application.
  2078. 1:41:35yml then I can Define here first I will
  2079. 1:41:38Define my server Port let's say I just
  2080. 1:41:40want to define something 91
  2081. 1:41:4291 then I will Define spring capka
  2082. 1:41:47producer then bootstrap server okay and
  2083. 1:41:51give the URL you can Define multiple
  2084. 1:41:55server port and host but since we have
  2085. 1:41:57only the default one which is our local
  2086. 1:41:59host I just specify Here Local Host and
  2087. 1:42:03the default Port is
  2088. 1:42:079092 fine next let me create couple of
  2089. 1:42:11package where we can Define our logic to
  2090. 1:42:14publish the message to the capka
  2091. 1:42:20okay next let me create the service
  2092. 1:42:23class where actually we will write the
  2093. 1:42:25code to publish the messages so I will
  2094. 1:42:28create a class called let's say I'll
  2095. 1:42:29will give a name something like capka
  2096. 1:42:31message publisher something like that
  2097. 1:42:36okay now this is the class so in this
  2098. 1:42:39class to publish a message to the capka
  2099. 1:42:41or from our application if you want to
  2100. 1:42:44talk to the capka server then you need
  2101. 1:42:46to use some class given by the spring
  2102. 1:42:48framework that is capka template okay
  2103. 1:42:54capka
  2104. 1:42:56template Define the key and value for
  2105. 1:42:58now let me Define the key as a string
  2106. 1:43:00and value as a
  2107. 1:43:04object let me annotate this class as a
  2108. 1:43:06atate
  2109. 1:43:07service and I need to Auto add
  2110. 1:43:11this fine now here I'll write a simple
  2111. 1:43:15method public will simply return the
  2112. 1:43:18message nothing else I mean we'll simply
  2113. 1:43:20return the message to the topic so so
  2114. 1:43:23I'll name it send message to
  2115. 1:43:28topic what message you want to send I'll
  2116. 1:43:31pass it from the
  2117. 1:43:34controller since we have injected the
  2118. 1:43:37template now what we can do using this
  2119. 1:43:39template we can talk to the capka server
  2120. 1:43:41so I'll just use this instance template
  2121. 1:43:44do send method If You observe send is
  2122. 1:43:47the overloaded method it contains
  2123. 1:43:49multiple argument you can use as for
  2124. 1:43:51your need since I just want to send a
  2125. 1:43:53simple message to the topic I'll use
  2126. 1:43:56this second method overloaded method
  2127. 1:43:58I'll specify the topic name let's say JT
  2128. 1:44:01or Java
  2129. 1:44:04Tey fine and then I need to specify what
  2130. 1:44:08data I want to send to the topic this
  2131. 1:44:11one now one thing you need to observe
  2132. 1:44:14here we have used this template. send
  2133. 1:44:16method but if you'll take a look into
  2134. 1:44:19its return return type it is completable
  2135. 1:44:22Future
  2136. 1:44:23okay so this is the completable future
  2137. 1:44:26so here if you want to block the sending
  2138. 1:44:28thread and get the result about the sent
  2139. 1:44:30messages then what you can do simply you
  2140. 1:44:33can do future do get API call from the
  2141. 1:44:38completable future then the thread will
  2142. 1:44:40wait for the results to come but it will
  2143. 1:44:42definitely slow down the producer as you
  2144. 1:44:45know capka is a fast in processing
  2145. 1:44:47platform therefore it's better to handle
  2146. 1:44:50the results asynchronously so that the
  2147. 1:44:52subsequent message do not wait for the
  2148. 1:44:54result of the previous messages okay now
  2149. 1:44:57how we can do that we can do this using
  2150. 1:44:59a call back implementation I'll show you
  2151. 1:45:02that how we can do that let's remove
  2152. 1:45:04this piece of code we'll simply tell to
  2153. 1:45:06this future object
  2154. 1:45:09future when complete when the future
  2155. 1:45:12will be complete okay then I will use
  2156. 1:45:15the Lambda it will give me the result
  2157. 1:45:17and also it will give me the parameter
  2158. 1:45:19of exception okay now I can simply print
  2159. 1:45:23whatever the things I
  2160. 1:45:25need so just add a comma here and I'll
  2161. 1:45:28just add some print statement okay so
  2162. 1:45:31here what I'm doing I'm just checking if
  2163. 1:45:34xal equal to null if there is no
  2164. 1:45:36exception it means message is sent and I
  2165. 1:45:38just want to tag what messages we have
  2166. 1:45:41sent and what is the upset number of it
  2167. 1:45:44also if you want you can also get the
  2168. 1:45:46partition number where the message went
  2169. 1:45:48okay so if you see here there is a
  2170. 1:45:51method result Dot get record metadata do
  2171. 1:45:56get not record
  2172. 1:45:58metadata uh okay
  2173. 1:46:02dot you can see here the partition okay
  2174. 1:46:05you also if you want to print the
  2175. 1:46:06partition you can do that but let's make
  2176. 1:46:08it simple okay I am trying to make it
  2177. 1:46:10asynchronous so that it don't wait for
  2178. 1:46:13the result to come and I am just simply
  2179. 1:46:15printing the message this is for success
  2180. 1:46:17and this is for failure okay that's it
  2181. 1:46:21now this is the me method who will send
  2182. 1:46:23message to the topic now I will call
  2183. 1:46:26this method from my controller class so
  2184. 1:46:28I'll create a controller class
  2185. 1:46:31quickly I'll name it
  2186. 1:46:35event now I need to un your atate R
  2187. 1:46:39controller I'll also Define request
  2188. 1:46:42mapping and I'll give some URL
  2189. 1:46:46here then I need to inject the capka
  2190. 1:46:49message publisher the service class okay
  2191. 1:46:52so I'll just inject private let me Zoom
  2192. 1:46:59this so once you inject the publisher
  2193. 1:47:02now I can simply Define the endpoint who
  2194. 1:47:04will publish the message okay so I'll
  2195. 1:47:07write public response
  2196. 1:47:09entity up type
  2197. 1:47:12generic let's say publish
  2198. 1:47:16message okay I'll pass the message in
  2199. 1:47:19the request
  2200. 1:47:21URL and here at path
  2201. 1:47:25variable also I will Define this as a
  2202. 1:47:28gate
  2203. 1:47:31mapping Define the URL I'll just Define
  2204. 1:47:34publish and what message I want to
  2205. 1:47:38publish simple right now what I can do
  2206. 1:47:43I'll simply call
  2207. 1:47:45Publisher dot send message to the topic
  2208. 1:47:49and I will simply give the message
  2209. 1:47:51name that's it
  2210. 1:47:53but for safer side I'll keep it inside
  2211. 1:47:56the try
  2212. 1:48:00catch fine now here I'll just return
  2213. 1:48:04response
  2214. 1:48:06entity do okay and some
  2215. 1:48:10messages I'll give something like
  2216. 1:48:17message similarly in the catch also I'll
  2217. 1:48:20just Define return respon
  2218. 1:48:23entity dot I can specify the
  2219. 1:48:27status which will be HTTP
  2220. 1:48:31status do internal server error anything
  2221. 1:48:34whatever you want to specify okay then
  2222. 1:48:37I'll simply build
  2223. 1:48:39it fine I have just handled the TR cage
  2224. 1:48:42here to just track the response or to
  2225. 1:48:46just track the uh event whether it is
  2226. 1:48:48successfully published or not fine let's
  2227. 1:48:51say my capka server is down and I'm
  2228. 1:48:53sending the messages then definitely I
  2229. 1:48:54will get the internal server error you
  2230. 1:48:57can handle it in better way but this is
  2231. 1:48:59the simple exception handling I have did
  2232. 1:49:01here okay so now we are all set to start
  2233. 1:49:05the server okay I mean application now
  2234. 1:49:09if You observe one thing we have not
  2235. 1:49:11create topic manually okay if You
  2236. 1:49:14observe here while sending the messages
  2237. 1:49:18to using this Capa template I'm just
  2238. 1:49:20giving the topic name but I have not
  2239. 1:49:23created it manually through the command
  2240. 1:49:25prompt so whether the spring boot will
  2241. 1:49:29create the topic for us or not that we
  2242. 1:49:31are going to verify if spring boot will
  2243. 1:49:33create the topic on behalf of us then
  2244. 1:49:36what is the default configuration he
  2245. 1:49:37will add that we are going to verify now
  2246. 1:49:40okay so all good let me go to the main
  2247. 1:49:45class just start the
  2248. 1:49:50application so you can observe here it
  2249. 1:49:52started on Port 9191 now let's go to the
  2250. 1:49:56postman and try to hit this particular
  2251. 1:49:58end point / producer hyen app SLP
  2252. 1:50:01publish on the messages okay now let me
  2253. 1:50:04clear
  2254. 1:50:07this let's say I'll just pass a message
  2255. 1:50:13welcome can you see here message
  2256. 1:50:16published successfully and now if you go
  2257. 1:50:19and check in your console you can find
  2258. 1:50:21that is what we have just added in our
  2259. 1:50:23completable future when complete this
  2260. 1:50:25messages we are going to print the
  2261. 1:50:27message we have sent is welcome let me
  2262. 1:50:29Zoom this for you and the upset count is
  2263. 1:50:32zero offset is nothing the position of
  2264. 1:50:34your message inside the partition okay
  2265. 1:50:37so that already I explain in the capka
  2266. 1:50:39component and its architecture so I hope
  2267. 1:50:42that makes sense to understand this uh
  2268. 1:50:44term okay now I'll add some other
  2269. 1:50:47messages let's say
  2270. 1:50:50ABC
  2271. 1:50:51DF
  2272. 1:50:55Ram
  2273. 1:50:57bimol okay so I have published near to
  2274. 1:50:59four or five messages now let's see go
  2275. 1:51:02and check in your console see all the
  2276. 1:51:04messages is assigning to the upset but
  2277. 1:51:07we are not sure whether it is going to
  2278. 1:51:09which partition because even we don't
  2279. 1:51:11know the topic configuration created by
  2280. 1:51:13Spring boot so let's verify the topic
  2281. 1:51:16configuration then I will show you how
  2282. 1:51:18you can create manually and how you can
  2283. 1:51:20create programmatically okay so now to
  2284. 1:51:24describe the topic what I can do I'll
  2285. 1:51:26will go to the uh
  2286. 1:51:29terminal then simply fire this command
  2287. 1:51:32give your topic name which is Java Tei
  2288. 1:51:36hyphen demo one so already all the
  2289. 1:51:40required command I have shared in this G
  2290. 1:51:42repo okay so I will also share this link
  2291. 1:51:45in video description so you can use that
  2292. 1:51:48now let me trigger
  2293. 1:51:51this so so if You observe here the
  2294. 1:51:54partition count equal to 1 and
  2295. 1:51:56replication Factor equal to 1 so
  2296. 1:51:58whenever we are allowing spring boot to
  2297. 1:52:01create the topic on behalf of us it will
  2298. 1:52:03go with the default configuration with
  2299. 1:52:05the partition count one it won't give
  2300. 1:52:08you the correct or proper throw put if
  2301. 1:52:10your application is being used by
  2302. 1:52:12multiple consumer they cannot able to
  2303. 1:52:15handle your request concurrently because
  2304. 1:52:17of this partition count now how you can
  2305. 1:52:19create topic with your own configuration
  2306. 1:52:22let's say I want to go with Partition
  2307. 1:52:23count 5 or 10 15 as for my needed then
  2308. 1:52:27you need to create it manually how we
  2309. 1:52:29can create that you can go to this and I
  2310. 1:52:32have already shared this command copy
  2311. 1:52:35this and just go to the terminal
  2312. 1:52:40again just trigger this command and you
  2313. 1:52:43just need to change the topic
  2314. 1:52:47name so I will change it
  2315. 1:52:49to Java Tey
  2316. 1:52:54okay let me create
  2317. 1:52:59this it created the topic for me but
  2318. 1:53:03before we use this javat demo to topic
  2319. 1:53:05first let's verify javat demo and topic
  2320. 1:53:08whatever the message we have sent
  2321. 1:53:10whether it is there in the topic or not
  2322. 1:53:12if it is there what is the partition and
  2323. 1:53:14what is the upset we can visualize okay
  2324. 1:53:17so to visualize the capka ecosystem I
  2325. 1:53:19already explained you can use the offset
  2326. 1:53:22EXP Explorer okay just open this then
  2327. 1:53:26simply take the
  2328. 1:53:28connection now if you'll observe here
  2329. 1:53:31there are two topic right javate demo
  2330. 1:53:34one javate demo hyphen 2 okay so the
  2331. 1:53:39first topic we use this demo one so if
  2332. 1:53:41I'll open this topic if I'll click on
  2333. 1:53:44the data and if I'll change it to the
  2334. 1:53:47new and if I'll send the request we can
  2335. 1:53:50see all the five messages we have
  2336. 1:53:51published right welcome ABC d a ram Bal
  2337. 1:53:56okay and corresponding upset and all
  2338. 1:53:58went to the partition zero because we
  2339. 1:54:00have only one partition now since we
  2340. 1:54:02have created the other topic with the
  2341. 1:54:05three partition 0 and one two you can
  2342. 1:54:07see here now let's see how we can send
  2343. 1:54:11multiple or bulk messages to the topic
  2344. 1:54:13so that message will be distribute to
  2345. 1:54:16multiple partition so what we'll do
  2346. 1:54:19we'll use this topic in our code now
  2347. 1:54:21rather than using the default topy
  2348. 1:54:22created by springboard to verify the
  2349. 1:54:25messages bulk messages is getting
  2350. 1:54:27distributed to multiple partition that
  2351. 1:54:30is have the increasing the throw put
  2352. 1:54:32from the middleman of kfka okay so what
  2353. 1:54:35I'll do I'll just go to the code first
  2354. 1:54:38I'll change the topic
  2355. 1:54:40name Java demo hyphen 2 this topic have
  2356. 1:54:45three partition okay so you f send bulk
  2357. 1:54:48messages let me write some logic to send
  2358. 1:54:50some bulk messages so go to the
  2359. 1:54:53controller what I'll do I'll just Define
  2360. 1:54:56a for Loop
  2361. 1:54:58here int I = to z i less than equal to
  2362. 1:55:04let's say I just want to send 10,000
  2363. 1:55:06messages okay that is how I can show you
  2364. 1:55:09how I can send the bulk message
  2365. 1:55:14i++ so here also I will just do some
  2366. 1:55:16changes with the message I'll just upend
  2367. 1:55:19the
  2368. 1:55:21number
  2369. 1:55:23whatever the message I will send let's
  2370. 1:55:24say I send user then user one 2 like
  2371. 1:55:2710,000 user string message will publish
  2372. 1:55:30to the Capa topic then we'll verify
  2373. 1:55:32since we have the three partition how
  2374. 1:55:34many messages is went to each partition
  2375. 1:55:36and how the messages is getting
  2376. 1:55:38distributed okay this is the simple way
  2377. 1:55:41to demonstrate this particular concept
  2378. 1:55:44all good let me restart
  2379. 1:55:48it so you can see here application
  2380. 1:55:50started on Port 9 91 go to the postman
  2381. 1:55:54then I'll simply trigger here let's say
  2382. 1:55:56user so that it will append user 1 2 3
  2383. 1:55:59like that okay now I will send the
  2384. 1:56:01request which will trigger 10,000
  2385. 1:56:04message to the capka topic send the
  2386. 1:56:07request it took 1 1915 millisecond okay
  2387. 1:56:12now go to
  2388. 1:56:13the this particular upside Explorer now
  2389. 1:56:16let me refresh
  2390. 1:56:18this okay I'll go to this particular
  2391. 1:56:21topic
  2392. 1:56:22and if I'll just verify the data there
  2393. 1:56:25are so many messages okay now if I'll
  2394. 1:56:29verify each message count from each
  2395. 1:56:32partition let's say I went to partition
  2396. 1:56:34zero it received 1682 messages if you
  2397. 1:56:38want to see the data of those particular
  2398. 1:56:41thing you can hit this all the messages
  2399. 1:56:43you will get from the partition zero and
  2400. 1:56:47you can find this upset here right so
  2401. 1:56:49the count we want to see it receive one
  2402. 1:56:521682 out of 10,000 now we verify
  2403. 1:56:55partition 1 it receed 5120
  2404. 1:56:595,120 now we'll see the partition two it
  2405. 1:57:02received
  2406. 1:57:043,19 all the three partition received
  2407. 1:57:07the message from the producer what we
  2408. 1:57:10just published now okay so it clearly
  2409. 1:57:13says that whenever you have multiple
  2410. 1:57:15partitions capka scheduler or Juke
  2411. 1:57:18keeper will take care to handle the
  2412. 1:57:20message load and splited into to the or
  2413. 1:57:22distributed into the multiple partition
  2414. 1:57:25based on their availability okay so you
  2415. 1:57:28can see here
  2416. 1:57:29again partition 0 1 and two they both
  2417. 1:57:33have some information or some
  2418. 1:57:35messages so this is how capka distribute
  2419. 1:57:39the load to multiple partition now the
  2420. 1:57:42next thing in a real time do we need to
  2421. 1:57:45create the topic from this command the
  2422. 1:57:47way I have created here javat demo 2 it
  2423. 1:57:51is up to you
  2424. 1:57:52in some case in some industry they have
  2425. 1:57:55their own portal to create the topic
  2426. 1:57:57from the automated way but if you don't
  2427. 1:58:00want to do or if you don't want to
  2428. 1:58:02create it from the command promt then
  2429. 1:58:04there is a way given by the spring
  2430. 1:58:06framework you can programmatically
  2431. 1:58:08create the topic now I will show you how
  2432. 1:58:11you can create the topic
  2433. 1:58:12programmatically okay just go to your
  2434. 1:58:15code so what I'll do I'll create another
  2435. 1:58:19package config now I'll create a
  2436. 1:58:27class then simply uned this atate
  2437. 1:58:31configuration
  2438. 1:58:32fine then next there is a class given by
  2439. 1:58:36Spring framework that is new topic using
  2440. 1:58:38that you can create a new topic so let
  2441. 1:58:41me do that public new topic make sure to
  2442. 1:58:45import it from ca. clients.
  2443. 1:58:50admin now you can just return new new
  2444. 1:58:55topic this is also overloaded method and
  2445. 1:58:58you can see here new topic you can
  2446. 1:59:00specify the topic name you want to
  2447. 1:59:02create you can specify the number of
  2448. 1:59:04partition you want to use and
  2449. 1:59:06replication Factor see all the required
  2450. 1:59:09information you can specify here let me
  2451. 1:59:11specify the name javat Tei
  2452. 1:59:16demo three okay and number of partition
  2453. 1:59:20let's say I just want to Define five
  2454. 1:59:23and replication Factor let's say I just
  2455. 1:59:26want to Define one so it will be in the
  2456. 1:59:31S specify the count
  2457. 1:59:35one okay let me Zoom
  2458. 1:59:38this now just Define this at theate
  2459. 1:59:42B fine so we are not creating the topic
  2460. 1:59:46using the command or we are not allowing
  2461. 1:59:48our spring boot to create the default
  2462. 1:59:51topic rather
  2463. 1:59:52we tell to the spring whatever the topic
  2464. 1:59:54configuration we need programmatically
  2465. 1:59:57we are telling him this is the topic
  2466. 1:59:59name I want to create and this is the
  2467. 2:00:00number of partition I want to keep as
  2468. 2:00:02part of my topic and number of
  2469. 2:00:04replication Factor okay now let me use
  2470. 2:00:06the same topic in my
  2471. 2:00:12services fine now let me rerun our
  2472. 2:00:17app so again it started now go to the
  2473. 2:00:20postman let me clear this
  2474. 2:00:23now we have five topic okay so we'll
  2475. 2:00:25verify first whether the topic is
  2476. 2:00:27created or not can you see here topic is
  2477. 2:00:31created with five partition see the
  2478. 2:00:34partition count 0 1 2 3 4 we don't have
  2479. 2:00:37any data because we have not published
  2480. 2:00:39any message to this particular topic now
  2481. 2:00:41same 10,000 messages again I want to
  2482. 2:00:43publish to the topic Java demo three and
  2483. 2:00:46we have five partition now now let's see
  2484. 2:00:49how much record how many record is going
  2485. 2:00:52to each partition there there could be
  2486. 2:00:54possible that some partition will not
  2487. 2:00:56get any single message also okay because
  2488. 2:00:59that is not in our hand that will be
  2489. 2:01:01handled by the capka schuer okay or Juke
  2490. 2:01:04keeper now I'll just send the
  2491. 2:01:08request all the message is published
  2492. 2:01:11let's verify
  2493. 2:01:13it just refresh
  2494. 2:01:17it go to the data trigger it
  2495. 2:01:22now let's see whether all the partition
  2496. 2:01:25is getting the messages or not partition
  2497. 2:01:28zero received
  2498. 2:01:303,717 partition one received
  2499. 2:01:331,954 partition 2 received
  2500. 2:01:37496 partition three didn't received
  2501. 2:01:39anything partition four received
  2502. 2:01:41something
  2503. 2:01:423834 out of five partition parti 3
  2504. 2:01:47didn't received any single message okay
  2505. 2:01:49so that is the reason it's not enough
  2506. 2:01:51our hand it will be decided by Juke
  2507. 2:01:53keeper to whom he need to send the
  2508. 2:01:55messages since we are only sending
  2509. 2:01:5710,000 messages Juke keeper assume that
  2510. 2:02:00okay these four partition is capable
  2511. 2:02:02enough to handle those kind of messages
  2512. 2:02:05to increase the throw putut okay so that
  2513. 2:02:07is how they will decide so this is how
  2514. 2:02:09you can develop your producer
  2515. 2:02:11application and you can also customize
  2516. 2:02:13your topic as for your required
  2517. 2:02:15configuration to increase the
  2518. 2:02:17application performance okay so in my
  2519. 2:02:20upcoming tutorial I will explain about
  2520. 2:02:22the consumer part so we understand
  2521. 2:02:24producer and we send message to the
  2522. 2:02:26topic and topic is being splitted to the
  2523. 2:02:29multiple partition so all the message
  2524. 2:02:31went to multiple partition okay now in
  2525. 2:02:33my next tutorial I will show you how you
  2526. 2:02:36can develop the consumer and how
  2527. 2:02:38concurrently you can handle the events
  2528. 2:02:40coming from the cap cut topic to this
  2529. 2:02:43consumer
  2530. 2:02:50okay so who when your producer
  2531. 2:02:52application will produce the messages it
  2532. 2:02:55needs to consume by the consumer
  2533. 2:02:57otherwise by keeping the messages in a
  2534. 2:02:59topic without using it does not make any
  2535. 2:03:02sense so you need to write a consumer
  2536. 2:03:04app who will consume the messages from
  2537. 2:03:06your topic now if You observe in the
  2538. 2:03:09flow one consumer is listening to three
  2539. 2:03:12different partition which is not good I
  2540. 2:03:14mean it don't give you the better
  2541. 2:03:16throughput then how can we design our
  2542. 2:03:18consumer app to overcome this issue it's
  2543. 2:03:21very simple just share the workload to
  2544. 2:03:24multiple consumer instance so what you
  2545. 2:03:26can do we can simply create multiple
  2546. 2:03:29consumer instance and then we can group
  2547. 2:03:31them with an unique ID so that this ID
  2548. 2:03:34will indicate the task of a specific
  2549. 2:03:36consumer group so now if You observe we
  2550. 2:03:40have three consumer instance right and
  2551. 2:03:42how many partition do we have three so
  2552. 2:03:45each partition can consumed by
  2553. 2:03:48individual consumer instance which will
  2554. 2:03:50definitely increase the through put
  2555. 2:03:52earlier a single consumer instance is
  2556. 2:03:54pointing to multiple partition now we
  2557. 2:03:57have a individual consumer instance for
  2558. 2:03:59each partition of our topic definitely
  2559. 2:04:02this will give you the better
  2560. 2:04:04performance but what if I have another
  2561. 2:04:06consumer instance then what you'll do
  2562. 2:04:09because already three partition is being
  2563. 2:04:10assigned to three consumer instance then
  2564. 2:04:13what the fourth consumer instance will
  2565. 2:04:15do nothing he will simply stay on bench
  2566. 2:04:18the way it company hires the employee
  2567. 2:04:21and keeping the them in a bench for
  2568. 2:04:22future project and once the project came
  2569. 2:04:25they assign the employee right similarly
  2570. 2:04:28if any consumer instance dies then this
  2571. 2:04:31consumer 4 will replace that and start
  2572. 2:04:34consuming the messages and this concept
  2573. 2:04:37is called consumer rebalancing okay so
  2574. 2:04:40this is what all about the theory of
  2575. 2:04:43capka consumer on the basic level so we
  2576. 2:04:47understand the theory now let's start
  2577. 2:04:49implementing our consumer app to
  2578. 2:04:51understand this PR ially okay so let's
  2579. 2:04:53go to the intelligent idea so this is
  2580. 2:04:56the cup producer example we have tried
  2581. 2:04:58last time now let's quickly create a
  2582. 2:05:00Capa consumer application click on file
  2583. 2:05:03new click on
  2584. 2:05:05Project click
  2585. 2:05:07next then specify all the required
  2586. 2:05:14field now let's add all the required
  2587. 2:05:16dependency I'll just add
  2588. 2:05:19capka spring for Apachi kapka
  2589. 2:05:22and then I will just add web
  2590. 2:05:24dependency spring web that's it click on
  2591. 2:05:28next click on
  2592. 2:05:30finish so now we have created the
  2593. 2:05:33consumer application now if You observe
  2594. 2:05:36here consumer application is the one who
  2595. 2:05:39connect to the capka topic to receive
  2596. 2:05:41the messages so you need to tell to your
  2597. 2:05:43consumer application where is your capka
  2598. 2:05:45server up and running then only he can
  2599. 2:05:47connect to the topic and he can retrive
  2600. 2:05:49the messages right so first
  2601. 2:05:52you need to tell to your consumer where
  2602. 2:05:54is your capka server is up and running
  2603. 2:05:56so go to the resource or application or
  2604. 2:05:58properties it is up to you I'm using the
  2605. 2:06:00application. IML
  2606. 2:06:04file now here you will Define spring
  2607. 2:06:08capka then consumer and where is your
  2608. 2:06:11bootstrap server is up and running in
  2609. 2:06:13our case it is running on Port Local
  2610. 2:06:16Host 9092 make sure before you start
  2611. 2:06:19your producer and consumer you should
  2612. 2:06:21start your Juke keeper then your capka
  2613. 2:06:23server okay and also I'll just change
  2614. 2:06:26the server Port
  2615. 2:06:28here server
  2616. 2:06:31Port
  2617. 2:06:329292 because I believe my producer is up
  2618. 2:06:36and running on Port 91 okay 91 91 so I
  2619. 2:06:40just change it to the 9292 that's it now
  2620. 2:06:43let me quickly create a package so that
  2621. 2:06:46we can start creating a class who will
  2622. 2:06:47do the actual logic or who will try to
  2623. 2:06:51face the messages from the topic okay
  2624. 2:06:53let me create a
  2625. 2:06:56package then we'll create a
  2626. 2:07:00class now just unnoted this class with
  2627. 2:07:02adate
  2628. 2:07:04service fine now we'll write a method
  2629. 2:07:08who will do the actual logic to retrieve
  2630. 2:07:10the message from the
  2631. 2:07:11topic public void so what I'll do I need
  2632. 2:07:15to an your SL forj okay I didn't added
  2633. 2:07:18the lbo fine I'll create the logger
  2634. 2:07:20object
  2635. 2:07:27then complete the
  2636. 2:07:28method consume that's
  2637. 2:07:32it now which type of data we are sending
  2638. 2:07:35from the producer if you go and check in
  2639. 2:07:38your
  2640. 2:07:39producer go to the class we are sending
  2641. 2:07:43message of type string right so you need
  2642. 2:07:47to specify the type what messages this
  2643. 2:07:49method will consume so I'll will specify
  2644. 2:07:53string
  2645. 2:07:55message fine now I'll just add the log
  2646. 2:07:58statement to print that
  2647. 2:08:00messages logger or just change it to the
  2648. 2:08:07log just add some messages
  2649. 2:08:10okay
  2650. 2:08:12consumer consume the
  2651. 2:08:17message and the messages we are
  2652. 2:08:20receiving
  2653. 2:08:22fine we are not doing anything we are
  2654. 2:08:24simply write a method to consume the
  2655. 2:08:26message and we are just simply printing
  2656. 2:08:28them now how this consumer will know
  2657. 2:08:32from which topic he need to read the
  2658. 2:08:34messages that you need to tell to the
  2659. 2:08:37you need to tell to the consumer okay
  2660. 2:08:40how you can tell that simple The
  2661. 2:08:41annotation is capka listener now in this
  2662. 2:08:46Capa listener annotation you can tell to
  2663. 2:08:48the application or you can tell to this
  2664. 2:08:51consumer who is the topic from where you
  2665. 2:08:53want to read the messages okay so in our
  2666. 2:08:57case what is the topic we created in our
  2667. 2:08:58producer
  2668. 2:09:00application Java demo right we are
  2669. 2:09:04creating the topic in our config class
  2670. 2:09:07this is where we are creating the topic
  2671. 2:09:10with three partition so you need to
  2672. 2:09:13specify the same topic name in consumer
  2673. 2:09:16from where you want to listen the
  2674. 2:09:18messages now all good let me start the
  2675. 2:09:21the producer then we'll start the
  2676. 2:09:23consumer app so go to the
  2677. 2:09:26producer start it once it will up we'll
  2678. 2:09:30start our
  2679. 2:09:31consumer so producer is up on put 9191
  2680. 2:09:35now let me start the consumer app go to
  2681. 2:09:38the main class and simply start
  2682. 2:09:41it meanwhile I will open the
  2683. 2:09:44postman let's check the producer code in
  2684. 2:09:48our
  2685. 2:09:49application just go to the public
  2686. 2:09:52not here go to the controller just
  2687. 2:09:54wanted to check how many messages we are
  2688. 2:09:56publishing okay 10,000 right that's fine
  2689. 2:09:59we can send the 10,000 and we'll see
  2690. 2:10:02whether it is getting logged in our
  2691. 2:10:03consumer or not then we'll change
  2692. 2:10:06it so we'll go and check our consumer
  2693. 2:10:09app we are getting the error now if You
  2694. 2:10:13observe carefully the error clearly says
  2695. 2:10:16that no group ID found in consumer
  2696. 2:10:19config as I already explained even
  2697. 2:10:22though you have a single consumer
  2698. 2:10:24instance still you need to map it to a
  2699. 2:10:27consumer ID but in our code we have not
  2700. 2:10:30specify any consumer ID okay that is the
  2701. 2:10:33reason kapka is giving error hey just
  2702. 2:10:36map a group ID to your consumer instance
  2703. 2:10:40so if you'll
  2704. 2:10:42Define group ID here group ID and let me
  2705. 2:10:47give something like JT hyphen group
  2706. 2:10:52hen one something like that okay and
  2707. 2:10:54also I need to configure this particular
  2708. 2:10:57group ID in yml file or application or
  2709. 2:11:00properties file as well okay because
  2710. 2:11:02that is the central place where we are
  2711. 2:11:04specifying our configuration so
  2712. 2:11:09spring okay so already we have defined
  2713. 2:11:11this so in the consumer section only you
  2714. 2:11:14can Define group ID what is the group ID
  2715. 2:11:17JT group one this is the group ID we
  2716. 2:11:20have created you can any unique name
  2717. 2:11:22okay it will just help you to find the
  2718. 2:11:25role of your consumer group or to find
  2719. 2:11:27the role of your this particular
  2720. 2:11:30consumer Group which task it is doing
  2721. 2:11:32that is the reason you can segregate
  2722. 2:11:33using this consumer or group ID okay
  2723. 2:11:37that's fine now go to The Listener we
  2724. 2:11:41have defined the same and we have
  2725. 2:11:42defined same in our config now let me
  2726. 2:11:44restart it
  2727. 2:11:47again so consumer app is up and running
  2728. 2:11:50now if You observe
  2729. 2:11:52carefully let me Zoom this for you JT
  2730. 2:11:56hyen group hyen one is my consumer group
  2731. 2:12:00ID right this particular consumer group
  2732. 2:12:04is assigned to all the three partition
  2733. 2:12:08can you see
  2734. 2:12:10here Java key demo 0o demo 1 demo 2 the
  2735. 2:12:14Java H demo is my topic name and
  2736. 2:12:17partition name happened with the number
  2737. 2:12:190 1 and two and all the three partition
  2738. 2:12:22of my topic is being assigned to single
  2739. 2:12:26consumer instance by specifying this
  2740. 2:12:29particular group ID so that is what the
  2741. 2:12:32first step we have discussed here a
  2742. 2:12:34single consumer instance is trying to
  2743. 2:12:36read from multiple partition this is the
  2744. 2:12:39happy scenario what we are trying now
  2745. 2:12:41lat will increase the consumer instance
  2746. 2:12:44and we'll see whether the each consumer
  2747. 2:12:46instance is pointing to each partition
  2748. 2:12:48or not that is the next step okay now
  2749. 2:12:50for now
  2750. 2:12:51you can read this particular statement
  2751. 2:12:54to understand this is the consumer
  2752. 2:12:56instance and this is the group ID is
  2753. 2:12:58being assigned to all three partition
  2754. 2:13:00that's fine let me clear this go to the
  2755. 2:13:03postman let me send the message it will
  2756. 2:13:06send 10,000 messages right it will
  2757. 2:13:09definitely take few
  2758. 2:13:11second message published successfully
  2759. 2:13:14and it take
  2760. 2:13:15157
  2761. 2:13:17millisecond and now let's check in our
  2762. 2:13:19consumer app can you see
  2763. 2:13:22here consumer consume the message user
  2764. 2:13:26this one I mean this is the
  2765. 2:13:28message this is the message and this is
  2766. 2:13:30my log statement consumer consume the
  2767. 2:13:33message this all the 10,000 messages is
  2768. 2:13:37being consumed okay now how you can see
  2769. 2:13:40that all the 10,000 messages what you
  2770. 2:13:42have published from producer is being
  2771. 2:13:44consumed by your consumer simply go to
  2772. 2:13:47your upset Explorer then refresh the
  2773. 2:13:50topic
  2774. 2:13:51you'll find the Java TI demo as a topic
  2775. 2:13:55now let me refresh
  2776. 2:13:56this let me yeah you can see here right
  2777. 2:14:00this is what our topic and this is what
  2778. 2:14:02the consumer group we have created now
  2779. 2:14:04first let's verify the data in topic so
  2780. 2:14:08just run
  2781. 2:14:10it now if you'll go and check in the
  2782. 2:14:13Java TI demo go inside the partition you
  2783. 2:14:17can verify each partition I mean getting
  2784. 2:14:20the messages
  2785. 2:14:21partition 0 received
  2786. 2:14:235,150 partition 1 received
  2787. 2:14:272346 partition 2 also received something
  2788. 2:14:302505 I mean all the three partition
  2789. 2:14:33received the messages okay now if you'll
  2790. 2:14:36go and check in the consumer group if I
  2791. 2:14:40will open the
  2792. 2:14:41offset can you see here the topic name
  2793. 2:14:44is Java demo and message received to all
  2794. 2:14:49the three partition 102 two okay and
  2795. 2:14:53count of each partition messages each
  2796. 2:14:56messages in Partition you can see here
  2797. 2:14:58partition one is this much zero is this
  2798. 2:15:01much and two is this much now upset is
  2799. 2:15:03the number of your
  2800. 2:15:05sequence now if You observe here lag is
  2801. 2:15:08zero now all the partition whatever the
  2802. 2:15:12messages they have received they are
  2803. 2:15:14able to deliver that messages to the
  2804. 2:15:16consumer I mean consumer successfully
  2805. 2:15:19read 23 6 messages from partition 1
  2806. 2:15:235,150 messages from partition 0
  2807. 2:15:27255 messages from partition two that is
  2808. 2:15:30the reason you can see the lag count is
  2809. 2:15:32zero there is no message is pending from
  2810. 2:15:35your producer side to consumed by your
  2811. 2:15:38consumer all the messages whatever your
  2812. 2:15:40producer is published is being consumed
  2813. 2:15:43by your consumer okay so by seeing this
  2814. 2:15:45lag number you can understand how many
  2815. 2:15:48messages your consumer is not received
  2816. 2:15:50okay this is what I always prefer to use
  2817. 2:15:53this offset Explorer because this will
  2818. 2:15:55give you the lag information okay that's
  2819. 2:15:57fine now what do you understand
  2820. 2:16:00partition 012 received all the messages
  2821. 2:16:03but we have only one consumer instance
  2822. 2:16:05who is listening to these three
  2823. 2:16:08partition now can we try creating three
  2824. 2:16:12consumer instance so that we'll verify
  2825. 2:16:15whether all the three instance is
  2826. 2:16:17pointing to individual partition or not
  2827. 2:16:19we'll do that right away let's go to the
  2828. 2:16:22code you can create a separate class and
  2829. 2:16:25Define the this particular Capa listener
  2830. 2:16:28and you can specify from which topic you
  2831. 2:16:31want it to read but we'll simply create
  2832. 2:16:35duplicate method to consume the messages
  2833. 2:16:37okay rather than create duplicate class
  2834. 2:16:40so I'll just copy the messages I'll will
  2835. 2:16:43create three consumer instance okay let
  2836. 2:16:45me Zoom this for you this is the second
  2837. 2:16:49one so I'll just Define 2 I'll Define
  2838. 2:16:54one now I created another one this this
  2839. 2:16:57is 1 2 3 right we have created three
  2840. 2:17:00consumer instance also as for the flow I
  2841. 2:17:03explained right if there is a fourth
  2842. 2:17:05consumer instance then what you'll do
  2843. 2:17:08because we have three partition all the
  2844. 2:17:09three partition will assign to each and
  2845. 2:17:11every consumer instance then what is the
  2846. 2:17:14role of consumer 4 we'll see that as
  2847. 2:17:16well okay so we'll create another
  2848. 2:17:19consumer instance for
  2849. 2:17:21backup so I'll name
  2850. 2:17:23it anything you can give consumer
  2851. 2:17:26consume four that's it now I'll just
  2852. 2:17:29change the log statement otherwise it is
  2853. 2:17:31difficult for us to filter out who
  2854. 2:17:33received the messages okay so I'll just
  2855. 2:17:36Define this is consumer 1 consumer 2
  2856. 2:17:40consumer
  2857. 2:17:423 and four that's it okay group ID
  2858. 2:17:47everything is same we have just created
  2859. 2:17:49multiple consumer instance
  2860. 2:17:51so we'll see messages will come to if
  2861. 2:17:54messages will come to two partition then
  2862. 2:17:57two consumer instance should read those
  2863. 2:18:00messages from the partition it can be
  2864. 2:18:03consumer one and consumer 2 or three and
  2865. 2:18:05four any order that is depends on the
  2866. 2:18:07Joe keeper coordinator this is not in
  2867. 2:18:09our hand that's fine so for safer side
  2868. 2:18:13what we'll do we'll just change the
  2869. 2:18:15topic name and group ID okay I'll change
  2870. 2:18:18it to the group J
  2871. 2:18:21group same I'll replace in all the
  2872. 2:18:27method also I'll change the topic
  2873. 2:18:30name same I need to do the change in my
  2874. 2:18:33producer as well right so producer will
  2875. 2:18:37publish the message
  2876. 2:18:38here and also in config right that's it
  2877. 2:18:43so we have created the same three
  2878. 2:18:44partition let me restart the
  2879. 2:18:48producer producer is up now let's go and
  2880. 2:18:51start our
  2881. 2:18:53consumer now if you see the statement
  2882. 2:18:56consumer is up and running three
  2883. 2:18:58individual consumer instance is being
  2884. 2:19:01assigned to individual partition you can
  2885. 2:19:04see here right our topic name Java demo
  2886. 2:19:07one hyphen 1 hyphen 2 Zer is nothing
  2887. 2:19:10your partition number and it is just
  2888. 2:19:12giving the group name because we don't
  2889. 2:19:14specify our consumer instance name all
  2890. 2:19:16the consumer instance we are wrapped
  2891. 2:19:18inside a group ID so you can see
  2892. 2:19:21instance one instance two and instance
  2893. 2:19:23three is pointing to three different
  2894. 2:19:26partition from the topic now let's
  2895. 2:19:28verify that right away okay clear
  2896. 2:19:31it I'll send the request now my producer
  2897. 2:19:35will publish 10,000 message to the topic
  2898. 2:19:37and the messages will distribute to
  2899. 2:19:40three different topic okay now then we
  2900. 2:19:43have three consumer instance we'll see
  2901. 2:19:45whether all the messages is being
  2902. 2:19:48distributed to individual uh partition
  2903. 2:19:50and and consumer instance combination or
  2904. 2:19:52not so go to the postman simply hit the
  2905. 2:19:57request it publish the 10,000 messages
  2906. 2:20:01first let's verify how many partition
  2907. 2:20:04received the messages okay then based on
  2908. 2:20:07that we'll validate our consumer
  2909. 2:20:08instance go and check here let me
  2910. 2:20:11refresh the topic also Let me refresh my
  2911. 2:20:14consumer we have the new consumer JT
  2912. 2:20:17group we'll verify here only okay
  2913. 2:20:21partition 1 2 0 all three partition
  2914. 2:20:24receive the messages there is no lag it
  2915. 2:20:26means there should be three consumer
  2916. 2:20:29instance log statement we can see okay
  2917. 2:20:33if you are not seeing three consumer
  2918. 2:20:34instance log then our concept is wrong
  2919. 2:20:37what we discuss is wrong okay so let's
  2920. 2:20:40verify it right away so how we can
  2921. 2:20:42filter it simple right that is the
  2922. 2:20:44reason I have changed the first
  2923. 2:20:46statement so I'll just filter here
  2924. 2:20:49consumer one
  2925. 2:20:51received
  2926. 2:20:532,445 messages now we'll see who else
  2927. 2:20:57received the messages does Consumer 2
  2928. 2:20:59received no consumer 3 yes consumer 3
  2929. 2:21:03received
  2930. 2:21:052371 okay now we'll see consumer 4 also
  2931. 2:21:08received something yeah
  2932. 2:21:112176 so what we cleared here we have
  2933. 2:21:14four instance consumer 1 2 3 4 consumer
  2934. 2:21:181 3 and four received the messages you
  2935. 2:21:20can see in four we can see some messages
  2936. 2:21:23right and the count you can see here now
  2937. 2:21:25if you change it to the
  2938. 2:21:27three consumer three three also receive
  2939. 2:21:32the messages right now if you change it
  2940. 2:21:34to the one one also receive the messages
  2941. 2:21:37but two consumer is not receive the
  2942. 2:21:40messages okay consumer 1 three and four
  2943. 2:21:43only these three consumer instance
  2944. 2:21:45receive the messages not this
  2945. 2:21:48guy why simple statement right we have
  2946. 2:21:52three partition that is the reason it
  2947. 2:21:53assigned to the three consumer instance
  2948. 2:21:56one consumer instance two consumer
  2949. 2:21:59instance three consumer instance if
  2950. 2:22:02message is being pushed to only two
  2951. 2:22:05partition let's say uh partition one and
  2952. 2:22:08partition two then only two consumer
  2953. 2:22:11instance will print the statement that
  2954. 2:22:13is how the capka maintain the balance
  2955. 2:22:16between the partition and consumer
  2956. 2:22:18instance okay now what I'll do the order
  2957. 2:22:21is not same right now this time consumer
  2958. 2:22:23two didn't receive the messages but
  2959. 2:22:24there is no guarantee that when the
  2960. 2:22:26message will come next time consumer 2 3
  2961. 2:22:294 or 1 2 3 like that anyone can receiv
  2962. 2:22:32it okay we'll just verify it right
  2963. 2:22:35away now I'll again send 10,000
  2964. 2:22:40messages fine now we'll see who all
  2965. 2:22:43received the messages consumer 3
  2966. 2:22:46received the
  2967. 2:22:48messages fine consumer 2 no it didn't
  2968. 2:22:52receive consumer one receive consumer 4
  2969. 2:22:54receive okay if you'll try many times
  2970. 2:22:57there might be you can see the change in
  2971. 2:23:00order okay it can be 1 2 3 or 3 to 1 any
  2972. 2:23:03any order we can't predict it it will be
  2973. 2:23:05decided by
  2974. 2:23:07coordinator that's fine so I believe
  2975. 2:23:10you're pretty clear with this concept
  2976. 2:23:12okay number of partition we have number
  2977. 2:23:14of consumer instance make the mapping
  2978. 2:23:17and get the messages that is the simple
  2979. 2:23:20statement
  2980. 2:23:21okay but just keep a note in real time
  2981. 2:23:24you should not write multiple consumer
  2982. 2:23:27instance like this okay so this is just
  2983. 2:23:30I give you the demo to give the clear
  2984. 2:23:34picture about this partition and
  2985. 2:23:36consumer instance mapping in real time
  2986. 2:23:39you can make it in a better way by
  2987. 2:23:40implementing the concurrency so you can
  2988. 2:23:43design or you can increase the
  2989. 2:23:44throughput of your application okay just
  2990. 2:23:47keep a note again this is just for the
  2991. 2:23:49demo purpose so you should not write the
  2992. 2:23:51code like this in your consumer that's
  2993. 2:23:54fine now let's understand if I have
  2994. 2:23:58published 10,000 message to the topic
  2995. 2:24:01whether all the messages is being
  2996. 2:24:03consumed by my consumer or not let's say
  2997. 2:24:05producer publish the 10,000 messages but
  2998. 2:24:08in between my capka consumer is shut
  2999. 2:24:11down then that time how can I verify
  3000. 2:24:14that how many messages my consumer
  3001. 2:24:17received or how many messages he didn't
  3002. 2:24:19received that is what the lag we just
  3003. 2:24:21discuss now right but let's prove it I
  3004. 2:24:24mean we'll forcefully stop our capka
  3005. 2:24:26consumer and we'll validate how the lag
  3006. 2:24:29show the exact Behavior or not okay or
  3007. 2:24:32whether it shows the exact number or not
  3008. 2:24:34fine so what I'll do I'll just open my
  3009. 2:24:38Postman so I'll I'll keep this in two
  3010. 2:24:44different uh section so that I can
  3011. 2:24:47quickly stop my
  3012. 2:24:49consumer
  3013. 2:24:51Okay cool so let me clear
  3014. 2:24:54everything I'll send the request then
  3015. 2:24:58immediately I will stop
  3016. 2:25:00it I don't know how many messages is
  3017. 2:25:02being published because from the
  3018. 2:25:04producer we have published the 10,000
  3019. 2:25:06messages okay so the topic name is also
  3020. 2:25:09same let's verify it right away go to
  3021. 2:25:11the upset
  3022. 2:25:14Explorer just reconnect
  3023. 2:25:17it open the topic just Java tiet demo
  3024. 2:25:22one go into the partition but it won't
  3025. 2:25:24give you any clue here if you look into
  3026. 2:25:26the topic better you go to the
  3027. 2:25:29consumer there is no lag because we not
  3028. 2:25:33able to shut down immediately okay so
  3029. 2:25:37what I'll do I'll publish more messages
  3030. 2:25:40so that I will get enough time to shut
  3031. 2:25:42down my consumer so I'll go to my
  3032. 2:25:44producer
  3033. 2:25:46application then this is how many 10,000
  3034. 2:25:49right I will send
  3035. 2:25:50one L messages and also I'll just change
  3036. 2:25:54my topic
  3037. 2:25:56name uh go to the config here okay we
  3038. 2:26:00did change in config change this topic
  3039. 2:26:02name now go to your consumer
  3040. 2:26:06code I mean meanwhile let me start my
  3041. 2:26:09producer right we have did the changes
  3042. 2:26:12just restart it I'll go to the
  3043. 2:26:16consumer in consumer also you need to
  3044. 2:26:19change the topic name
  3045. 2:26:22uh let's say two only right and I'll
  3046. 2:26:25change the group J group hyphen
  3047. 2:26:30new let me specify in all the
  3048. 2:26:35instance fine we have changed the
  3049. 2:26:38consumer group and we have changed the
  3050. 2:26:40topic name in both producer and consumer
  3051. 2:26:42and we start our producer now let me
  3052. 2:26:44start my
  3053. 2:26:48consumer okay consumer is up and running
  3054. 2:26:51let me clear
  3055. 2:26:54everything let me send the request now
  3056. 2:26:57now it will send one lakh record to the
  3057. 2:26:59capka okay now send the request and
  3058. 2:27:03meanwhile I will stop
  3059. 2:27:06it I'm able to stop or not I'm not sure
  3060. 2:27:09but I've have tried it but let's
  3061. 2:27:11see I will just reconnect it okay so
  3062. 2:27:15that it will refresh
  3063. 2:27:17everything go to the topic this is the
  3064. 2:27:20topic newly we created right go to the
  3065. 2:27:23consumer J group new is there yeah we
  3066. 2:27:26are able to deliver it Java demo
  3067. 2:27:302 can you see
  3068. 2:27:32here not don't don't verify the demo one
  3069. 2:27:35this is the recent topic we created in
  3070. 2:27:37demo 2 partition one it received
  3071. 2:27:4132358 messages and only 976 message is
  3072. 2:27:47being consumed by your consumer that is
  3073. 2:27:49the reason you are able to to see the
  3074. 2:27:50upset count rest
  3075. 2:27:5331382 message is not being consumed by
  3076. 2:27:56your consumer okay you won't find those
  3077. 2:27:59messages in your consumer section okay
  3078. 2:28:02now if you'll see the partition zero it
  3079. 2:28:06received
  3080. 2:28:073276 messages it was able to deliver
  3081. 2:28:103,217 messages 29
  3082. 2:28:149,549 messages is not being consumed
  3083. 2:28:17producer is able to publish the messages
  3084. 2:28:19but but somehow your consumer is shut
  3085. 2:28:21down that time so he is not able to
  3086. 2:28:23receive those messages okay now you can
  3087. 2:28:26easily identify right which partition is
  3088. 2:28:29don't I mean which partition messages is
  3089. 2:28:32not being consumed by your consumer so
  3090. 2:28:35in real time in production issue you
  3091. 2:28:37might need to republish your messages or
  3092. 2:28:39you need to publish your messages again
  3093. 2:28:41to resolve such kind of issue so if you
  3094. 2:28:43have this tool at least you can figure
  3095. 2:28:45out right the number of messages in
  3096. 2:28:47which partition okay that will give you
  3097. 2:28:50the clue and you can publish the
  3098. 2:28:52messages from that specific partition
  3099. 2:28:54okay and you can see here partition
  3100. 2:28:57two 34,000 messages he received but he
  3101. 2:29:01only published
  3102. 2:29:033,257 because these are the messages is
  3103. 2:29:05being consumed by consumer 31620 is not
  3104. 2:29:09consumed okay so this is how you can
  3105. 2:29:12figure out the lag in your producer and
  3106. 2:29:14consumer so it will make your job easier
  3107. 2:29:17or it will give you the better
  3108. 2:29:18productivity while analyzing the issue
  3109. 2:29:21on capka okay don't worry I will also
  3110. 2:29:24tell you in my upcoming tutorial how you
  3111. 2:29:26can retrive a specific messages from the
  3112. 2:29:29partition we'll go in deeper okay with
  3113. 2:29:32the code in my upcoming session so I
  3114. 2:29:34hope you are clear about the consumer
  3115. 2:29:37and consumer instance and partition
  3116. 2:29:39mapping and how to verify the lag in the
  3117. 2:29:43upset Explorer
  3118. 2:29:49two
  3119. 2:29:52[Music]
  3120. 2:29:53in the previous capka tutorial we
  3121. 2:29:55understood the complete capka pops up
  3122. 2:29:57mechanism right where we publish the
  3123. 2:29:59plan string message to the topic and
  3124. 2:30:01from the topic our consumer application
  3125. 2:30:03consumed it even we Deep dive more to
  3126. 2:30:06understand partition and consumer group
  3127. 2:30:08mapping with examples but the pop sub
  3128. 2:30:11system which we designed will it accept
  3129. 2:30:14any data type to publish and consume the
  3130. 2:30:16event the answer is big no let's prove
  3131. 2:30:19it right away then we'll find out a
  3132. 2:30:21solution for it okay so to verify this
  3133. 2:30:24Behavior instead of sending the string
  3134. 2:30:26message to the topic and consumed it
  3135. 2:30:28let's send some object or let's create
  3136. 2:30:31some pujo class which we want to send to
  3137. 2:30:33the capka topic and we want that PUO
  3138. 2:30:36need to be consumed by my consumer so
  3139. 2:30:38for that what I'll do I'll simply create
  3140. 2:30:40a new
  3141. 2:30:42package dto now I'll create some class
  3142. 2:30:45here let's say customer
  3143. 2:30:47class now let's define couple of
  3144. 2:30:57fi so we have defined ID name email and
  3145. 2:31:00contact number so we added the lbook
  3146. 2:31:03right so I can use theate data
  3147. 2:31:05annotation to avoid okay we have not
  3148. 2:31:08added the lumbo no is go to your pom.xml
  3149. 2:31:12and then you can add the lbook
  3150. 2:31:15dependency just update it that's it now
  3151. 2:31:19we can input this statement so we don't
  3152. 2:31:21need to write the getter and Setter
  3153. 2:31:22because we already added the at theate
  3154. 2:31:24data annotation that's fine now I want
  3155. 2:31:27to send this customer object to the
  3156. 2:31:29capka topic from the producer and I want
  3157. 2:31:32this customer object need to be consumed
  3158. 2:31:34by my consumer application so let's do
  3159. 2:31:37that go to the publisher where exactly
  3160. 2:31:40we are publishing the message so let me
  3161. 2:31:43go to that
  3162. 2:31:45class we have defined the publisher
  3163. 2:31:47right so I don't want to touch the
  3164. 2:31:49existing in code let it be I'll create a
  3165. 2:31:52new
  3166. 2:31:54method so I'll name
  3167. 2:31:56it let's say send events to
  3168. 2:32:01topic and here I don't want to send the
  3169. 2:32:04message I want to send the object which
  3170. 2:32:07is
  3171. 2:32:09customer fine now everywhere I need to
  3172. 2:32:13change
  3173. 2:32:16it fine so I will also change thep toic
  3174. 2:32:20name that will do later now let me send
  3175. 2:32:23the object so this is the exact place
  3176. 2:32:27where we are sending the object okay
  3177. 2:32:30earlier we are sending the string
  3178. 2:32:31message now we are sending one custom
  3179. 2:32:33object which is customer that's fine now
  3180. 2:32:36we'll call this method from our
  3181. 2:32:38controller go to the controller
  3182. 2:32:41class then simply write another endpoint
  3183. 2:32:45so I'll write something
  3184. 2:32:46like
  3185. 2:32:48public
  3186. 2:32:50void send events okay and what type of
  3187. 2:32:55event I want to send customer
  3188. 2:32:58object now simply I can call Publisher
  3189. 2:33:01dot send events to the topic and
  3190. 2:33:05customer and I need to Define this as a
  3191. 2:33:07endpoint so what I'll do I'll just
  3192. 2:33:10Define post mapping because I want to
  3193. 2:33:13send the object from the postman and I
  3194. 2:33:15need to annotate this at theate request
  3195. 2:33:18body that's it I need to define the URL
  3196. 2:33:22here
  3197. 2:33:24publish okay so what we are doing here
  3198. 2:33:27from the postman we'll send the customer
  3199. 2:33:29object in the form of Json and then we
  3200. 2:33:32are giving that to the capka template to
  3201. 2:33:34send this particular customer object to
  3202. 2:33:36this given topic okay so what we'll do
  3203. 2:33:39we'll also change the topic name so go
  3204. 2:33:42to the config this is the place where we
  3205. 2:33:44are creating the topic I'll name it Java
  3206. 2:33:47demo and go to the controller class not
  3207. 2:33:50controller go to the publisher
  3208. 2:33:53class there also we need to change the
  3209. 2:33:56topic name so you want to send the
  3210. 2:33:58customer object to this particular Java
  3211. 2:34:01demo topic okay now once we send it to
  3212. 2:34:05the topic who will consume it our
  3213. 2:34:07consumer now also we need to tell to the
  3214. 2:34:10consumer hey consumer please consume
  3215. 2:34:13customer object instead of string right
  3216. 2:34:16so I also need to do the code change in
  3217. 2:34:18my consumer so go to the consumer
  3218. 2:34:20application first let me copy this dto
  3219. 2:34:25class in consumer also you need to tell
  3220. 2:34:28right what need to be consumed so what
  3221. 2:34:31I'll do I will also comment all the
  3222. 2:34:33consumer group related Stu this is my
  3223. 2:34:37consumer he will point to the Java key
  3224. 2:34:39demo what what I have defined just now
  3225. 2:34:41in my producer and instead of string
  3226. 2:34:44message we we need to tell to this
  3227. 2:34:46consumer please consume the object
  3228. 2:34:49object which is customer what data type
  3229. 2:34:52you need to consume you can specify here
  3230. 2:34:55okay so I'll change the method name to
  3231. 2:34:57consume so it is crying because we don't
  3232. 2:34:59have the customer class in this
  3233. 2:35:01particular project so rather than keep
  3234. 2:35:03the same class in both producer and
  3235. 2:35:05consumer application you can create a
  3236. 2:35:07multimodule project and you can create a
  3237. 2:35:09common module and you can keep all the
  3238. 2:35:12common dto or PUO class okay but for
  3239. 2:35:15this demo purpose I'm just adding
  3240. 2:35:18it so you have added the customer again
  3241. 2:35:21we don't have the lbook dependency here
  3242. 2:35:23so just go to the
  3243. 2:35:24producer and copy the lbook
  3244. 2:35:29dependency then simply go to
  3245. 2:35:32the consumer pom.xml and paste
  3246. 2:35:35it all good go to The
  3247. 2:35:38Listener and just input the
  3248. 2:35:41statement so I will just print your
  3249. 2:35:44customer dot two string I just want to
  3250. 2:35:47print it the plain string okay
  3251. 2:35:50okay consumer consume the
  3252. 2:35:55events fine we are also specifying the
  3253. 2:35:58topic name and group ID so group ID you
  3254. 2:36:01can give any
  3255. 2:36:02name that's
  3256. 2:36:04it just go to the producer one
  3257. 2:36:08again let me verify we have defined this
  3258. 2:36:12right also what I want to do I'll keep
  3259. 2:36:14this in TR catch so that if there is any
  3260. 2:36:16exception while publishing the event we
  3261. 2:36:19can easily catch
  3262. 2:36:22it just add another bracket that's it so
  3263. 2:36:25here what I do I just print it see out
  3264. 2:36:29let's say
  3265. 2:36:30error and what is the error message we
  3266. 2:36:33got if there is
  3267. 2:36:35any get
  3268. 2:36:37message that's it right so I have
  3269. 2:36:39started my juke keeper and capka server
  3270. 2:36:42that is the first step you need to do
  3271. 2:36:44before you start your application now we
  3272. 2:36:46are all good let's run our application
  3273. 2:36:48so let me start the producer
  3274. 2:36:52app once it will up then I will quickly
  3275. 2:36:54start my consumer
  3276. 2:36:57app so producer is up on put 9191 go to
  3277. 2:37:01the consumer and just start
  3278. 2:37:07it so it is up and running also it
  3279. 2:37:10clearly says that the group ID what you
  3280. 2:37:12have created is being assigned to the
  3281. 2:37:14topic of three partition 012 because we
  3282. 2:37:18are creating Java demo
  3283. 2:37:20topic with three partition that is what
  3284. 2:37:21we have written in our cavka config
  3285. 2:37:23that's fine let me clear this this is my
  3286. 2:37:27consumer right and go to the producer
  3287. 2:37:30let me clear the console fine now what
  3288. 2:37:33Endo we need to trigger this particular
  3289. 2:37:36endpoint SLP publish and you need to
  3290. 2:37:38give the customer as a Json so I'll go
  3291. 2:37:41to the
  3292. 2:37:42postman let me check the
  3293. 2:37:46endpoint producer of this is are the
  3294. 2:37:50producer app and publish so I will send
  3295. 2:37:53the customer object ID name email and
  3296. 2:37:56contact number now let me send this
  3297. 2:37:59object to the from the producer app to
  3298. 2:38:02the topic let's see what is the result
  3299. 2:38:03we are getting status is
  3300. 2:38:0620 let's see what if there is any
  3301. 2:38:10error can you see here we are getting
  3302. 2:38:14the error here can't convert value of
  3303. 2:38:18class this D customer to Apachi kapka
  3304. 2:38:21common serial serialization string
  3305. 2:38:24serializer specified in value
  3306. 2:38:26serializer what it says usually when we
  3307. 2:38:29are sending the messages to the topic it
  3308. 2:38:33will always accept bite AR as a input
  3309. 2:38:36because we are serializing the object we
  3310. 2:38:38are sending the object over the network
  3311. 2:38:40to whom topic so if you look into the
  3312. 2:38:44presentation from the producer to the
  3313. 2:38:46topic we are serializing the data okay
  3314. 2:38:49in the form of object or in the form of
  3315. 2:38:51Json but in the consumer perspective we
  3316. 2:38:55are deserializing the data from producer
  3317. 2:38:58which we are sending the bite array over
  3318. 2:39:00the network to the topic and in consumer
  3319. 2:39:03it consumes the bite array from the
  3320. 2:39:05topic so this is the part of
  3321. 2:39:07serialization and deserialization
  3322. 2:39:09concept basic core Java if some object
  3323. 2:39:12you'll send over the network that must
  3324. 2:39:14need to be serialized and if you'll read
  3325. 2:39:17that particular object then that must
  3326. 2:39:19need to be that that concept is called
  3327. 2:39:21der serialize right that is what exactly
  3328. 2:39:23you are doing producer is serializing
  3329. 2:39:26the object to the topic and consumer is
  3330. 2:39:28dis realizing the object from the topic
  3331. 2:39:31so that is the reason we are getting the
  3332. 2:39:33error here because Capa looking for bite
  3333. 2:39:36array to be input so that is the reason
  3334. 2:39:38we can happily play with the string
  3335. 2:39:40without adding any configuration if
  3336. 2:39:42you'll send any string that will be
  3337. 2:39:44converted to the bite array and will
  3338. 2:39:46publish to the topic and consumer can
  3339. 2:39:48consume that bite array can convert it
  3340. 2:39:50to the string but if you want to play
  3341. 2:39:52with the different type of object then
  3342. 2:39:54you need to tell to the capka hey capka
  3343. 2:39:58while doing the serialization please use
  3344. 2:40:00this serializer or in the consumer you
  3345. 2:40:03can tell him hey consumer while
  3346. 2:40:06deserializing that particular object
  3347. 2:40:08please use the deserializer what I am
  3348. 2:40:10giving to you tell that I'm sending the
  3349. 2:40:13customer object please serialize it and
  3350. 2:40:15consumer need to tell to the capka hey I
  3351. 2:40:18am expecting consumer object please
  3352. 2:40:20derealize it now how you can tell to the
  3353. 2:40:22capka very simple just go to the
  3354. 2:40:25application. IML
  3355. 2:40:26file you need to mention in both
  3356. 2:40:29producer and consumer because from the
  3357. 2:40:31producer you are serializing the data
  3358. 2:40:34and from the consumer you are
  3359. 2:40:35deserializing the data okay so go to the
  3360. 2:40:38resource application. IML let me Zoom
  3361. 2:40:41this for
  3362. 2:40:42you now here you can tell him hey capka
  3363. 2:40:48please use this is key serializer and
  3364. 2:40:51what is the key serializer I'm sending
  3365. 2:40:53the key in the form of string so use
  3366. 2:40:56this string serializer to just convert
  3367. 2:40:59the key okay and for Value serializer
  3368. 2:41:03use the Json
  3369. 2:41:05serializer just specify that very simple
  3370. 2:41:09so I'm sending the key in the form of
  3371. 2:41:11string you just play with the string
  3372. 2:41:13serializer but the value what I'm
  3373. 2:41:16sending the customer object for that
  3374. 2:41:18please you use this Json serializer
  3375. 2:41:21because I'm sending in the form of Json
  3376. 2:41:23you please take that Json and send it to
  3377. 2:41:25the topic okay and now same thing you
  3378. 2:41:28need to tell in your consumer also so go
  3379. 2:41:31to the
  3380. 2:41:33consumer go to the application.
  3381. 2:41:37yl now here in the consumer also you
  3382. 2:41:40need to tell him what is your key
  3383. 2:41:42deserializer see the word here see the
  3384. 2:41:44key here in consumer we are
  3385. 2:41:47deserializing the data right so that is
  3386. 2:41:49the region key dis realizer what is the
  3387. 2:41:51key dis realizer that is the same string
  3388. 2:41:54string dis realizer right so just Define
  3389. 2:41:58it now what is the value D realizer same
  3390. 2:42:02Json D realizer just Define that can you
  3391. 2:42:06see here key serializer key der
  3392. 2:42:08serializer is the string deserializer
  3393. 2:42:10and value der serializer is the Json D
  3394. 2:42:13realizer because we are not giving any
  3395. 2:42:15key as per our example okay we are
  3396. 2:42:17playing with the value so it's fine you
  3397. 2:42:19can keep string serializer and der
  3398. 2:42:21serializer as a key for now but you're
  3399. 2:42:24are sending the object so serializer and
  3400. 2:42:26deserializer must be Json one because we
  3401. 2:42:29sending the object in the form of Json
  3402. 2:42:32fine all good now let's run our producer
  3403. 2:42:35and consumer to verify whether the way
  3404. 2:42:38we have configured for the object it is
  3405. 2:42:40working or not my capka is able to
  3406. 2:42:43publish the object to the topic and my
  3407. 2:42:45consumer is consume that object from the
  3408. 2:42:47topic or not okay so very simple just
  3409. 2:42:50restart go to the producer first restart
  3410. 2:42:54it then go to the
  3411. 2:42:57consumer here also you can simply
  3412. 2:42:59restart
  3413. 2:43:01it both producer and consumer is up and
  3414. 2:43:04running you can see here this is the
  3415. 2:43:06consumer let me clear the console go to
  3416. 2:43:09the producer let me clear the
  3417. 2:43:11console that's fine now let me send the
  3418. 2:43:14request
  3419. 2:43:17okay they're getting status code 20 and
  3420. 2:43:21then let's see whether is there any
  3421. 2:43:24error there is no error from the
  3422. 2:43:26producer producer successfully send this
  3423. 2:43:29particular object you can see here okay
  3424. 2:43:31because we are just printing the two
  3425. 2:43:33string now let's verify in the
  3426. 2:43:36consumer there is a exception in
  3427. 2:43:38consumer let me stop it
  3428. 2:43:41now let's see what is the error we are
  3429. 2:43:44getting from the consumer okay the class
  3430. 2:43:47com. java. d.com customer is not the
  3431. 2:43:51trusted package Java util Java Lang if
  3432. 2:43:54you believe this class is safe to dis
  3433. 2:43:56realize please provide its name if the
  3434. 2:44:00if the serialization is only done by a
  3435. 2:44:02trusted trusted Source you can also
  3436. 2:44:04enable trust all okay so very simple
  3437. 2:44:07okay the exception it clearly says that
  3438. 2:44:10the D what you are sending or what your
  3439. 2:44:14consumer is trying to consume is not a
  3440. 2:44:16trusted package so you need to tell to
  3441. 2:44:18the
  3442. 2:44:19hey if you're getting any object from
  3443. 2:44:22this particular package please accept it
  3444. 2:44:25please listen to it okay that is what
  3445. 2:44:28you can Define so just mention that in
  3446. 2:44:31our yl file so what I'll do I will tell
  3447. 2:44:34here
  3448. 2:44:36properties
  3449. 2:44:38spring
  3450. 2:44:41Json fine
  3451. 2:44:44trusted and specify the packages which
  3452. 2:44:48packages you trusted to use or you are
  3453. 2:44:50allowing your consumer to read that so
  3454. 2:44:53what you can do for now our package is
  3455. 2:44:56come.
  3456. 2:44:58java. dto if you want to include any
  3457. 2:45:02kind of package just Define the star
  3458. 2:45:05instead of specify the single package
  3459. 2:45:07name okay com. java. dto now let me
  3460. 2:45:11restart the consumer producer is up and
  3461. 2:45:13running he is able to publish the
  3462. 2:45:15message there is no error but consumer
  3463. 2:45:18was crying so if fixed it let's see
  3464. 2:45:20whether it is able to consume or not
  3465. 2:45:21yeah can you see
  3466. 2:45:23here now my consumer consume the
  3467. 2:45:27previous event which is the object this
  3468. 2:45:30is what we have sent right now to cross
  3469. 2:45:33verify it let me clear this let me clear
  3470. 2:45:37the producer as well and then what you
  3471. 2:45:40can do let me publish some different
  3472. 2:45:42event
  3473. 2:45:46okay fine let me send the request
  3474. 2:45:50go to the
  3475. 2:45:52producer producer send the messages to
  3476. 2:45:56the topic now go to the
  3477. 2:45:59consumer can you see here consumer
  3478. 2:46:02consume the event this is what just now
  3479. 2:46:04we sent
  3480. 2:46:05right we're able to consume it fine all
  3481. 2:46:10good we are able to play with the object
  3482. 2:46:12from the producer to the consumer but is
  3483. 2:46:16there the only one way to play with the
  3484. 2:46:18object object by defining just the
  3485. 2:46:20serializer and deserializer in
  3486. 2:46:22application. IML file no you can
  3487. 2:46:26customize that by defining your Java Bas
  3488. 2:46:28config class okay rather than add the
  3489. 2:46:31key and value or whatever the properties
  3490. 2:46:34in the application.yml file still you
  3491. 2:46:36have option to go with the Java Bas
  3492. 2:46:38configuration if you want to do any
  3493. 2:46:40customization okay I will also show you
  3494. 2:46:42that part how you can go with the Java
  3495. 2:46:45base configuration first let me comment
  3496. 2:46:48this piece of code because we are not
  3497. 2:46:49going to use the application. IML
  3498. 2:46:52configuration we want to write our own
  3499. 2:46:54Java base configuration go to the
  3500. 2:46:56producer as
  3501. 2:46:58well let me not all actually these
  3502. 2:47:02things fine now go to the config class
  3503. 2:47:07which is Capa producer config and then
  3504. 2:47:09here you can Define your own
  3505. 2:47:11configuration when I say own
  3506. 2:47:13configuration whatever the things key
  3507. 2:47:16and value you have defined in this
  3508. 2:47:18application IML same things you need to
  3509. 2:47:21configure in the Java code I mean you
  3510. 2:47:23need to create a bin of it okay so I'll
  3511. 2:47:26show you how we can do
  3512. 2:47:28that so first create a producer config
  3513. 2:47:31map so
  3514. 2:47:34public map of
  3515. 2:47:37string
  3516. 2:47:40object now create a object of
  3517. 2:47:44map now all the key whatever we have
  3518. 2:47:47defined in application. yml
  3519. 2:47:49that needs to be configured here so you
  3520. 2:47:51can Define like this okay producer
  3521. 2:47:54config what is the bootstrap server
  3522. 2:47:56Local Host 9092 what is your key
  3523. 2:47:58serializer what is your value serializer
  3524. 2:48:01so you just need to Define this at the
  3525. 2:48:05r bin fine now by giving this producer
  3526. 2:48:10config you can create producer Factory
  3527. 2:48:12object so
  3528. 2:48:17public now simply you can return return
  3529. 2:48:19here new default Capa producer Factory
  3530. 2:48:23and you need to give this config
  3531. 2:48:25whatever you have Define about your um
  3532. 2:48:28capka server serializer all the things
  3533. 2:48:31okay so just Define that
  3534. 2:48:33config and annotate this at theate
  3535. 2:48:36bin now again you need to create capka
  3536. 2:48:39template object by giving this producer
  3537. 2:48:41Factory now your capka template will
  3538. 2:48:43have all the information okay because
  3539. 2:48:45he's not going to read from yml he is
  3540. 2:48:48going to read from this config map so
  3541. 2:48:50let me create
  3542. 2:48:55it just Define this at theate bin that's
  3543. 2:48:59it okay so we Define the config map
  3544. 2:49:02where you have defined all the K and
  3545. 2:49:03value then we created the producer
  3546. 2:49:05Factory and then we give that producer
  3547. 2:49:08Factory to the capka template now same
  3548. 2:49:11things you need to write in your
  3549. 2:49:13consumer as well in consumer also you
  3550. 2:49:15can specify the consumer config map by
  3551. 2:49:18defining all the D realizer property and
  3552. 2:49:21all the bootstrap server related
  3553. 2:49:23properties okay so that is also
  3554. 2:49:25straightforward what is the error
  3555. 2:49:28here missing return statement okay I
  3556. 2:49:31need to return that map
  3557. 2:49:35object fine now go to the consumer and
  3558. 2:49:38do the same kind of configuration so go
  3559. 2:49:41to the consumer
  3560. 2:49:43app we already commented all the key and
  3561. 2:49:46value from the application.
  3562. 2:49:49now what I do I will create a new
  3563. 2:49:51package then quickly create a
  3564. 2:49:56class fine just annotate this at theate
  3565. 2:50:01configuration now again here also I need
  3566. 2:50:03to define a consumer config map by
  3567. 2:50:06defining all the key and value key key
  3568. 2:50:09dis realizer value dis realizer trusted
  3569. 2:50:11packages bootstrap server group ID
  3570. 2:50:14everything you can configure here okay
  3571. 2:50:16so just go to the config
  3572. 2:50:19class just Define a
  3573. 2:50:25bin now you can create the object of a
  3574. 2:50:29map now you can Define all the key and
  3575. 2:50:31value so name it
  3576. 2:50:34props then just
  3577. 2:50:38Define all the value
  3578. 2:50:42okay so we have defined Bop server key D
  3579. 2:50:46serializer value d serializer and
  3580. 2:50:48trusted package so IED this atate
  3581. 2:50:52bin next you need to define a consumer
  3582. 2:50:55Factory by giving this consumer config
  3583. 2:50:58so quickly create that class
  3584. 2:51:02public now return new
  3585. 2:51:06default capka consumer Factory and
  3586. 2:51:09Define the config which is nothing
  3587. 2:51:11consumer
  3588. 2:51:13config fine Define this at the
  3589. 2:51:17bin now you just need to define the
  3590. 2:51:20container Factory Capal listener
  3591. 2:51:22container Factory okay so just Define
  3592. 2:51:26that Capa listener container Factory and
  3593. 2:51:30we are creating the object of it and we
  3594. 2:51:31are giving the consumer Factory here
  3595. 2:51:34okay this is the simple way we are
  3596. 2:51:36creating the consumer config consumer
  3597. 2:51:38Factory and consumer listener okay or
  3598. 2:51:41Capa listener so the advantages of using
  3599. 2:51:44this Java base config if your
  3600. 2:51:46application is straightforward you don't
  3601. 2:51:48want to do any customization then you
  3602. 2:51:51can happily go with the application. yl
  3603. 2:51:53file okay but for example let's say you
  3604. 2:51:55want to access a secured Capa cluster
  3605. 2:51:58which will be https okay then in that
  3606. 2:52:01case you need to Define all the
  3607. 2:52:02certificate and all in your producer
  3608. 2:52:05config place okay you need to define the
  3609. 2:52:08uh all the SSL related information in
  3610. 2:52:10the config class you you need to
  3611. 2:52:13manually configure them but that you
  3612. 2:52:14cannot do using the application. yl file
  3613. 2:52:17okay but if you check in the consumer
  3614. 2:52:19there also if you want to set the
  3615. 2:52:21concurrency label for your consumer that
  3616. 2:52:24you can configure here in this listener
  3617. 2:52:26container Factory that things cannot be
  3618. 2:52:28done using the application. yml file so
  3619. 2:52:31it's pretty simple if your approach is
  3620. 2:52:33straightforward just to push the event
  3621. 2:52:36to the topic and consume it without any
  3622. 2:52:38customization you can go with the
  3623. 2:52:40application. IML file but if you want
  3624. 2:52:42any customization then you can go with
  3625. 2:52:45the Java base config approach okay so
  3626. 2:52:47all good now what I'll do I'll just
  3627. 2:52:50restart both producer and
  3628. 2:52:54consumer so it seems application is up
  3629. 2:52:57and running you can see here the
  3630. 2:52:58consumer this is the group assign to the
  3631. 2:53:01three different partition let's see the
  3632. 2:53:03producer yeah producer is up and running
  3633. 2:53:06let me clear
  3634. 2:53:08everything from the consumer clear
  3635. 2:53:10everything now we comment out all the
  3636. 2:53:14application. imlb configuration and
  3637. 2:53:16rather we created our own Java config
  3638. 2:53:19right so I'll go to the postman I'll
  3639. 2:53:22change something 1 2 3 name
  3640. 2:53:27John some number okay now let me send
  3641. 2:53:30the
  3642. 2:53:31request status code 20 go to the
  3643. 2:53:36producer can you see here producer is
  3644. 2:53:39able to publish the message this is what
  3645. 2:53:41the messages now let's verify whether
  3646. 2:53:44consumer is consumed it or
  3647. 2:53:46not yeah can you see here consumer
  3648. 2:53:50consume the event customer ID 1 2 3 name
  3649. 2:53:52John email is this contact number is
  3650. 2:53:55this okay so this is how you can play
  3651. 2:53:58with the object in capka I mean you can
  3652. 2:54:01serialize and deserialize any type of
  3653. 2:54:03object in the form of Json using the
  3654. 2:54:06springboard capka okay so I already
  3655. 2:54:08explained both the approach application.
  3656. 2:54:10IML and Java base config so just choose
  3657. 2:54:13them based on your
  3658. 2:54:17need
  3659. 2:54:21so we'll start with brushing of capka
  3660. 2:54:23internal workflow and then we'll move
  3661. 2:54:25into the capka partitioning
  3662. 2:54:27demonstration okay so in capka ecosystem
  3663. 2:54:30once producer send bulk messages it will
  3664. 2:54:33split into different partition okay so
  3665. 2:54:36let's say I have sent thousand of
  3666. 2:54:37messages then each and every message
  3667. 2:54:40can't be guaranteed that it will go to
  3668. 2:54:42the same partition it will go to the
  3669. 2:54:44multiple partition the number of
  3670. 2:54:46partition we have in our broker
  3671. 2:54:48similarly consumer will consume from all
  3672. 2:54:50the partition so this is the typical C
  3673. 2:54:53cup of sub mechanism right now how you
  3674. 2:54:56can ensure your message go exactly where
  3675. 2:54:58you want them to go maybe you want to
  3676. 2:55:01optimize the data processing or improve
  3677. 2:55:03load balancing then how you can control
  3678. 2:55:05that I want my producer will send all
  3679. 2:55:09the messages to a single partition and
  3680. 2:55:11say I want my consumer to read from a
  3681. 2:55:14single partition how you can make the
  3682. 2:55:17control on this partition
  3683. 2:55:19that is what I'm going to demonstrate in
  3684. 2:55:20this video so this is the capka producer
  3685. 2:55:22example and here we have the capka
  3686. 2:55:24consumer example this is what the
  3687. 2:55:26example we are starting learning from
  3688. 2:55:28the capka series beginning right I'm
  3689. 2:55:31taking the same example to just
  3690. 2:55:33demonstrate on this Capa partitioning
  3691. 2:55:36okay so what we'll do first I will
  3692. 2:55:38create a topic with couple of partition
  3693. 2:55:41then first we'll see the general
  3694. 2:55:43Behavior or the default Behavior how the
  3695. 2:55:45messages are getting splitted to the
  3696. 2:55:48different partition then we'll
  3697. 2:55:50understand how we can make a control on
  3698. 2:55:52that how I can send message to a
  3699. 2:55:55specific partition rather than sending
  3700. 2:55:56it to all the partition then we'll move
  3701. 2:55:59to the consumer and we'll read from a
  3702. 2:56:01specific partition okay so first let me
  3703. 2:56:04create a
  3704. 2:56:06topic so you know the command to create
  3705. 2:56:08the topic right capka topic s then
  3706. 2:56:11provide the topic name and then provide
  3707. 2:56:13the number of partition and replication
  3708. 2:56:16Factor so the topic name I'm creating
  3709. 2:56:19here javat hyen topic just enter it so
  3710. 2:56:23now this topic is created with five
  3711. 2:56:26partition count okay can you see here
  3712. 2:56:28the partition count is five it means now
  3713. 2:56:31we can distribute our messages to
  3714. 2:56:33different five partition fine so I will
  3715. 2:56:36copy this topic name then I will go to
  3716. 2:56:40the consumer I'll just change here then
  3717. 2:56:44I'll go to the
  3718. 2:56:45producer I will just change here
  3719. 2:56:49here now simply start your
  3720. 2:56:53producer and start your
  3721. 2:56:56consumer but make sure before you play
  3722. 2:56:59with your producer and consumer you
  3723. 2:57:01should start your Juke keeper and capka
  3724. 2:57:04server okay so I have already started
  3725. 2:57:06both the server now I have started my
  3726. 2:57:08producer and consumer then we'll publish
  3727. 2:57:10the message and we'll verify meanwhile I
  3728. 2:57:13will open the offset Explorer then I
  3729. 2:57:15will refresh the topic so we created
  3730. 2:57:18this topic right javat hyen topic I'll
  3731. 2:57:21just go inside this
  3732. 2:57:24topic there is no data because you have
  3733. 2:57:27not published anything right so I cannot
  3734. 2:57:29see anything here let's see if the
  3735. 2:57:31producer and consumer is up so producer
  3736. 2:57:34is up and
  3737. 2:57:35running also consumer is up and running
  3738. 2:57:38and the consumer group is assigned to
  3739. 2:57:41the three partition of my topic sorry
  3740. 2:57:44five partition of my topic can you see
  3741. 2:57:46here 0 1 2 3 4
  3742. 2:57:48that's fine just go to the producer and
  3743. 2:57:52we'll just publish couple of messages so
  3744. 2:57:55this is what the messages I mean this is
  3745. 2:57:57what the method I want to execute who
  3746. 2:57:59will use the template to send the
  3747. 2:58:01messages now if I see here this is what
  3748. 2:58:04the controller now here I'm sending
  3749. 2:58:0610,000 messages so if I'll send bulk
  3750. 2:58:09messages then only I can differentiate
  3751. 2:58:11okay all the messages is going to
  3752. 2:58:13different partition if I'll send one
  3753. 2:58:16messages then simply it can go to the
  3754. 2:58:18any single petition right so that is the
  3755. 2:58:20reason I'm sending the bulk messages
  3756. 2:58:22here and yeah I need to hit this
  3757. 2:58:24particular Endo so let me go to the
  3758. 2:58:27browser or I will go to the postman this
  3759. 2:58:30is what the endpoint I'll will send some
  3760. 2:58:33messages like
  3761. 2:58:34welcome okay now let me send
  3762. 2:58:38this so all the message has been
  3763. 2:58:40published here you can see the messages
  3764. 2:58:42now to verify that okay all the messages
  3765. 2:58:45is goes to the top PE I will go to this
  3766. 2:58:48offset Explorer and I'll simply refresh
  3767. 2:58:52this then if I execute this I can see
  3768. 2:58:56bunch of messages right and now let's
  3769. 2:58:58see how many messages went to each
  3770. 2:59:01partition so the number of partition we
  3771. 2:59:03have is five can you see here 0 1 2 3 4
  3772. 2:59:07I mean begin from the zero it is five
  3773. 2:59:09now let's see the number of messages in
  3774. 2:59:12each partition partition
  3775. 2:59:14zero contains 2242 messages
  3776. 2:59:20partition 1 contains
  3777. 2:59:233,206 partition 2
  3778. 2:59:261843 partition 3
  3779. 2:59:28709 partition 4 2011 okay I mean we have
  3780. 2:59:33sent 10,000 messages now different
  3781. 2:59:36messages went to different partition and
  3782. 2:59:39we can see the number of messages hold
  3783. 2:59:41in each partition right so now that that
  3784. 2:59:45is what the typical uh producer flow I
  3785. 2:59:48mean uh whenever we are publish the
  3786. 2:59:50messages messages will distributed to
  3787. 2:59:52different partition but I want to make
  3788. 2:59:54the control here I want to send messages
  3789. 2:59:57to a single partition from this topic I
  3790. 3:00:00might need to perform the data
  3791. 3:00:03processing or optimization so I might
  3792. 3:00:05need to send the messages to a single
  3793. 3:00:07partition let's say I want to send to
  3794. 3:00:09the partition three how I can do that
  3795. 3:00:12that that is what we are going to learn
  3796. 3:00:14here right so simple thing you need to
  3797. 3:00:17tell to the capka template while sending
  3798. 3:00:20the messages to which partition you want
  3799. 3:00:23to put this messages that thing you need
  3800. 3:00:25to tell to the capka template now how
  3801. 3:00:27you can tell that simple go to your code
  3802. 3:00:30go to the capka template where where
  3803. 3:00:33exactly you are sending the messages now
  3804. 3:00:35here if you'll open this send method
  3805. 3:00:37this is the overloaded method in the
  3806. 3:00:39template class can you see here topic
  3807. 3:00:42and data topic key and data and here is
  3808. 3:00:46the method top top now you can tell here
  3809. 3:00:49which partition you want to send your
  3810. 3:00:52messages you can specify the partition
  3811. 3:00:54along with the key key is something
  3812. 3:00:56which will help you to avoid duplicate
  3813. 3:00:58message in capka that will cover in the
  3814. 3:01:00separate session but this is what the
  3815. 3:01:02method you can use to specify to which
  3816. 3:01:05partition you want to send the messages
  3817. 3:01:08so just do the simple code change go to
  3818. 3:01:10the publisher and tell that okay I want
  3819. 3:01:12to send to partition three and just pass
  3820. 3:01:16the key I mean for now I will pass the
  3821. 3:01:18the null I don't want to play with the
  3822. 3:01:20key at this moment so now all the
  3823. 3:01:22messages will send to this partition so
  3824. 3:01:25shall we verify that simple thing just
  3825. 3:01:27go to the controller I'll just reduce
  3826. 3:01:29the message count I want to send 100
  3827. 3:01:32messages okay now it will go to the
  3828. 3:01:34partition three so just verify we want
  3829. 3:01:38to send into this partition the current
  3830. 3:01:40message count is 79 and we will push the
  3831. 3:01:43100 more messages okay so simply I'll
  3832. 3:01:46will just restart my product
  3833. 3:01:48producer so producer is up and running
  3834. 3:01:51now go to the postman I'll just send
  3835. 3:01:54some different message let's say user
  3836. 3:01:57and it will trigger 100 user messages
  3837. 3:02:00that is what we are just looping in the
  3838. 3:02:01code right we are sending 100 with the
  3839. 3:02:04user count user 1 2 3 like 100 now let
  3840. 3:02:08me send the
  3841. 3:02:09request all the messages has been sent
  3842. 3:02:13can you see here send message user 93
  3843. 3:02:15and this are the partition and also so
  3844. 3:02:18if you'll observe in the
  3845. 3:02:19consumer okay what is the problem here
  3846. 3:02:22okay so that's fine we'll we'll come to
  3847. 3:02:24the consumer because we have Define your
  3848. 3:02:26object and we are sending the string
  3849. 3:02:28that is the reason this consumer is
  3850. 3:02:30crying but we'll do the code change once
  3851. 3:02:31we'll demonstrate the consumer part okay
  3852. 3:02:34that's fine now just go to the offset
  3853. 3:02:37Explorer see the count is 709 right and
  3854. 3:02:40we have pushed 100 more messages so just
  3855. 3:02:43let me refresh this then simply come to
  3856. 3:02:46the partition three
  3857. 3:02:48can you see here the count is 810
  3858. 3:02:52earlier it was 709 right now all the 100
  3859. 3:02:56messages is come to partition 3 only now
  3860. 3:02:59similarly this is how you can manage in
  3861. 3:03:01the producer part and you can specify to
  3862. 3:03:04which partition you want to send the
  3863. 3:03:06messages like this you just need to
  3864. 3:03:10specify the partition number that's it
  3865. 3:03:13now this is what we understand from the
  3866. 3:03:15producer perspective now whatever all
  3867. 3:03:18the messages we are sending to a
  3868. 3:03:19partition or the broker is being
  3869. 3:03:22consumed by my consumer right now I
  3870. 3:03:25don't want my consumer to look into all
  3871. 3:03:28the partition I want to tell to my
  3872. 3:03:30consumer hey consumer can you please
  3873. 3:03:33read into a specific partition for
  3874. 3:03:35example from partition 3 or partition
  3875. 3:03:37two not from all how I can do that we
  3876. 3:03:40understand from the producer perspective
  3877. 3:03:42how to push the message to a specific
  3878. 3:03:44partition now we we just need to start
  3879. 3:03:47implementing from the consumer
  3880. 3:03:49perspective how can my consumer read
  3881. 3:03:51from a specific partition okay so it's
  3882. 3:03:55very simple you just need to play with
  3883. 3:03:57The annotation just go to the
  3884. 3:04:00consumer okay let me stop this first
  3885. 3:04:04then I will just do one thing I'll just
  3886. 3:04:06copy this or I can create different
  3887. 3:04:09instance okay I'll take the input as a
  3888. 3:04:12string because that is what I'm sending
  3889. 3:04:14from my producer so it found the object
  3890. 3:04:17which is is not able to dis realize so
  3891. 3:04:19that is the reason we are getting the
  3892. 3:04:20error in the consumer that is fine now
  3893. 3:04:23here in The
  3894. 3:04:25Listener here exactly in the capka
  3895. 3:04:27listener you need to specify from which
  3896. 3:04:32partition you want to execute this
  3897. 3:04:34consumer to consume the messages that is
  3898. 3:04:37what you can just simply Define by just
  3899. 3:04:39writing the topic
  3900. 3:04:43partition okay now in this topic
  3901. 3:04:45partition you can simply just Define
  3902. 3:04:48here at
  3903. 3:04:50theate topic
  3904. 3:04:52partition now you just need to define
  3905. 3:04:54the what is the topic name and what is
  3906. 3:04:56the partition count you want to read the
  3907. 3:04:59topic name you can Define the same topic
  3908. 3:05:01name from where you want to
  3909. 3:05:03consume and then you can just Define the
  3910. 3:05:07partition count the count I want to read
  3911. 3:05:10it from let's say from partition two
  3912. 3:05:13okay I want to read it from partition
  3913. 3:05:16two that's it so this is how you can
  3914. 3:05:20control from your consumer perspective
  3915. 3:05:23to read from a specific partition okay
  3916. 3:05:26that's fine now let's verify that so now
  3917. 3:05:29I'll just use the different topic javate
  3918. 3:05:31techy topic one fine and then okay let
  3919. 3:05:36it be I mean better I will just comment
  3920. 3:05:38this okay now also go to the
  3921. 3:05:42producer and I'll will just change your
  3922. 3:05:44Java topic one rather than doing like
  3923. 3:05:47this what what I will do I just want to
  3924. 3:05:49send messages to the different partition
  3925. 3:05:53then I can prove that okay my consumer
  3926. 3:05:55is reading from the specific partition
  3927. 3:05:57what I have mentioned there so for that
  3928. 3:05:59what I can do capka template or what I
  3929. 3:06:02have different template right template
  3930. 3:06:04do
  3931. 3:06:06send messages to I mean I'll just simply
  3932. 3:06:09copy this
  3933. 3:06:11right so what is the
  3934. 3:06:13messages I'll just Define let's say hi
  3935. 3:06:17then something some random string
  3936. 3:06:20okay I'm sending multiple messages to
  3937. 3:06:22the same topic to different partition
  3938. 3:06:25one
  3939. 3:06:27two okay first let me see what number we
  3940. 3:06:30have specified two right so I'll send
  3941. 3:06:33more messages to the partition
  3942. 3:06:352 so I'm sending to all the partition
  3943. 3:06:39but I want my consumer to read from only
  3944. 3:06:42these two partition okay I mean this is
  3945. 3:06:45the same partition my consumer should
  3946. 3:06:47receive only these two messages because
  3947. 3:06:49these two messages went to partition two
  3948. 3:06:52so just change the
  3949. 3:06:55messages okay so welcome and YouTube
  3950. 3:06:58should my consumer consumed I mean that
  3951. 3:07:01is what we can find in my consumer
  3952. 3:07:03console let's verify that so looks good
  3953. 3:07:08we have specified the topic name
  3954. 3:07:09correctly now we just need to create
  3955. 3:07:11this topic with five partition okay so
  3956. 3:07:15go to the terminal just
  3957. 3:07:18run this the topic name the same Java
  3958. 3:07:21topic one fine the topic is created
  3959. 3:07:24let's verify that topic is
  3960. 3:07:27created yeah topic is here we don't have
  3961. 3:07:30any messages it contains five partition
  3962. 3:07:33fine so what I'll do I'll just start my
  3963. 3:07:38producer and my consumer as
  3964. 3:07:42well so both are up and running let's
  3965. 3:07:45verify the producer all good let's go to
  3966. 3:07:48the
  3967. 3:07:49consumer in consumer If You observe the
  3968. 3:07:52console statement consumer client ID
  3969. 3:07:55this is are the consumer group group ID
  3970. 3:07:58is this resetting offset for partition
  3971. 3:08:01javat topic one 2 can you see here this
  3972. 3:08:06is the topic name Java hen topic one and
  3973. 3:08:09it is only listening to partition two
  3974. 3:08:12that is what you can see in the
  3975. 3:08:14statement itself phas position offset
  3976. 3:08:17from the zero I mean it's just telling
  3977. 3:08:19that okay read it from the partition two
  3978. 3:08:21that is what I can understand from this
  3979. 3:08:23console now let's hit the endpoint and
  3980. 3:08:26we'll
  3981. 3:08:27verify I'll send the some some messages
  3982. 3:08:30okay because anyway it is not going to
  3983. 3:08:32print we have hardcoded the value while
  3984. 3:08:34sending the messages send the
  3985. 3:08:37request message has been sent now if you
  3986. 3:08:39will go and check in the
  3987. 3:08:43topic just open the
  3988. 3:08:45data white send lot of
  3989. 3:08:48messages okay oh it's sending on the
  3990. 3:08:51loop yeah that's fine but let's see the
  3991. 3:08:54number of messages in the partition 2 20
  3992. 3:08:58202 now let's see the consumer go to the
  3993. 3:09:02consumer see consumer only consume the
  3994. 3:09:05method I mean messages welcome and
  3995. 3:09:07YouTube because it's in the loop so it's
  3996. 3:09:10send multiple I mean 100 messages so can
  3997. 3:09:13you see here it only receive welcome and
  3998. 3:09:16YouTube
  3999. 3:09:18because only YouTube and welcome these
  4000. 3:09:20two messages we are sending to partition
  4001. 3:09:242 in our producer can you see here
  4002. 3:09:26welcome and YouTube so it is clearly
  4003. 3:09:29state that my consumer is listening to
  4004. 3:09:32only partition 2 because I cannot see
  4005. 3:09:35this hi hello Java TI key these messages
  4006. 3:09:37in my consumer console okay so you
  4007. 3:09:41cannot let me filter it okay we have not
  4008. 3:09:44see this no
  4009. 3:09:48no right but only welcome and
  4010. 3:09:52YouTube can you see here the count is
  4011. 3:09:54itself is 101 and
  4012. 3:09:57YouTube it should be same one1 okay
  4013. 3:10:01that's it I mean this is how you can
  4014. 3:10:03play with the Capa partition to specify
  4015. 3:10:06while publishing the messages and
  4016. 3:10:08specify the partition while consuming
  4017. 3:10:11the messages this is sometimes required
  4018. 3:10:13Whenever there is some uh message event
  4019. 3:10:16failed in the production you might need
  4020. 3:10:18to republish the event okay and that
  4021. 3:10:21time you might need to play with this
  4022. 3:10:22partition kind of concept so just give a
  4023. 3:10:25try and let me know in a comment section
  4024. 3:10:27if you have any
  4025. 3:10:33doubts if you remember in the last capka
  4026. 3:10:36session we have designed our capka
  4027. 3:10:38producer and consumer application right
  4028. 3:10:41so in this tutorial I'll guide you how
  4029. 3:10:43to write capka integration test with
  4030. 3:10:46test container
  4031. 3:10:48okay all right being a developer always
  4032. 3:10:50writing a capka integration test can be
  4033. 3:10:53frustrating because that's mainly due to
  4034. 3:10:55the complex test configuration that
  4035. 3:10:57involves for registering the consumer
  4036. 3:10:59and producer or to read and write
  4037. 3:11:02messages isn't it and also without
  4038. 3:11:04proper integration testing you cannot be
  4039. 3:11:06confident about the stability of your
  4040. 3:11:08production environment So to liage that
  4041. 3:11:11we can use the test containers which can
  4042. 3:11:13reduce test configuration to almost zero
  4043. 3:11:16and not worry about how to read and
  4044. 3:11:18write messages from and to capka when
  4045. 3:11:21writing a test case instead a developer
  4046. 3:11:24can entirely focus on only testing
  4047. 3:11:26needed functionality okay so if you're
  4048. 3:11:29not aware about what is test containers
  4049. 3:11:31and how to use it then I would strongly
  4050. 3:11:33suggest you to check out this particular
  4051. 3:11:35video in my YouTube channel spring boot
  4052. 3:11:373 integration testing with test
  4053. 3:11:40container where I have explain in detail
  4054. 3:11:42by taking the example of my SQL using
  4055. 3:11:44the test containers I will also share
  4056. 3:11:46the link in the video description for
  4057. 3:11:48your reference okay so without any
  4058. 3:11:50further delay let's Circle back to the
  4059. 3:11:52demo so let's get started so before we
  4060. 3:11:55start writing the test case first let's
  4061. 3:11:58verify whether our producer and consumer
  4062. 3:12:00example application is working or not so
  4063. 3:12:02I have started my producer application
  4064. 3:12:05and also I have started my consumer
  4065. 3:12:07application here and if You observe here
  4066. 3:12:10in the terminal I have started my juke
  4067. 3:12:12keeper and capka server okay that's
  4068. 3:12:15enough now if you will go to the
  4069. 3:12:17producer app in the producer application
  4070. 3:12:20we have defined the controller from this
  4071. 3:12:22controller method we are sending the
  4072. 3:12:24customer object to the topic fine so the
  4073. 3:12:27endpoint is SL publish let's go to the
  4074. 3:12:30postman and I have this particular
  4075. 3:12:32endpoint with this particular payload
  4076. 3:12:34now just trigger the
  4077. 3:12:36request status code is 20 now let's
  4078. 3:12:39verify in the consumer whether that
  4079. 3:12:41particular object is received or not
  4080. 3:12:43yeah can you see here consumer consume
  4081. 3:12:46the event this this is what we are
  4082. 3:12:48sending from our producer one1 name is
  4083. 3:12:51basant email ID and contact number so
  4084. 3:12:55all good now let's start writing the
  4085. 3:12:57test case for that I don't want to use
  4086. 3:13:00my capka which I installed on my machine
  4087. 3:13:03so I will stop
  4088. 3:13:04everything I will stop my
  4089. 3:13:07consumer and producer as
  4090. 3:13:10well and from the terminal I'll close my
  4091. 3:13:13juke keeper and capka server because I'm
  4092. 3:13:16not going to use this particular capka
  4093. 3:13:18instance I want to take the help from
  4094. 3:13:20capka taste containers to spin up a new
  4095. 3:13:23capka instance for me so I'll show you
  4096. 3:13:26that how you can do that so let me close
  4097. 3:13:28everything now the local Capa is shut
  4098. 3:13:30down for me so what I'll do very simple
  4099. 3:13:34just go to the pal.
  4100. 3:13:36XML in pal. XML we just need to add the
  4101. 3:13:40tast container specific dependency if
  4102. 3:13:42I'll open it so I have added the tast
  4103. 3:13:45container dependency then taste
  4104. 3:13:47container for capka and I have added the
  4105. 3:13:50Jupiter and also I have added this
  4106. 3:13:52utility to just pause for some time I
  4107. 3:13:56mean whenever I'm running the capka
  4108. 3:13:58producer and consumer I want my thread
  4109. 3:14:01will pause for some specific second or
  4110. 3:14:04for some time interval that is the
  4111. 3:14:05reason I I have just added this utility
  4112. 3:14:08okay I I'll tell you in the code
  4113. 3:14:10whenever we will implement this that's
  4114. 3:14:12fine then just update your
  4115. 3:14:15project then what I want to do I want to
  4116. 3:14:18disable this config class because I want
  4117. 3:14:20to load it from the application. yml
  4118. 3:14:23file so I'll just uncomment this that's
  4119. 3:14:27it just go to the test class and start
  4120. 3:14:30writing your test case now here okay let
  4121. 3:14:33me close everything so first step we can
  4122. 3:14:37just run this particular test case in
  4123. 3:14:40random Port okay so I'll Define web
  4124. 3:14:44environment there is something called
  4125. 3:14:47random
  4126. 3:14:48Port then I just let me Zoom this for
  4127. 3:14:51you then I just need to annotate here at
  4128. 3:14:54theate test
  4129. 3:14:56containers by adding this annotation I'm
  4130. 3:14:59telling to the spring boot test that
  4131. 3:15:01this particular class is using some
  4132. 3:15:04container fine now which container I
  4133. 3:15:08want to use I want to use the capka
  4134. 3:15:10container so for capka container how
  4135. 3:15:12from where you'll get this capka
  4136. 3:15:14container just go to this documentation
  4137. 3:15:17you can copy this and then then simply
  4138. 3:15:21just paste it here we are using the
  4139. 3:15:23capka container by saying to The capka
  4140. 3:15:25Container hey capka container can you
  4141. 3:15:28please bring this specific capka version
  4142. 3:15:30for me
  4143. 3:15:316.2.1 if you don't want to specify any
  4144. 3:15:33capka version just tell that hey
  4145. 3:15:36container can you give me the latest
  4146. 3:15:38capka version which you have with you
  4147. 3:15:40that's fine you can Define the version
  4148. 3:15:42whatever you want here okay now annotate
  4149. 3:15:45this atate container
  4150. 3:15:48next since we have created the Capa
  4151. 3:15:50container we need to configure the
  4152. 3:15:52bootstrap server so for that I will
  4153. 3:15:54simply write a method public
  4154. 3:15:57viid let's say init cap Properties or
  4155. 3:16:00something like
  4156. 3:16:02that then you need to just pass your
  4157. 3:16:04Dynamic Property
  4158. 3:16:07registry and also here you need to
  4159. 3:16:09annotate Dynamic Property Source these
  4160. 3:16:13annotation came from the this specific
  4161. 3:16:16test containers okay so you don't need
  4162. 3:16:18to remember this annotation name but
  4163. 3:16:20whenever you are using the test
  4164. 3:16:21container you need to play with these
  4165. 3:16:24annotation fine now
  4166. 3:16:26registry do
  4167. 3:16:29add key name is spring. ca. bootstrap
  4168. 3:16:33hypen server I just need to copy the
  4169. 3:16:35same name what I have defined here so
  4170. 3:16:38this is
  4171. 3:16:39right so you can Define spring.
  4172. 3:16:44capka then bootstrap servers
  4173. 3:16:47and what is the bootstrap server you
  4174. 3:16:49want to specify I don't know exactly the
  4175. 3:16:51bootstrap server name because this
  4176. 3:16:54particular container will get the server
  4177. 3:16:56for me every time you will run you'll
  4178. 3:16:58get different server okay so what we can
  4179. 3:17:01do we can tell here hey get it from the
  4180. 3:17:04Capa container
  4181. 3:17:06itself this is how we can
  4182. 3:17:09specify fine so we are done with the
  4183. 3:17:13infrastructure setup now let's start
  4184. 3:17:15writing our actual test case so let's go
  4185. 3:17:19to the project we are going to write the
  4186. 3:17:21test case for this guy okay this capka
  4187. 3:17:24message publisher we want to send the
  4188. 3:17:26custom object which is customer this
  4189. 3:17:29particular method so let me copy this
  4190. 3:17:31method
  4191. 3:17:33name then I'll simply write the test
  4192. 3:17:35method
  4193. 3:17:37public
  4194. 3:17:38viid
  4195. 3:17:41test fine so to call this specific
  4196. 3:17:44method from the capka message publish
  4197. 3:17:47sir first I need to inject this so just
  4198. 3:17:50go here and I just need to Auto add that
  4199. 3:17:56private then just do the auto
  4200. 3:17:59add that's it now I just need to call
  4201. 3:18:04Publisher dot send events to the topic
  4202. 3:18:09there are two method we have defined in
  4203. 3:18:10that publisher one will send the string
  4204. 3:18:13message one will send the custom object
  4205. 3:18:15where we have just find the customer as
  4206. 3:18:17a d and we are sending it so I'm using
  4207. 3:18:20the second method I mean wherever I am
  4208. 3:18:22sending the custom object so I will
  4209. 3:18:24create a new customer new customer what
  4210. 3:18:28all field I need to pass ID name email
  4211. 3:18:31and contact number so let's say ID
  4212. 3:18:34something some random
  4213. 3:18:37number name let's say test
  4214. 3:18:40user email I guess email is test at
  4215. 3:18:45gmail.com
  4216. 3:18:47then what else contact number some
  4217. 3:18:50random number
  4218. 3:18:52okay next just annotate this at theate
  4219. 3:18:55test make sure to import the test from
  4220. 3:18:59Jupiter not from the junit once you have
  4221. 3:19:02written this this sent event to the
  4222. 3:19:04topic will publish the message to the
  4223. 3:19:06topic and after that I want to pause for
  4224. 3:19:09some time interval so that is the reason
  4225. 3:19:11we have used this utility class so let
  4226. 3:19:13me add the input
  4227. 3:19:15statement this should be UT from org do
  4228. 3:19:18this particular class okay and I want to
  4229. 3:19:21wait the pool interval is 3 second and
  4230. 3:19:25minimum I want to wait for 10
  4231. 3:19:27second and next to that if you have any
  4232. 3:19:30asset statement you can add it inside
  4233. 3:19:33this particular
  4234. 3:19:35block so just UT
  4235. 3:19:38this so we are specifying the pool
  4236. 3:19:41interval of 3 second and at most I mean
  4237. 3:19:44the minimum amount I want to wait for 10
  4238. 3:19:46second once this particular message will
  4239. 3:19:48push to the topic so after that if you
  4240. 3:19:51have any asset statement you can write
  4241. 3:19:53it here since my method is B I don't
  4242. 3:19:56have any Asser statement I cannot write
  4243. 3:19:58anything here even you can give a try by
  4244. 3:20:01persisting that particular customer
  4245. 3:20:03object to the DV and you can just write
  4246. 3:20:05the assert statement here by fetching it
  4247. 3:20:08from the
  4248. 3:20:09DV so this is the simple example guys
  4249. 3:20:11okay nothing to worry now I believe all
  4250. 3:20:14good let's run our code
  4251. 3:20:17so let me run the test
  4252. 3:20:20case okay it seems there is error this
  4253. 3:20:24particular method must be static okay
  4254. 3:20:26let's change it to the
  4255. 3:20:28static so if you'll make this static
  4256. 3:20:30better let's change this particular
  4257. 3:20:32field also
  4258. 3:20:34static now looks good let me run this
  4259. 3:20:38we'll find out some error then I'll tell
  4260. 3:20:40you how we can resolve
  4261. 3:20:42that so if You observe here when the
  4262. 3:20:45particular test will execute first it
  4263. 3:20:48will get that particular capka image can
  4264. 3:20:51you see here starting to pull the image
  4265. 3:20:54what is the version latest now it will
  4266. 3:20:56take few second to pull that Docker
  4267. 3:20:59images so you can see here it
  4268. 3:21:02successfully pull the image of this
  4269. 3:21:04specific version I mean the latest
  4270. 3:21:06version then it's trying to start that
  4271. 3:21:08particular container this is what right
  4272. 3:21:11now to verify whether it pull the
  4273. 3:21:13specific Docker image or not what you
  4274. 3:21:15can do go to the terminal just type
  4275. 3:21:19Ducker
  4276. 3:21:21images If You observe here can you see
  4277. 3:21:23here C capka and the tag is latest now
  4278. 3:21:27if you want to verify whether that is
  4279. 3:21:29the container itself is running or not
  4280. 3:21:31just run Docker PS you can see here
  4281. 3:21:35right the capka container is running
  4282. 3:21:37here let me Zoom this for you the
  4283. 3:21:41container is running here and this is
  4284. 3:21:43the Ducker image it pull
  4285. 3:21:47kapka fine so go back here let's see
  4286. 3:21:51what is the result so if You observe
  4287. 3:21:54here it's giving us the
  4288. 3:21:57error because this particular test case
  4289. 3:22:01will look into your application. yml
  4290. 3:22:03file which you have defined in
  4291. 3:22:06your Source folder I mean in the main
  4292. 3:22:08folder not in the test folder there you
  4293. 3:22:11have specified the bootstrap server as a
  4294. 3:22:149092 local host but our bootstrap server
  4295. 3:22:18is running dynamically fine so for that
  4296. 3:22:21reason you need to override this
  4297. 3:22:23application. yml in your test
  4298. 3:22:27folder so just create a directory
  4299. 3:22:32resource just paste
  4300. 3:22:35this and remove the bootstrap server so
  4301. 3:22:38that it will pick from the container and
  4302. 3:22:40will run it Dynamic bootstrap I mean the
  4303. 3:22:43bootstrap server will be dynamic here so
  4304. 3:22:46this is not not required for test you
  4305. 3:22:47can remove
  4306. 3:22:49this fine now go to the test class and
  4307. 3:22:53run it
  4308. 3:22:55again now second time when I'm running
  4309. 3:22:58it it won't pull the image again because
  4310. 3:23:01it is already pulled that specific image
  4311. 3:23:03at first time fine so let's wait it to
  4312. 3:23:08complete see directly pull the image
  4313. 3:23:11here and starting the
  4314. 3:23:15container okay can you see here we got
  4315. 3:23:18the message here sent message this is
  4316. 3:23:21what the object we are sending right
  4317. 3:23:23with upset zero now if you go and check
  4318. 3:23:25in the publisher class after
  4319. 3:23:28successfully send the messages we are
  4320. 3:23:31just printing the statement
  4321. 3:23:33system.out.print and send message this
  4322. 3:23:35is what right if there is a exception
  4323. 3:23:38then it will print this particular
  4324. 3:23:40statement since in our case we are able
  4325. 3:23:42to successfully send the messages we are
  4326. 3:23:44able to get the first statement that
  4327. 3:23:46sent message to the particular message
  4328. 3:23:49and to which upset that is what we can
  4329. 3:23:52see here
  4330. 3:23:53right if you go here to the test
  4331. 3:23:57case get the result go to this specific
  4332. 3:24:00test case now if you'll scroll down you
  4333. 3:24:02can see the log messages here right this
  4334. 3:24:06is what we have written for producer now
  4335. 3:24:08since I am a producer I might have 100
  4336. 3:24:11of consumers right so now consumers
  4337. 3:24:14people need to write their own test case
  4338. 3:24:16for Consumer class okay so let's start
  4339. 3:24:19begin writing the test case for Consumer
  4340. 3:24:21we are good with the producer now if You
  4341. 3:24:23observe in the code I have not worried
  4342. 3:24:26more about the infrastructure I have
  4343. 3:24:28just defined these two line everything
  4344. 3:24:30will be Take Care by this capka
  4345. 3:24:31container itself what I focused I only
  4346. 3:24:34focused on writing my functionality test
  4347. 3:24:37whether this particular method where I'm
  4348. 3:24:39exactly publishing the event is working
  4349. 3:24:42or not okay now let's start writing the
  4350. 3:24:44test case for consumer application so I
  4351. 3:24:47need this information so first of all
  4352. 3:24:49first let me copy all the dependency
  4353. 3:24:52what I have added here because same
  4354. 3:24:54dependency we need to add in our
  4355. 3:24:56consumer as
  4356. 3:24:57well copy this go to the consumer
  4357. 3:25:01application go to the pom.xml
  4358. 3:25:05then just scroll down and paste it
  4359. 3:25:10here just update
  4360. 3:25:12it fine now go to the test case here
  4361. 3:25:16this are the test case now let me copy
  4362. 3:25:19all the field from the producer I mean
  4363. 3:25:21we are going to reuse the same
  4364. 3:25:23annotation and um capka container so
  4365. 3:25:25I'll just copy
  4366. 3:25:27paste just go to the
  4367. 3:25:30consumer paste it
  4368. 3:25:33here go to the producer get the
  4369. 3:25:37container and Dynamic Property
  4370. 3:25:39Source copy
  4371. 3:25:41this then paste it here I mean whoever
  4372. 3:25:45have the consumer for your application
  4373. 3:25:48they need to test their application that
  4374. 3:25:50whether they are able to successfully
  4375. 3:25:52face the events from that specific topic
  4376. 3:25:54or not okay so that is the reason they
  4377. 3:25:57need to write the test case so for that
  4378. 3:25:59how they can validate that whether the
  4379. 3:26:01message is coming to the topic or not so
  4380. 3:26:03forcefully you need to send some event
  4381. 3:26:06or messages to the topic then in
  4382. 3:26:08consumer itself you need to write the
  4383. 3:26:09logic to the or you need to validate
  4384. 3:26:12that whether it is consuming or not okay
  4385. 3:26:14that is simple statement guys so let me
  4386. 3:26:17write the test case
  4387. 3:26:19public first let me go to The Listener
  4388. 3:26:22class right this is the class where my
  4389. 3:26:24consumer is written here I mean this is
  4390. 3:26:27the place I'm consuming the event from
  4391. 3:26:29this specific topic so that is the
  4392. 3:26:31reason I have defined the adate Capal
  4393. 3:26:34listener so I'll just take the method
  4394. 3:26:36name go to the test class public
  4395. 3:26:40void
  4396. 3:26:43test so to validate whether this part
  4397. 3:26:46particular method is being consumed or
  4398. 3:26:48not so what I'll do forcefully I need to
  4399. 3:26:52send some message to this topic so for
  4400. 3:26:54that what I need I need a capka template
  4401. 3:26:57so I just need to inject here Capa
  4402. 3:27:02template up type string as a key and
  4403. 3:27:06value as a
  4404. 3:27:08object just inject using Auto
  4405. 3:27:13add so here what I will do I'll just
  4406. 3:27:16send Capa template do
  4407. 3:27:19send object to which topic the same
  4408. 3:27:23topic what you have defined here because
  4409. 3:27:25I only forcefully send some message to
  4410. 3:27:26this topic to validate okay this
  4411. 3:27:29consumer is working
  4412. 3:27:30correctly just specify the topic and
  4413. 3:27:33just Define the customer object so I
  4414. 3:27:35will better copy the customer object
  4415. 3:27:37from here
  4416. 3:27:40itself just paste it here or I'll just
  4417. 3:27:44Define above okay
  4418. 3:27:47then just pass this customer object to
  4419. 3:27:49this Capa template so that it will
  4420. 3:27:52publish the message to this topic and
  4421. 3:27:54this particular listener need to execute
  4422. 3:27:56and it will print this log statement
  4423. 3:27:58that is what we are expecting fine so
  4424. 3:28:01what I do go to the test first I'll do
  4425. 3:28:04one thing I'll just add some log
  4426. 3:28:06statement here SL
  4427. 3:28:084J then I'll just
  4428. 3:28:11add
  4429. 3:28:12log
  4430. 3:28:15doino let's say test consume
  4431. 3:28:19events method
  4432. 3:28:22execution started something like that
  4433. 3:28:25and also I will just add execution
  4434. 3:28:29ended so execution will be start then we
  4435. 3:28:32are building the customer object and
  4436. 3:28:34through capka template we are sending it
  4437. 3:28:36to the this specific topic fine now once
  4438. 3:28:40it will publish to to this specific
  4439. 3:28:42topic this listener will read that
  4440. 3:28:44messages and it will print the log stat
  4441. 3:28:46once everything done we are just
  4442. 3:28:48printing that okay the execution is
  4443. 3:28:50ended and you can also annotate your
  4444. 3:28:54test and make sure to input it from the
  4445. 3:28:57Jupiter okay this is as much as
  4446. 3:29:01simple fine now here also what I want to
  4447. 3:29:04do I want to enable the application.
  4448. 3:29:08yml I mean I just want to uncomment I
  4449. 3:29:11want to use this application. IML and I
  4450. 3:29:13want to comment this config class again
  4451. 3:29:17you can try in both the way but let's go
  4452. 3:29:19with the application. IML so that if any
  4453. 3:29:22test configuration required I can add
  4454. 3:29:24directly the yml file here rather than
  4455. 3:29:26Define the config class now here also I
  4456. 3:29:29need to define the resource folder new
  4457. 3:29:33directory resources and just add the
  4458. 3:29:36application. IML
  4459. 3:29:38file fine so make sure you need to
  4460. 3:29:42define the same group in your test case
  4461. 3:29:45so so let's go here I mean in not in the
  4462. 3:29:48test case this particular capka template
  4463. 3:29:51will publish the message to this topic
  4464. 3:29:53now if you go and check in The Listener
  4465. 3:29:55the topic name is correct and the group
  4466. 3:29:57name need to be this okay I mean it is
  4467. 3:30:01same only that is how I have configured
  4468. 3:30:02in yml file so go to the test case all
  4469. 3:30:07good now let me run
  4470. 3:30:13this so it started the container here
  4471. 3:30:15can you see see here now it will start
  4472. 3:30:17executing our test
  4473. 3:30:20case so this test is executed
  4474. 3:30:24successfully now if you filter
  4475. 3:30:27this we have not received the I mean the
  4476. 3:30:29request is not goes to my consumer fine
  4477. 3:30:33if you'll see here not here to go to the
  4478. 3:30:36main one you'll find some error right or
  4479. 3:30:40ca.on producer is closed forcefully so
  4480. 3:30:43for that what you can do you need to
  4481. 3:30:46wait for some time I mean the way we
  4482. 3:30:49have done in the producer similarly you
  4483. 3:30:51need to wait for some second because it
  4484. 3:30:54might take some time to establish the
  4485. 3:30:55connection right or it might take some
  4486. 3:30:58time to connect to the container so it's
  4487. 3:31:00good to keep some buffer uh time
  4488. 3:31:02interval for
  4489. 3:31:04sleep fine now let's run it just run
  4490. 3:31:09from
  4491. 3:31:11here restarting the container
  4492. 3:31:14now
  4493. 3:31:16so it started our
  4494. 3:31:18application now can you see here let's
  4495. 3:31:21wait it to complete yeah within a second
  4496. 3:31:23it will be complete now if you'll scroll
  4497. 3:31:26down the JT group partition assigned to
  4498. 3:31:29this particular topic partition I mean
  4499. 3:31:31the partition count is zero and this is
  4500. 3:31:33your topic name and this is the group
  4501. 3:31:36name and can you see here the messages
  4502. 3:31:39let me Zoom this consumer consume the
  4503. 3:31:42event this is what the 263 test user t
  4504. 3:31:46start the email and contact number this
  4505. 3:31:48is the object we are publishing through
  4506. 3:31:50the capka template and we have defined
  4507. 3:31:52the consumer who listen to that
  4508. 3:31:54particular topic and my consumer is able
  4509. 3:31:57to consume it so if You observe here go
  4510. 3:32:00to the consumer the statement we have
  4511. 3:32:02written is same right consumer consume
  4512. 3:32:05the event then what is the event it is
  4513. 3:32:07getting we're just converting it to the
  4514. 3:32:09string the same statement we are able to
  4515. 3:32:12see it I mean we are able to
  4516. 3:32:15successfully consume the event from our
  4517. 3:32:17test case and using the test containers
  4518. 3:32:21so if You observe here again I didn't
  4519. 3:32:23take much heck to Define my
  4520. 3:32:25infrastructure I just Define these two
  4521. 3:32:27statement and rest everything will be
  4522. 3:32:29Take Care by this capka container itself
  4523. 3:32:32I mean the tast container itself okay so
  4524. 3:32:35the another advantages here in this
  4525. 3:32:37particular approach the Capa Ducker
  4526. 3:32:39container can be kept alive which can
  4527. 3:32:42help with the test performance and
  4528. 3:32:44results in a testing environment closer
  4529. 3:32:46to the production one so this particular
  4530. 3:32:49tutorial will give you the fully context
  4531. 3:32:51how you can write the integration test
  4532. 3:32:54for capka using the tast containers
  4533. 3:32:56whenever you'll try to apply this
  4534. 3:32:58specific use case to your real life
  4535. 3:33:00situation you can take it further by
  4536. 3:33:02adding more test cases you could also
  4537. 3:33:04start refactoring your app or adding new
  4538. 3:33:07features more reliable with the test
  4539. 3:33:09that you have written
  4540. 3:33:14okay
  4541. 3:33:18as you know Apachi kapka run in a
  4542. 3:33:21distributed manner across multiple
  4543. 3:33:23containers or machines it is also
  4544. 3:33:26crucial to address the errors and
  4545. 3:33:28recover the data in the event of failure
  4546. 3:33:32sometimes what happen when a producer
  4547. 3:33:34send a messages and we process that
  4548. 3:33:37message from the capka topic error can
  4549. 3:33:39occur for instance consumer services or
  4550. 3:33:42related infrastructure such as database
  4551. 3:33:45connection
  4552. 3:33:46might be unavailable during that period
  4553. 3:33:49so in that case there is a risk of
  4554. 3:33:52losing any events send or received due
  4555. 3:33:55to the failure so here what do we want
  4556. 3:33:57to ensure we don't lose any data and try
  4557. 3:34:01to handle the failed messages that's the
  4558. 3:34:04challenging part isn't it but don't
  4559. 3:34:06worry in this tutorial I'll be
  4560. 3:34:09explaining different way to handle
  4561. 3:34:11errors in capka okay all right let me
  4562. 3:34:15walk you through an use case consider a
  4563. 3:34:17scenario where you are processing
  4564. 3:34:19financial transaction if a transaction
  4565. 3:34:22fails to be processed due to some
  4566. 3:34:24temporary issue then how will you handle
  4567. 3:34:27it because here we want to ensure
  4568. 3:34:29reliable message processing so what
  4569. 3:34:32we'll do here we'll instruct capka to
  4570. 3:34:36retry the failed event now what capka
  4571. 3:34:39will does here he will simply reattempt
  4572. 3:34:42process the messages multiple times as
  4573. 3:34:46per your configuration for example if
  4574. 3:34:48you set the retry count to four capka
  4575. 3:34:51will make three retry attempts in a
  4576. 3:34:54sequential order because it follows n
  4577. 3:34:57minus one order okay so if you specify
  4578. 3:35:00four times to retry capka will do three
  4579. 3:35:03times so that is how you need to decide
  4580. 3:35:05what number you need to set for retry
  4581. 3:35:08attempt next if the process succeed
  4582. 3:35:11Within These retrace that's excellent
  4583. 3:35:14however if the retray account is
  4584. 3:35:16exceeded then the message will be
  4585. 3:35:18directed to the dead letter topic okay
  4586. 3:35:21or the messages will be route to the DLT
  4587. 3:35:24now you might have a question hey what
  4588. 3:35:27is DT DT stands for dead letter topic
  4589. 3:35:31which is nothing but creating a new
  4590. 3:35:33failure topic to store all the failed
  4591. 3:35:36messages or all the failed events if a
  4592. 3:35:38consumer is not able to process messages
  4593. 3:35:41even after retry then those unprocessed
  4594. 3:35:44messages will p push to this particular
  4595. 3:35:47dead letter topic okay now since you
  4596. 3:35:49have failed records with you in a topic
  4597. 3:35:52subsequently you can monitor them to
  4598. 3:35:54identify and investigate further so this
  4599. 3:35:58mechanism ensures that no data is lost
  4600. 3:36:01in the event of failure we still rain
  4601. 3:36:03the ability to handle and manage those
  4602. 3:36:06failed messages right so this is the
  4603. 3:36:09simple way to ensure that there is no
  4604. 3:36:12data is lost and reliable message
  4605. 3:36:15process procing so let's quickly see
  4606. 3:36:17this in a action let's go to our
  4607. 3:36:19intelligent idea since already you
  4608. 3:36:21discuss how to produce and consume
  4609. 3:36:24messages using capka so I have not
  4610. 3:36:26wasting the time and I have created a
  4611. 3:36:28project already so if you check here I
  4612. 3:36:31have a publisher and I have a consumer
  4613. 3:36:33if you're not aware about how to play
  4614. 3:36:35with the popup using capka you can check
  4615. 3:36:38out my playlist capka for beginers from
  4616. 3:36:41my YouTube I will also share the link in
  4617. 3:36:43video description for your refer friend
  4618. 3:36:46okay now let's jump into the code and
  4619. 3:36:48try to understand what pops up we are
  4620. 3:36:50doing in this particular example let's
  4621. 3:36:53go to the
  4622. 3:36:55publisher publisher is the simple thing
  4623. 3:36:57what we are doing here we are taking the
  4624. 3:36:59user object as a input and we are
  4625. 3:37:02publishing it to the
  4626. 3:37:03capka fine now if you'll open this
  4627. 3:37:06particular user object we have couple of
  4628. 3:37:08field called ID first name last name
  4629. 3:37:11email gender and IP address now let's go
  4630. 3:37:15to the consumer what exact action we are
  4631. 3:37:18doing in the
  4632. 3:37:19consumer if I open the
  4633. 3:37:23consumer we are simply taking that input
  4634. 3:37:26user input what we received from our
  4635. 3:37:29topic then I'm just adding one
  4636. 3:37:31validation here to simulate the error
  4637. 3:37:34scenario I have just added this
  4638. 3:37:36restriction okay so as part of the user
  4639. 3:37:40you can see there is a IP address so
  4640. 3:37:42when I will receive any user request or
  4641. 3:37:44when I will consum
  4642. 3:37:46any event specific to the user I will
  4643. 3:37:48validate that okay if user is giving any
  4644. 3:37:52of the IP specified in this particular
  4645. 3:37:54list then I will not allow that user to
  4646. 3:37:57process further okay so I have just
  4647. 3:38:00added a simple if Clause to check if the
  4648. 3:38:04address if the list contains the address
  4649. 3:38:07then throw some simple exception to just
  4650. 3:38:09simulate the error scenario okay now
  4651. 3:38:13what I'll do let's simply wrun on this
  4652. 3:38:15particular use case then we'll find out
  4653. 3:38:18what is the problem with this particular
  4654. 3:38:20implementation then we'll go with the
  4655. 3:38:22solution so first I need to start the
  4656. 3:38:25jke
  4657. 3:38:27keeper start
  4658. 3:38:30it then let me simply start the capka
  4659. 3:38:34server just enter
  4660. 3:38:37it so here my Joe keeper and capka
  4661. 3:38:41server both are up and running to
  4662. 3:38:43validate that what I'll do I'll go to
  4663. 3:38:45this
  4664. 3:38:47upset yeah if I'll open this I can able
  4665. 3:38:50to make the
  4666. 3:38:53connection okay great so this is the
  4667. 3:38:56tool to visualize your cup cup payload
  4668. 3:38:59from the producer end and you can find
  4669. 3:39:01the consumer related stop as well okay
  4670. 3:39:04everything I have covered in my Capa
  4671. 3:39:05playlist you can take a look to that
  4672. 3:39:07particular
  4673. 3:39:09videos all good now let's start our
  4674. 3:39:13application so in config we have defined
  4675. 3:39:16to create the topic can you see here we
  4676. 3:39:20have the topic name and here we are
  4677. 3:39:22saying to create the topic with three
  4678. 3:39:25partition and the topic name is defined
  4679. 3:39:29in this application. properties
  4680. 3:39:33file
  4681. 3:39:34fine so let's see the
  4682. 3:39:38log can you see here Java group that is
  4683. 3:39:42what my consumer group partition
  4684. 3:39:44assigned two since we have created topic
  4685. 3:39:47with the three partition you can see
  4686. 3:39:49each and every partition here right 1
  4687. 3:39:53two so now just let's test our pops up
  4688. 3:39:57flow so we have defined a controller
  4689. 3:39:59class here Here If You observe we have a
  4690. 3:40:02endpoint called publish new where we are
  4691. 3:40:05just giving a user object and it will
  4692. 3:40:08call our publisher to publish the event
  4693. 3:40:11to the topic okay then our consumer will
  4694. 3:40:14listen to that part particular topic and
  4695. 3:40:16we'll do the steps mention here that's
  4696. 3:40:20fine just go to the
  4697. 3:40:22postman I'll give some valid input
  4698. 3:40:25first so let me send the
  4699. 3:40:29request message published successfully
  4700. 3:40:32now if you validate in your
  4701. 3:40:34console Can You observe here this is the
  4702. 3:40:38log from producer okay the messages is
  4703. 3:40:42pushed to upset zero and this is the log
  4704. 3:40:46from the
  4705. 3:40:47consumer can you see
  4706. 3:40:51here 2
  4707. 3:40:5435 let's change the name to basant then
  4708. 3:40:58last name something
  4709. 3:41:00Hut and give some random email
  4710. 3:41:04id id will be two now let me send the
  4711. 3:41:09request the message published
  4712. 3:41:11successfully again if you check in your
  4713. 3:41:14log
  4714. 3:41:15the second record with id2 from the
  4715. 3:41:18producer log and this is what the
  4716. 3:41:21messages log from the
  4717. 3:41:23consumer okay it read from the upset one
  4718. 3:41:28and also the upset one in the producer
  4719. 3:41:31this is the happy scenario right it is
  4720. 3:41:33working as expected now let me clear
  4721. 3:41:35this let me give some IP address which
  4722. 3:41:39is specified
  4723. 3:41:41here let me
  4724. 3:41:43just change change in
  4725. 3:41:46the request
  4726. 3:41:48body now if I'll send the request let's
  4727. 3:41:51see what will be the
  4728. 3:41:54result message published successfully
  4729. 3:41:56producer is successfully able to publish
  4730. 3:41:59the message to the topic now the
  4731. 3:42:01validation is there in our consumer
  4732. 3:42:03right so what is the result here invalid
  4733. 3:42:07IP address received that is what we are
  4734. 3:42:10expecting here right we are expecting to
  4735. 3:42:13get the exception and we are getting it
  4736. 3:42:15now what is the problem
  4737. 3:42:18here there is nothing right what is the
  4738. 3:42:20problem here the simple thing is that
  4739. 3:42:23the record which we are not processed if
  4740. 3:42:27we not take a look into it there could
  4741. 3:42:29be a chance for data lost right the
  4742. 3:42:31record which we just received and what
  4743. 3:42:34just we validated that we need to take
  4744. 3:42:36care of it we need to reattempt because
  4745. 3:42:39see here I am just added the if
  4746. 3:42:42statement and throwing the exception but
  4747. 3:42:44let's assume from this piece of code it
  4748. 3:42:46is connecting to the DV or it is
  4749. 3:42:49connecting to the AWS S3 okay in that
  4750. 3:42:52case if that particular server is down
  4751. 3:42:54and your request is not able to process
  4752. 3:42:57then that is the wrong practice right
  4753. 3:42:59because you completely lost that input
  4754. 3:43:02what you received from your producer
  4755. 3:43:04because of because of your AWS failure
  4756. 3:43:06or because of your DV failure since this
  4757. 3:43:09is the simple scenario it's fine we are
  4758. 3:43:11just throwing the exception okay but
  4759. 3:43:13still we are losing the that particular
  4760. 3:43:16event or messages and we are not doing
  4761. 3:43:18anything with that so what we need to do
  4762. 3:43:21as for the presentation what we
  4763. 3:43:23understand we need to keep a retry we
  4764. 3:43:26need to tell to the capka hey can you
  4765. 3:43:29please retry for two or three times that
  4766. 3:43:31is what the number I will tell to you
  4767. 3:43:33once kapka will do the retry if within
  4768. 3:43:37that time period I mean let's say I have
  4769. 3:43:38defined for three if after three times
  4770. 3:43:42reattempt if it is able to resolve the
  4771. 3:43:44issue
  4772. 3:43:45then well and good if not if the ret
  4773. 3:43:48account exceed then it will simply push
  4774. 3:43:51that failed event or failed messages to
  4775. 3:43:55De letterer topic okay that is what we
  4776. 3:43:58just need to tell to the capka so we
  4777. 3:44:00need to tell to the capai about the
  4778. 3:44:02retry and if retry count exceed then
  4779. 3:44:05push the messages to the DT so that we
  4780. 3:44:08have a copy of our failed messages or
  4781. 3:44:10failed events so in future we can
  4782. 3:44:13investigate it and we can reprocess it
  4783. 3:44:15if required fine so just go back to the
  4784. 3:44:20code now here let me stop the
  4785. 3:44:24server so what you can do here simply
  4786. 3:44:27you can tell to the capka by defining
  4787. 3:44:30one
  4788. 3:44:31annotation retriable topic okay here you
  4789. 3:44:37can tell to the
  4790. 3:44:38capka how many attempts you want to
  4791. 3:44:41perform so you can Define I want to
  4792. 3:44:44retry
  4793. 3:44:45four times so by default attempt count
  4794. 3:44:48is three if you will not specify any
  4795. 3:44:50attempt kka will do three times attempt
  4796. 3:44:54now since I have defined the four capka
  4797. 3:44:57will do four times attempt I mean to the
  4798. 3:45:00same consumer will be keep executing for
  4799. 3:45:02four time okay so what will happen
  4800. 3:45:06internally capka will create three
  4801. 3:45:11topic just appending the suffix with
  4802. 3:45:15retry okay each topic will retry once
  4803. 3:45:19since we have defined there will be
  4804. 3:45:21three times rise attempt okay because as
  4805. 3:45:24I mentioned it will work on N minus one
  4806. 3:45:28order okay we'll test in a moment now
  4807. 3:45:31what next we are saying to the kapka by
  4808. 3:45:33defining this particular annotation
  4809. 3:45:35please enable retry mechanism for me and
  4810. 3:45:38I want to perform four times retry okay
  4811. 3:45:43now after four time four times retry if
  4812. 3:45:47the issue is not resolved what do you
  4813. 3:45:49want to perform we want to Simply push
  4814. 3:45:51that messages to dead letter topic right
  4815. 3:45:54so for that what you can do simply you
  4816. 3:45:57can define a
  4817. 3:46:00method
  4818. 3:46:04public then just copy the same header
  4819. 3:46:09because the event is
  4820. 3:46:12same just Define here now simply just
  4821. 3:46:16add a log
  4822. 3:46:18statement do info and just Define some
  4823. 3:46:25messages just add some meaningful
  4824. 3:46:30messages now what we have defined here
  4825. 3:46:33we are just saying what is the body and
  4826. 3:46:38what is the topic from where we are
  4827. 3:46:39listening and what is the offset count
  4828. 3:46:42okay so I can capture the entire body
  4829. 3:46:45but better to simplify the log statement
  4830. 3:46:48I'll just capture the
  4831. 3:46:51name
  4832. 3:46:53then
  4833. 3:46:55topic so this looks good now what next
  4834. 3:46:59we need to annotate this method with DT
  4835. 3:47:03Handler dead letter topic and Handler
  4836. 3:47:07this is what The annotation if you open
  4837. 3:47:09this annotation this is the empty
  4838. 3:47:12one fine so using this annotation we can
  4839. 3:47:16able to enable DT Logic for failure
  4840. 3:47:20message based on our Capa topic okay so
  4841. 3:47:24using this annotation this will listen
  4842. 3:47:27all the failed messages so looks good
  4843. 3:47:30now let me start the
  4844. 3:47:34application so it started If You observe
  4845. 3:47:37the console log carefully see here Java
  4846. 3:47:41group DLT this is the topic name
  4847. 3:47:45partition assign this and since as I
  4848. 3:47:48already mentioned for if you specify the
  4849. 3:47:51retry count for example go here ret
  4850. 3:47:54count if you'll specify four it will
  4851. 3:47:57create internally three topic to do the
  4852. 3:48:00reattempt okay can you see here Java
  4853. 3:48:04group retry zero this is one topic capka
  4854. 3:48:07error handle retry zero retry
  4855. 3:48:111 retry two can you see here now to just
  4856. 3:48:17visualize it in a better way what I'll
  4857. 3:48:19do I'll open the I'll just refresh this
  4858. 3:48:23capka upset
  4859. 3:48:26Explorer can you see here this is our
  4860. 3:48:29main topic or Target topic where you
  4861. 3:48:31want to push the messages and listen to
  4862. 3:48:34it then it created DT can you see here I
  4863. 3:48:38cannot maximize this let me try no I
  4864. 3:48:41cannot do that but you can see here
  4865. 3:48:43right then how many ret toic get created
  4866. 3:48:46guys 0 1 and two so the total count is
  4867. 3:48:51three here right that's super isn't it
  4868. 3:48:55now let's do one thing let's quickly
  4869. 3:48:57test this scenario let me rest okay we
  4870. 3:49:01already restarted it right now I'll go
  4871. 3:49:03to the
  4872. 3:49:05postman first let me clear this
  4873. 3:49:08console what I'll do I'll just use the
  4874. 3:49:12same messages but I'll just give some
  4875. 3:49:15valid IP so that I don't want to see any
  4876. 3:49:17error first time so just send the
  4877. 3:49:21request there is no error we got the
  4878. 3:49:25success
  4879. 3:49:26result this is the producer log this is
  4880. 3:49:29the consumer log now let me clear this
  4881. 3:49:33now let's try try with one failed
  4882. 3:49:36scenario I'll give the IP address which
  4883. 3:49:39is already restricted in my consumer
  4884. 3:49:42okay let's change it to
  4885. 3:49:45now let's observe carefully let me send
  4886. 3:49:48the
  4887. 3:49:51request see here it's doing the retry
  4888. 3:49:53then it throw the exception we'll verify
  4889. 3:49:55in the log itself
  4890. 3:49:57okay see here this is the first time it
  4891. 3:50:01received then it did the three times
  4892. 3:50:04retry to verify okay B you just showing
  4893. 3:50:07the log how can you get confirm that
  4894. 3:50:10these three log statement being execute
  4895. 3:50:13from the retri topic let me Zoom this
  4896. 3:50:16first then what we'll
  4897. 3:50:19do just go here because we are already
  4898. 3:50:23logging the topic name and offset name
  4899. 3:50:25right what is the topic name here guys
  4900. 3:50:29capka error handle retry zero capka
  4901. 3:50:32error handle retry one capka error
  4902. 3:50:36handle retry two so you tried three
  4903. 3:50:40times reattempt with three different
  4904. 3:50:43topic now again if you want to check or
  4905. 3:50:46if if you want to validate again go
  4906. 3:50:49simply to your topic
  4907. 3:50:52here just open the data you can see
  4908. 3:50:56here each since in the log we found each
  4909. 3:51:00topic retry topic receive the messages
  4910. 3:51:03from the upset you can validate that
  4911. 3:51:05directly in
  4912. 3:51:06the topic
  4913. 3:51:09itself can you see here fine now the
  4914. 3:51:14retry is succeeded after three try three
  4915. 3:51:17times it retried still we are not
  4916. 3:51:20getting any result it is failed can you
  4917. 3:51:24see here invalid IP address because
  4918. 3:51:27since we are simulating the error
  4919. 3:51:29scenario forcefully you'll get the error
  4920. 3:51:32messages but between that retry if your
  4921. 3:51:36DB connection or any aw specific infra
  4922. 3:51:39isue is being resolved then you'll get
  4923. 3:51:41the response I mean that is the happy
  4924. 3:51:43scenario since we are getting the error
  4925. 3:51:47after four times retry or after three
  4926. 3:51:50times retry then where suppose to the
  4927. 3:51:53message will
  4928. 3:51:54go to DT topic right so if You observe
  4929. 3:51:58here it created a topic capka error
  4930. 3:52:02handle DLT now let's validate message
  4931. 3:52:05went to this particular topic or not
  4932. 3:52:08just run it can you see
  4933. 3:52:12here this is the failed event went to
  4934. 3:52:15the particular
  4935. 3:52:18topic but if you'll send the not failed
  4936. 3:52:22event I mean not failure scenario
  4937. 3:52:25payload let's say
  4938. 3:52:26239 I'll keep sending the
  4939. 3:52:31request now if I
  4940. 3:52:34validate in the upset
  4941. 3:52:37Explorer no record right nothing will
  4942. 3:52:40come to DT because only dead letter top
  4943. 3:52:45will listen the failed events that is
  4944. 3:52:48what we are saying in the code and there
  4945. 3:52:50will be nothing in the
  4946. 3:52:51retry only
  4947. 3:52:54one good so it's working as expected
  4948. 3:52:58right now there is also you can play
  4949. 3:53:01with this retryable topic annotation now
  4950. 3:53:05continuously our retry is happening
  4951. 3:53:08right I mean there is no Gap but if you
  4952. 3:53:10want to set the attempt in every or in
  4953. 3:53:14some time interval you can do that you
  4954. 3:53:18can simply Define
  4955. 3:53:22backup okay then you can specify the
  4956. 3:53:26what is the delay you expecting and what
  4957. 3:53:28is the multiplier all these stops you
  4958. 3:53:30can
  4959. 3:53:33Define then what is the Marx
  4960. 3:53:38delay you can define those value this is
  4961. 3:53:41the number not integer for example I
  4962. 3:53:43will just Define 3,000 I mean 3 second
  4963. 3:53:48then multiply
  4964. 3:53:511.5 and Max delay could be
  4965. 3:53:5515,000 Max 15
  4966. 3:53:59second now this is how you can Define
  4967. 3:54:02the when you want to do the retry
  4968. 3:54:05attempt not if you don't want to do it
  4969. 3:54:07immediately if you want to specify your
  4970. 3:54:09own time interval you can Define this
  4971. 3:54:13now also you can tell to this retryable
  4972. 3:54:15topic for what kind of exception you
  4973. 3:54:19want to perform this retry now for
  4974. 3:54:23runtime exception if you don't want to
  4975. 3:54:25perform this retry what you can do
  4976. 3:54:27simply you can Define here please
  4977. 3:54:31exclude the retry for this
  4978. 3:54:35exception what is the exception name
  4979. 3:54:38null
  4980. 3:54:40pointer do class or I don't run for this
  4981. 3:54:44run exception right runtime
  4982. 3:54:46exception do class you can also control
  4983. 3:54:51for what exception you don't want to do
  4984. 3:54:54the retry okay you can exclude them for
  4985. 3:54:59this kind of exception there will be no
  4986. 3:55:01retry so it is up to you based on your
  4987. 3:55:04need you can configure
  4988. 3:55:06it fine so this is how you can override
  4989. 3:55:10the behavior of this retriable topic now
  4990. 3:55:13let's do one thing let's try to produce
  4991. 3:55:16bulk record and we'll see this
  4992. 3:55:18particular Behavior okay let's go to the
  4993. 3:55:21publisher I'll go to the controller
  4994. 3:55:24class so I have a csb file list of user
  4995. 3:55:28okay I mean I guess 100 is there there
  4996. 3:55:31is total 100 user object I want to load
  4997. 3:55:34this CSV file and we'll convert this
  4998. 3:55:37particular to list of object this
  4999. 3:55:40particular user in csb to list of user
  5000. 3:55:43object then we'll push one by one to our
  5001. 3:55:46publisher okay so it's a simple step I
  5002. 3:55:49have just written one util class to load
  5003. 3:55:53the CSV file and convert it to the list
  5004. 3:55:55of user
  5005. 3:55:56object then what I'll do I'll go to the
  5006. 3:56:00controller
  5007. 3:56:01class I'll will call this method to load
  5008. 3:56:04the csb data and convert it to the list
  5009. 3:56:08of user now simply what I'll do I'll
  5010. 3:56:10just use users. for each user
  5011. 3:56:16object then simply call
  5012. 3:56:22this now it will trigger 100 event out
  5013. 3:56:27of 100 event in my consumer I have
  5014. 3:56:30restricted four user IP address okay it
  5015. 3:56:36means out of 100 row 100 user object
  5016. 3:56:40four user will be discarded and we go to
  5017. 3:56:43the DLT okay when I say DT it is dead
  5018. 3:56:48letter topic okay now if You observe we
  5019. 3:56:51have only one record in our capka error
  5020. 3:56:55handle DT if I run it again only one
  5021. 3:56:58record now once I will execute this
  5022. 3:57:02there should be four more record which
  5023. 3:57:04need to add in this particular topic
  5024. 3:57:07okay so what we'll do because see the
  5025. 3:57:10simple thing guys whatever the IP I have
  5026. 3:57:12specified here see I have taken it from
  5027. 3:57:16this particular
  5028. 3:57:19csb
  5029. 3:57:20okay all the four are there I took from
  5030. 3:57:23here only now let's do one thing let's
  5031. 3:57:28rerun our
  5032. 3:57:31app okay let me stop
  5033. 3:57:34this because we need to it's fine we can
  5034. 3:57:37run it I mean what I supposed to do in
  5035. 3:57:40the controller class now I'm not giving
  5036. 3:57:43the input even though I'm giving that
  5037. 3:57:45input it doesn't make any sense anyway
  5038. 3:57:48at the end it will iterate the csb and
  5039. 3:57:51will push those messages what I'm giving
  5040. 3:57:54here is not being pushed so I supposed
  5041. 3:57:56to define a new endpoint saying get or
  5042. 3:57:58something like that but it's fine we can
  5043. 3:58:00play with the same because whatever the
  5044. 3:58:02value will give will not be used so fine
  5045. 3:58:05let me clear
  5046. 3:58:09this just go to the postman this you can
  5047. 3:58:13give any value okay this is not not
  5048. 3:58:15being used send the
  5049. 3:58:20request message publish
  5050. 3:58:23successfully now if you'll go and check
  5051. 3:58:25your
  5052. 3:58:27console can you see
  5053. 3:58:31here these are the messages from
  5054. 3:58:35producer okay and if you scroll
  5055. 3:58:39down these are the messages right 1 2 3
  5056. 3:58:434 5
  5057. 3:58:45is there any error let's
  5058. 3:58:48see invalid IP address
  5059. 3:58:51received it will do the retry can you
  5060. 3:58:54see here DT also received some messages
  5061. 3:58:58and if You observe here it did retry I
  5062. 3:59:00mean since there are 100 record it's not
  5063. 3:59:04easy to check the log to find out the
  5064. 3:59:07retry account and its validation now to
  5065. 3:59:10validate in a simple way see there are
  5066. 3:59:13lot of error right
  5067. 3:59:14DT received this just verify one thing
  5068. 3:59:17how many dted messages you have there in
  5069. 3:59:20your
  5070. 3:59:21console four right because we have only
  5071. 3:59:24four restricted IP address out of 100
  5072. 3:59:27whatever the file we have in the
  5073. 3:59:29csb we have here okay let me show you
  5074. 3:59:33here only four user IP address are not
  5075. 3:59:37correct so rest others should process
  5076. 3:59:39the result now to validate that go and
  5077. 3:59:43check in your up set Explorer just run
  5078. 3:59:46this can you see here 1 2 3 4
  5079. 3:59:495 this is the first record which we
  5080. 3:59:52added before executing This bul Record
  5081. 3:59:56then 1 2 3 4 with the same IP
  5082. 4:00:01address take anyone's IP and just check
  5083. 4:00:05in your
  5084. 4:00:10csb okay also check in your consumer
  5085. 4:00:14whether you have restricted for this
  5086. 4:00:15user or not can you see
  5087. 4:00:18here fine so whenever you are performing
  5088. 4:00:21the bulk upload kind of scenario using
  5089. 4:00:23capka you can do this kind of validation
  5090. 4:00:27using this ret template and for failed
  5091. 4:00:30event rather than losing those data
  5092. 4:00:33better to keep it in some different
  5093. 4:00:35topic and you don't need to create that
  5094. 4:00:37topic manually that will be Take Care by
  5095. 4:00:39capka by defining the simple annotation
  5096. 4:00:42DT Handler that is called dead letter
  5097. 4:00:45topic okay and everything will be Take
  5098. 4:00:48Care by capka so that you have the filed
  5099. 4:00:50messages with you you can play with them
  5100. 4:00:52or you can investigate with them in
  5101. 4:00:54future whenever it needed to process
  5102. 4:00:57those details so this is how you can
  5103. 4:01:00handle the error in capka using this DT
  5104. 4:01:04and retry mechanism
  5105. 4:01:12okay in in this tutorial we'll learn
  5106. 4:01:15about how to use abro schema to produce
  5107. 4:01:18and consume messages using spring boot
  5108. 4:01:20additionally we'll explore the concept
  5109. 4:01:22of schema registry what does it mean and
  5110. 4:01:25what benefits does it provide okay all
  5111. 4:01:28right let's assume I have a stable capka
  5112. 4:01:31producer and consumer application where
  5113. 4:01:33I'm sending employee details to a capka
  5114. 4:01:35topic and the consumer read it from the
  5115. 4:01:38capka topic and perform some further
  5116. 4:01:41operation this is a happy scenario of
  5117. 4:01:43pop up mechanism right but what if I
  5118. 4:01:46change the producer data if I change the
  5119. 4:01:49record to this new format where I'm
  5120. 4:01:52adding a new field called middle name
  5121. 4:01:54and I'm renaming one existing field
  5122. 4:01:57called email ID and I'm removing one
  5123. 4:01:59field called do now the problem starts
  5124. 4:02:02from here will my consumer work with
  5125. 4:02:05these new records the answer is no
  5126. 4:02:08because the consumer is not aare of data
  5127. 4:02:10changes and that's a big problem isn't
  5128. 4:02:13it if there is any changes in my data it
  5129. 4:02:16will directly impact all my consumer
  5130. 4:02:19which is not acceptable in real-time
  5131. 4:02:21implementation so how to overcome this
  5132. 4:02:24The Simple Solution is to write a new
  5133. 4:02:26producer and consumer application so
  5134. 4:02:28that new data will be produced and
  5135. 4:02:30consumed by the new instance without
  5136. 4:02:33impacting the existing flow however that
  5137. 4:02:36requires too much work and that is not a
  5138. 4:02:38feasible solution then again how to
  5139. 4:02:42solve this problem or how to handle data
  5140. 4:02:45changes or schema evalution so that's
  5141. 4:02:48where confident kapka introduced the
  5142. 4:02:50concept of abro schema and to store the
  5143. 4:02:53schema it has a component called schema
  5144. 4:02:55registry okay now let's go one step
  5145. 4:02:57ahead and understand what this abro
  5146. 4:03:00schema is how to use it and how to
  5147. 4:03:02handle schema Evolution then further
  5148. 4:03:05we'll understand how it works internally
  5149. 4:03:08so when I am saying Abu schema it's
  5150. 4:03:10nothing but a contract between your
  5151. 4:03:12producer and consumer it represents the
  5152. 4:03:15data that you are going to serialize
  5153. 4:03:17while producing and deserialize while
  5154. 4:03:20consuming now if I try to represent the
  5155. 4:03:22equivalent Abu schema of our record it
  5156. 4:03:25will look something like this now if You
  5157. 4:03:27observe carefully we are defining in
  5158. 4:03:29abro schema saying that okay these are
  5159. 4:03:32my fields which the producer will send
  5160. 4:03:35and the consumer will consume in case
  5161. 4:03:37the producer is not sending any of the
  5162. 4:03:39field or adding any of the new field
  5163. 4:03:42then there should not be any imp on the
  5164. 4:03:44consumer side also if any changes are
  5165. 4:03:47made to the schema it will be considered
  5166. 4:03:49as a new version okay that is what
  5167. 4:03:52called schema Evolution I have the
  5168. 4:03:55contract or schema with me now how can I
  5169. 4:03:58use it that's pretty simple once you
  5170. 4:04:01prepare the schema you need to generate
  5171. 4:04:03the corresponding object out from the
  5172. 4:04:05schema so you need to Define all the
  5173. 4:04:08field whether it is optional or
  5174. 4:04:10mandatory in your schema file then you
  5175. 4:04:13need to generate the abro object to
  5176. 4:04:16convert abro schema to abro object you
  5177. 4:04:19have multiple option you can directly
  5178. 4:04:21use the abro tool or you can use Maven
  5179. 4:04:24or gradel plugins to generate the object
  5180. 4:04:26for you once you have generated the abro
  5181. 4:04:29class then going forward you can use
  5182. 4:04:31this employee. Java as a data object
  5183. 4:04:34which you can produce and consume but
  5184. 4:04:37while producing this object we need a
  5185. 4:04:39serializer from the producer end we will
  5186. 4:04:42serialize the encoded message and send
  5187. 4:04:45them back to the capka topic so we can
  5188. 4:04:47use capka abro serializer similarly we
  5189. 4:04:51need a deserializer from the consumer
  5190. 4:04:53end who will deserialize abro encoded
  5191. 4:04:56message and convert them back to the
  5192. 4:04:58object so we can use capka abro der
  5193. 4:05:02serializer that's straightforward right
  5194. 4:05:04here capka abro serializer and der
  5195. 4:05:06serializer takes all the responsibility
  5196. 4:05:09of converting your encoded abro message
  5197. 4:05:12to the corresponding object and perform
  5198. 4:05:14the serialize and deserialize operation
  5199. 4:05:17that's interesting but where is the
  5200. 4:05:19validation part the encoded abro message
  5201. 4:05:21that my producer is sending whether it
  5202. 4:05:23matches to the schema I have defined or
  5203. 4:05:25not where are we validating it or how
  5204. 4:05:28does my deserializer this realize the
  5205. 4:05:30raw bites to an object without knowing
  5206. 4:05:32the schema that's the major part we need
  5207. 4:05:35to deal with to avoid failure on schema
  5208. 4:05:38Evolution right so that's where schema
  5209. 4:05:40registry comes into the picture what
  5210. 4:05:43schema registry does it store your
  5211. 4:05:45schema so when abro serializer serialize
  5212. 4:05:48the record it first validate and store
  5213. 4:05:51the schema into the registry then when
  5214. 4:05:53abro deserializer deserialize it first
  5215. 4:05:56takes the schema from the registry
  5216. 4:05:58validate it with the messages and then
  5217. 4:06:01deserialize it back to an object the
  5218. 4:06:03primary purpose of schema registry is to
  5219. 4:06:06provide a way to store retrive and
  5220. 4:06:08evolve the schema in a consistent manner
  5221. 4:06:11so in the future if I'm making any
  5222. 4:06:13changes to my existing schema it will
  5223. 4:06:16create a new version and store it into
  5224. 4:06:18the schema registry since schema
  5225. 4:06:21registry has the flexibility to support
  5226. 4:06:23both backward and forward compatibility
  5227. 4:06:26if any upgrade happens to the schema it
  5228. 4:06:28will support the old schema as well as
  5229. 4:06:30the new schema that is how it handle
  5230. 4:06:33schema Evolution hope this makes sense
  5231. 4:06:36to you no worries we'll do a handson
  5232. 4:06:38example with all the theories we
  5233. 4:06:41understand okay so without any further
  5234. 4:06:43delay let's get
  5235. 4:06:44[Music]
  5236. 4:07:04started so let's create a new project to
  5237. 4:07:07demonstrate this schema registry I'll
  5238. 4:07:09create a new
  5239. 4:07:11project then Define all the required
  5240. 4:07:17field click next then just Define all
  5241. 4:07:21required dependency I add web
  5242. 4:07:24dependency then I need Lum book
  5243. 4:07:28dependency then I need capka
  5244. 4:07:33dependency click
  5245. 4:07:36next now once it imported just go to the
  5246. 4:07:39pom.xml
  5247. 4:07:41and we'll validate that we have added
  5248. 4:07:43the web dependency and we added spring
  5249. 4:07:46capka and we added the lumo dependency
  5250. 4:07:50right and anything else no but why there
  5251. 4:07:54is
  5252. 4:07:55error okay it is saying stter parent
  5253. 4:07:593.2.2 not found okay let's downgrade it
  5254. 4:08:02to the
  5255. 4:08:043.2.1 let me update the
  5256. 4:08:07project now let me clear this next we
  5257. 4:08:11need to set up our capka environment so
  5258. 4:08:13you want to use the conflent capka you
  5259. 4:08:16can download the binary distribution and
  5260. 4:08:18you can start the Juke keeper capka
  5261. 4:08:20server service registry everything from
  5262. 4:08:23the command prompt but I would prefer
  5263. 4:08:24here to use the docker Compass file I
  5264. 4:08:27will just Define all the container I
  5265. 4:08:29need so that if I'll do the docker
  5266. 4:08:31compose of it will start all the
  5267. 4:08:33services for me okay so I'll just Define
  5268. 4:08:36the docker compose file in this root
  5269. 4:08:40directory then I can Define all the
  5270. 4:08:43services I need so if You observe here
  5271. 4:08:46let me Zoom this for you I need the Juke
  5272. 4:08:49keeper then I need the broker which is
  5273. 4:08:52nothing the capka server and then I need
  5274. 4:08:55the Capa tools so this Capa tools is
  5275. 4:08:59available for administrative task so you
  5276. 4:09:01can ignore it this is optional and I
  5277. 4:09:03need the schema registry so you
  5278. 4:09:06understand what is the role of schema
  5279. 4:09:07registry right so we need this schema
  5280. 4:09:09registry component who will store the
  5281. 4:09:11schema and validate with the encoded
  5282. 4:09:13message and we need the control center
  5283. 4:09:16so this is just a UI platform to monitor
  5284. 4:09:19your capka activity okay so this control
  5285. 4:09:23center depends on Juke keeper broker and
  5286. 4:09:25schema registry it collect all the
  5287. 4:09:28information from these three component
  5288. 4:09:30and mapped into the UI okay and it will
  5289. 4:09:32run on the port 9021 and these are the
  5290. 4:09:35environment variable of each Services
  5291. 4:09:37what I have defined okay no is I'll
  5292. 4:09:40share this GitHub code in the video
  5293. 4:09:41description you guys can to the same
  5294. 4:09:44file so now to start these Services we
  5295. 4:09:47need to start our Docker first right so
  5296. 4:09:49I'll just open my Docker desktop in my
  5297. 4:09:52local machine and once it will be start
  5298. 4:09:55then I can just trigger Docker compose
  5299. 4:09:57up so that all the services what I have
  5300. 4:09:59defined in this compos file will be up
  5301. 4:10:02and running for me and I can do the
  5302. 4:10:04further step with this confident Capa so
  5303. 4:10:07let's wait it to start so Docker is up
  5304. 4:10:10and running now now what I'll do I'll go
  5305. 4:10:12to the terminal Al so simply I will
  5306. 4:10:14trigger
  5307. 4:10:17Docker
  5308. 4:10:19compose hyen
  5309. 4:10:21D okay now if You observe it is just
  5310. 4:10:25starting my all the
  5311. 4:10:27services so if You observe it started
  5312. 4:10:30the Juke keeper capka tools then capka
  5313. 4:10:33server schema registry and control
  5314. 4:10:36center so to verify that whether it
  5315. 4:10:38started or not what I'll do I will just
  5316. 4:10:41check the port of my control center that
  5317. 4:10:43is
  5318. 4:10:459021 I'll go to the
  5319. 4:10:47browser and I'll will trigger
  5320. 4:10:509021 it's loading right so it means it
  5321. 4:10:53started so we are good here now what you
  5322. 4:10:56need to do we'll follow the same step
  5323. 4:10:59what we have discussed here first we'll
  5324. 4:11:01create the schema then using the mavin
  5325. 4:11:03plugin we'll generate the corresponding
  5326. 4:11:05abro class then we'll Define the
  5327. 4:11:07producer and consumer and we have
  5328. 4:11:09defined the serializer and deserializer
  5329. 4:11:11and schema registry okay okay so the
  5330. 4:11:13first step let's create the schema so
  5331. 4:11:17just go back to ID in the resource I
  5332. 4:11:19will create a folder called
  5333. 4:11:23abro then I need to define the schema
  5334. 4:11:26here okay so let me create a file called
  5335. 4:11:30employee dot
  5336. 4:11:34avsc so this do absc is the extension of
  5337. 4:11:38abro schema just create it then here you
  5338. 4:11:43you need to Define what is the package
  5339. 4:11:45where you want to keep your generated
  5340. 4:11:47class so just Define the package name
  5341. 4:11:50I'll define com dot
  5342. 4:11:52java. dto let me Zoom this for
  5343. 4:11:56you fine then next you need to Define
  5344. 4:12:00what is the type so you want to define
  5345. 4:12:03the abro record right so I'll Define the
  5346. 4:12:06type as a record now what what is the
  5347. 4:12:10class name you want to keep so from the
  5348. 4:12:12schema the class what it will generate
  5349. 4:12:15what what name you want to give okay so
  5350. 4:12:17the name I'll Define
  5351. 4:12:21employee next to that you need to Define
  5352. 4:12:24all the field which you want to produce
  5353. 4:12:26and consume so what you can do you can
  5354. 4:12:29Define fields that need to be one array
  5355. 4:12:32and you can Define all the field you
  5356. 4:12:34need so if you'll verify the field we
  5357. 4:12:37have defined ID first name last name
  5358. 4:12:40email and do so let's go to the ID I'll
  5359. 4:12:44Define the field name
  5360. 4:12:46is the first field name
  5361. 4:12:51is ID of
  5362. 4:12:55type it will be
  5363. 4:12:58string okay simple right now I will
  5364. 4:13:02Define another field let me copy the
  5365. 4:13:05same the field name is first name okay
  5366. 4:13:12and okay there is a spelling
  5367. 4:13:14mistake rst name of type string then the
  5368. 4:13:19next last
  5369. 4:13:22name type is
  5370. 4:13:25string then what
  5371. 4:13:27else first name last name email and date
  5372. 4:13:30of Worth right so Define the email
  5373. 4:13:35here up type string then D
  5374. 4:13:40OB up type string and also let me add
  5375. 4:13:43one additional field called age of type
  5376. 4:13:48int okay you can Define any data type
  5377. 4:13:52here string int double as for your
  5378. 4:13:55requirement okay also you want to keep
  5379. 4:13:58let's say I just want this email to be
  5380. 4:14:00optional so what I can do I can Define
  5381. 4:14:03here default value should be you can
  5382. 4:14:06define null or you can Define
  5383. 4:14:10empty okay so this is what the schema I
  5384. 4:14:13have defined this particular field my
  5385. 4:14:16producer will publish and my consumer
  5386. 4:14:18will consume it that's fine now next If
  5387. 4:14:21You observe the flow we have the abro
  5388. 4:14:23schema with us next we need to generate
  5389. 4:14:26the abro object by using the mavin
  5390. 4:14:28plugin okay so let's go to the ID and
  5391. 4:14:31we'll add all the required dependency
  5392. 4:14:33and
  5393. 4:14:34plugin so just go to the pal.
  5394. 4:14:37XML and then I will add all the required
  5395. 4:14:42dependency so if You observe here we
  5396. 4:14:44need the abro serializer let me Zoom
  5397. 4:14:46this for you and then we need the schema
  5398. 4:14:49registry and we need this abro object
  5399. 4:14:53okay then we just need to add the
  5400. 4:14:56plugin just add it
  5401. 4:14:59here just update
  5402. 4:15:01it so we are getting the error but it is
  5403. 4:15:04saying cannot resolve this dependency
  5404. 4:15:07okay so it is looking from the mavin
  5405. 4:15:10central repo to load these two depend
  5406. 4:15:13schema registry and abro serializer but
  5407. 4:15:16in Maven it is not available okay so
  5408. 4:15:19what I'll do I'll tell in the pum to
  5409. 4:15:22load it from the conflent repository
  5410. 4:15:26okay now if I'll just update
  5411. 4:15:31it there should not be any
  5412. 4:15:34error okay there is no error now if
  5413. 4:15:37you'll go to the plugin
  5414. 4:15:39section If You observe here in the
  5415. 4:15:42configuration
  5416. 4:15:43I am telling here this is what my source
  5417. 4:15:45directory where where you can find my
  5418. 4:15:48schema and this is what the output
  5419. 4:15:50directory where I want you to generate
  5420. 4:15:53the object for me okay and the version
  5421. 4:15:56of abro Maven plugin we are using
  5422. 4:16:001.8.2 so that's fine now let's run the
  5423. 4:16:03maven goal to generate the object for us
  5424. 4:16:07just go to the mavin run the
  5425. 4:16:11install so here here simply we are
  5426. 4:16:13telling to take the abro schema and
  5427. 4:16:16generate the abro object for us so the
  5428. 4:16:19build is succeed now to validate that
  5429. 4:16:21what we can do go to the main Java now
  5430. 4:16:25you can see here right there is a
  5431. 4:16:27package called D and this is what the
  5432. 4:16:31package name we have defined in our
  5433. 4:16:33schema can you see here the name space
  5434. 4:16:35or the package we want to generate the
  5435. 4:16:37abro object is this now if I'll open
  5436. 4:16:41this I can see the abro class now if I
  5437. 4:16:44open the employee. class let me Zoom
  5438. 4:16:46this for
  5439. 4:16:47you this class extends
  5440. 4:16:50from specific record base specific
  5441. 4:16:54record and this is are the schema what
  5442. 4:16:57we have
  5443. 4:16:58defined fine now if you'll scroll down
  5444. 4:17:01we will find all the field can you see
  5445. 4:17:04here ID first name last name email and
  5446. 4:17:08date of birth and age also you can find
  5447. 4:17:11the Constructor here this is your the
  5448. 4:17:13default Constructor and you can find the
  5449. 4:17:16getter and Setter method as well I mean
  5450. 4:17:18this is just a class generated by the
  5451. 4:17:21abro now we can use this particular
  5452. 4:17:24employee as a data object to perform the
  5453. 4:17:27producer I mean we can publish this
  5454. 4:17:29particular object and we can consume
  5455. 4:17:31this particular object so to do that
  5456. 4:17:34let's create one producer and consumer
  5457. 4:17:36application okay so what I'll do I'll
  5458. 4:17:39create a separate package here
  5459. 4:17:41itself and I'll create another for
  5460. 4:17:44Consumer so I'll just Define
  5461. 4:17:48package fine so let's create one
  5462. 4:17:51producer and consumer class but before
  5463. 4:17:54that let's verify the flow what we have
  5464. 4:17:56discussed we have we have the schema
  5465. 4:17:58with us and we created the employee.
  5466. 4:18:00Java class which is nothing the abro
  5467. 4:18:02record now we'll create the producer and
  5468. 4:18:05consumer then we'll Define the abro
  5469. 4:18:07serializer and deserializer and we'll
  5470. 4:18:09validate the schema registry I mean we
  5471. 4:18:12also need to give the configuration of
  5472. 4:18:13schema registry to store all the schema
  5473. 4:18:17okay so we are in the third step to
  5474. 4:18:19create the producer and consumer so just
  5475. 4:18:22go to the idea and then I'll just create
  5476. 4:18:24a class
  5477. 4:18:30here then just annotate here at theate
  5478. 4:18:34service then I just need to define the
  5479. 4:18:37capka template right
  5480. 4:18:40private capka template
  5481. 4:18:44of type you can Define string and of
  5482. 4:18:48object employee right that is what our
  5483. 4:18:50object abro object so I can define
  5484. 4:18:53template just do the auto
  5485. 4:18:55add then just Define the method public
  5486. 4:19:00board send something like that okay
  5487. 4:19:03Define the object what you want to send
  5488. 4:19:05employee this employe is not our object
  5489. 4:19:07right it's the abro object I mean you
  5490. 4:19:10can consider it as a abro record so to
  5491. 4:19:13do that I will just do Capa
  5492. 4:19:15template do
  5493. 4:19:18send what is the topic name we have not
  5494. 4:19:21defined the topic and we want this topic
  5495. 4:19:23to be autocreate so for that what I'll
  5496. 4:19:26do I'll just create a config
  5497. 4:19:28class or I'll just create a package
  5498. 4:19:30called
  5499. 4:19:31config then I'll Define class name capka
  5500. 4:19:36config so I just need to annotate this
  5501. 4:19:39with at theate
  5502. 4:19:41configuration then I'll just create the
  5503. 4:19:44topic I just need to create the B of
  5504. 4:19:47topic
  5505. 4:19:48public new topic this is the class name
  5506. 4:19:52okay now create topic I'll just Define
  5507. 4:19:56the method
  5508. 4:19:58name then
  5509. 4:20:01return see if You observe here you just
  5510. 4:20:04need to define the name of your topic
  5511. 4:20:06number of partition and replication
  5512. 4:20:08Factor so I'll will just Define the name
  5513. 4:20:11let's say Java
  5514. 4:20:14hyphen
  5515. 4:20:15abro and number of partition I want
  5516. 4:20:18three and replication factor I want one
  5517. 4:20:22so I can
  5518. 4:20:24Define
  5519. 4:20:26one just need to type c to
  5520. 4:20:30sort just annotate this at theate B let
  5521. 4:20:33me maximize this yeah Define at theate
  5522. 4:20:37ban now I don't want to hard code this
  5523. 4:20:39topic name here so what I want to do I
  5524. 4:20:43have the application. properties file or
  5525. 4:20:45I will just create a file called yml
  5526. 4:20:49file and here I can Define my topic name
  5527. 4:20:53okay so I'll Define
  5528. 4:20:55topic name equal to this so I want to
  5529. 4:20:59make it generic so I have defined the
  5530. 4:21:01topic name in my configuration I mean
  5531. 4:21:03the yml configuration and that I will
  5532. 4:21:05load in my config so you know how to
  5533. 4:21:08load the value from the properties file
  5534. 4:21:10right I'll just Define private
  5535. 4:21:14string topic
  5536. 4:21:16name I just need to annotate your at
  5537. 4:21:19theate
  5538. 4:21:20Value and I just need to get that value
  5539. 4:21:23from my yl file so just Define the
  5540. 4:21:25dollar and give the key what is the key
  5541. 4:21:28name topic dot
  5542. 4:21:31name that's it right so I no need to
  5543. 4:21:34hard code here I can use the topic
  5544. 4:21:38name same topic name I can use while
  5545. 4:21:41producing the messages
  5546. 4:21:43so here also I can use the topic from
  5547. 4:21:45the properties file so let me copy this
  5548. 4:21:51syntax I need this topic to publish the
  5549. 4:21:54messages and what data you want to
  5550. 4:21:57publish
  5551. 4:21:59employee
  5552. 4:22:01fine next I'll just capture the return
  5553. 4:22:04statement so that we can just add the
  5554. 4:22:07log statement what data you are sending
  5555. 4:22:09what is the offset count and everything
  5556. 4:22:10okay so this will give give you the
  5557. 4:22:13future
  5558. 4:22:14object can you see here this will return
  5559. 4:22:16the completable future now I'll take
  5560. 4:22:19that future object and I'll will just
  5561. 4:22:21get the result okay so this will be
  5562. 4:22:25employee nothing I'm just checking if
  5563. 4:22:27there is no exception print that okay
  5564. 4:22:30message has been sent to this this this
  5565. 4:22:32is what the message we have sent and
  5566. 4:22:33this is what the upset count but if
  5567. 4:22:35there is a error just print that unable
  5568. 4:22:37to send the messages okay that that is
  5569. 4:22:40the simple things we have done here now
  5570. 4:22:42let me Define the consumer let me copy
  5571. 4:22:45the name I'll go to the consumer
  5572. 4:22:48package create a new
  5573. 4:22:51class fine consumer is the simple one
  5574. 4:22:54what you need to do just Define The
  5575. 4:22:56annotation first to make it a component
  5576. 4:22:59Define service then you just need to
  5577. 4:23:02write a method to listen to the topic so
  5578. 4:23:05just Define
  5579. 4:23:06public
  5580. 4:23:08boid read
  5581. 4:23:11messages which type of messages it will
  5582. 4:23:13read let's say Define
  5583. 4:23:17consumer consumer
  5584. 4:23:19record of type key as a string value as
  5585. 4:23:22a
  5586. 4:23:25employee fine now I just need to tell to
  5587. 4:23:29this consumer from where he need to read
  5588. 4:23:31that messages okay so just annoted Capa
  5589. 4:23:34listener and just Define what is the
  5590. 4:23:38topics just tell that okay read it from
  5591. 4:23:42the topic what I have defined in my
  5592. 4:23:45properties file that is the reason I
  5593. 4:23:47move it to the properties file to make
  5594. 4:23:48it generic rather than hard code in each
  5595. 4:23:50and every place I have just defined it
  5596. 4:23:53in a single place okay so topic dot
  5597. 4:23:57name so we telling to this particular
  5598. 4:24:00listener to read the messages from topic
  5599. 4:24:03what I have defined and what what
  5600. 4:24:05messages it will read of type employee
  5601. 4:24:08so what we can do just add the log
  5602. 4:24:10statement okay to verify that SL
  5603. 4:24:13forj this we added from the lambo now
  5604. 4:24:16here I will simply first get the key are
  5605. 4:24:19you sending any key no we are not
  5606. 4:24:20sending any key right but still let's
  5607. 4:24:23capture it or we can pass it from the um
  5608. 4:24:26producer
  5609. 4:24:27itself consumer record do get
  5610. 4:24:32key what is the value we are
  5611. 4:24:35sending consumer record do
  5612. 4:24:39value so now we can just add a log
  5613. 4:24:41statement
  5614. 4:24:43just add the log statement abro message
  5615. 4:24:46received for the key is this and value
  5616. 4:24:48is employee right okay I have done the
  5617. 4:24:52mistake this this value should be of
  5618. 4:24:54type employee that is what we have
  5619. 4:24:56defined so this need to be
  5620. 4:24:58employee because this is what the value
  5621. 4:25:00you are getting right key is a string it
  5622. 4:25:03can be serialized and deserialized by a
  5623. 4:25:05string serializer or der serializer but
  5624. 4:25:08value is something object which is abro
  5625. 4:25:11object and it it needs to be serialized
  5626. 4:25:14and deserialized by the ab serializer
  5627. 4:25:16and der serializer so that we are going
  5628. 4:25:18to Define in a moment so this is what we
  5629. 4:25:21are
  5630. 4:25:22getting fine we have defined the
  5631. 4:25:25producer and we have defined the
  5632. 4:25:26consumer now let me Define a controller
  5633. 4:25:29so that I can trigger an event so just
  5634. 4:25:32create another
  5635. 4:25:35class just Define the package called
  5636. 4:25:39controller just annoted here at theate r
  5637. 4:25:44controller then you can define a I mean
  5638. 4:25:47you need to inject the
  5639. 4:25:50producer then just Define an end point
  5640. 4:25:53to trigger the I mean event to the cap
  5641. 4:25:56copy okay so I'll just Define public
  5642. 4:25:59[Music]
  5643. 4:26:01string what type of messages we want to
  5644. 4:26:04send
  5645. 4:26:05employee then you can simply Define your
  5646. 4:26:09producer dot send what is that employee
  5647. 4:26:15object and I can return some dummy
  5648. 4:26:18string
  5649. 4:26:21message and this need to be annoted at
  5650. 4:26:23theate request
  5651. 4:26:25body and I need to annoted here at theed
  5652. 4:26:29post mapping since I have the request
  5653. 4:26:30body and I'll Define the endpoint
  5654. 4:26:34events and this particular application I
  5655. 4:26:38want to run it in a different port so
  5656. 4:26:40I'll just Define
  5657. 4:26:47serverport let's say 9292 or let's take
  5658. 4:26:51some different number okay
  5659. 4:26:548 1 81 something like
  5660. 4:26:58that we are good now okay so if you
  5661. 4:27:02cross verify the flow we have created
  5662. 4:27:04the producer and consumer and now the
  5663. 4:27:07next step we need to Define what is the
  5664. 4:27:10serializer of my value what is the
  5665. 4:27:12deserializer of my value and then where
  5666. 4:27:15is my bootstrap server is up and running
  5667. 4:27:18everything I need to Define as a
  5668. 4:27:20configuration so what I can do I'll
  5669. 4:27:23prefer to Define in a application. yml
  5670. 4:27:25file you can also create a javab base
  5671. 4:27:27config class but I can Define here in
  5672. 4:27:30the yl file that is the easy approach
  5673. 4:27:33okay because I don't want more
  5674. 4:27:35customization so I just need to use the
  5675. 4:27:38producer and consumer config in the yml
  5676. 4:27:40file but if you need more configuration
  5677. 4:27:42I mean customization of more
  5678. 4:27:44configuration you need to go with the
  5679. 4:27:46javab base config approach so I need to
  5680. 4:27:48Define here
  5681. 4:27:49spring
  5682. 4:27:51capka producer first okay in the
  5683. 4:27:55producer first I need to Define where is
  5684. 4:27:58my bootstrap server I mean where is my
  5685. 4:28:00capka is running so where exactly it is
  5686. 4:28:03running you can
  5687. 4:28:06Define Local Host 9092 right that is
  5688. 4:28:10what usually we Define Local Host
  5689. 4:28:139092 so if You observe your Docker
  5690. 4:28:15compose
  5691. 4:28:17file go to the docker compose file the
  5692. 4:28:21bootstrap
  5693. 4:28:23server if you scroll yeah can you see
  5694. 4:28:26here this is what
  5695. 4:28:27your kka server right broker and it is
  5696. 4:28:31running on Port 9092 that is what we are
  5697. 4:28:33just defining here so just go to the ml
  5698. 4:28:39file 9092 but we are not running it in
  5699. 4:28:43our local we are running it in a Docker
  5700. 4:28:46so you need to give the default IP so my
  5701. 4:28:51default IP is 127 do 0 do 0 do
  5702. 4:28:581 colum
  5703. 4:29:009092 fine
  5704. 4:29:03now now I can Define the
  5705. 4:29:08serializer key serializer okay so the
  5706. 4:29:11key seral ier is the plain string I can
  5707. 4:29:14use this string serializer which is the
  5708. 4:29:16default given by the capka itself okay
  5709. 4:29:19but if I Define the value serializer I
  5710. 4:29:22cannot Define the Json D serializer here
  5711. 4:29:25I need to define the abro capka abizer
  5712. 4:29:29okay coming from the confluent that is
  5713. 4:29:32what we have discussed in our flow right
  5714. 4:29:34we need the capka abro serializer to
  5715. 4:29:38serialize my value to the topic so we
  5716. 4:29:41need to Define that so just Define the
  5717. 4:29:45class io. conf. kapka serializers can
  5718. 4:29:49you see the class name capka abro
  5719. 4:29:52serializer we are using this abro
  5720. 4:29:54serializer to take the encoded abro
  5721. 4:29:58messages and send it to the Capa opy so
  5722. 4:30:02we are good now also we need to define
  5723. 4:30:04the schema registry right so I'll just
  5724. 4:30:07define
  5725. 4:30:08properties
  5726. 4:30:10schema registry
  5727. 4:30:13now where is your schema registry is up
  5728. 4:30:15and running if you go to your Docker
  5729. 4:30:17compos file the registry is running on
  5730. 4:30:21Port
  5731. 4:30:238081 right so I need to Define
  5732. 4:30:27that
  5733. 4:30:30HTTP then your IP and your Port that is
  5734. 4:30:368081 and my IP is this
  5735. 4:30:38one fine this is where my schema
  5736. 4:30:41registry is stop and
  5737. 4:30:43run we are good now let's define the
  5738. 4:30:46consumer
  5739. 4:30:49configuration Now consumer also you need
  5740. 4:30:51to define the bootstrap server this are
  5741. 4:30:54the bootstrap server let me copy
  5742. 4:30:58this next here also if You observe in
  5743. 4:31:01the consumer part we need to Define d
  5744. 4:31:04serializer properties right so I can
  5745. 4:31:06Define here key der
  5746. 4:31:09serializer is the same that is my string
  5747. 4:31:12so I using the default Capa string der
  5748. 4:31:15serializer but value der serializer
  5749. 4:31:18should be from IO confl capka abro
  5750. 4:31:22realizer just Define that class we are
  5751. 4:31:25good here now next you need to Define
  5752. 4:31:29Auto offset reset you can Define it as
  5753. 4:31:33earliest or latest it is up to
  5754. 4:31:35you next in consumer also you need to
  5755. 4:31:39tell to that consumer okay where is your
  5756. 4:31:41schema registry up and running If You
  5757. 4:31:43observe the flow both abro serializer
  5758. 4:31:47and abro der serializer is connecting to
  5759. 4:31:49the schema registry right so you need to
  5760. 4:31:52give information about schema registry
  5761. 4:31:54to both your consumer and producer so we
  5762. 4:31:57have given here in the producer now same
  5763. 4:32:01let's give in the consumer so it need to
  5764. 4:32:05be inside the code so that's fine I'll
  5765. 4:32:09just define properties
  5766. 4:32:15next just Define one additional field
  5767. 4:32:18that is to tell to the consumer to read
  5768. 4:32:21the abro messages okay so there is
  5769. 4:32:24something
  5770. 4:32:26called
  5771. 4:32:28specific okay and
  5772. 4:32:32abro
  5773. 4:32:35reader equal to
  5774. 4:32:37true that's it okay so the main thing we
  5775. 4:32:41need to Def Define serializer and
  5776. 4:32:44deserializer that is what we want to
  5777. 4:32:46Define and also you just need to Define
  5778. 4:32:49about your schema registry so these are
  5779. 4:32:51the three component we are missing
  5780. 4:32:53serializer der serializer and schema
  5781. 4:32:55registry and these three we just
  5782. 4:32:57configured in this yl file okay but one
  5783. 4:33:01thing I observed here producer also need
  5784. 4:33:04this property bootstrap hyphen server
  5785. 4:33:06and consumer also need this property so
  5786. 4:33:08better let's not Define in both the
  5787. 4:33:10place I can Define it in
  5788. 4:33:14a global label in capka itself bootstrap
  5789. 4:33:19server this looks good so kapka having
  5790. 4:33:23the bootstrap server for both producer
  5791. 4:33:25and consumer and in producer we have
  5792. 4:33:27Define the focus on this value
  5793. 4:33:29serializer okay we have defined capka
  5794. 4:33:32abro serializer and we are telling to
  5795. 4:33:34the serializer about where is my schema
  5796. 4:33:37registry up and running so that he can
  5797. 4:33:39add the schema to this registry and and
  5798. 4:33:41we have the Der serializer and we are
  5799. 4:33:44telling the again about the schema
  5800. 4:33:46registry and we are telling that here
  5801. 4:33:48okay read the abro messages fine so we
  5802. 4:33:52are good here now let me close
  5803. 4:33:55everything just go to the
  5804. 4:33:59producer I just want to add a key okay
  5805. 4:34:02while sending the event I also want to
  5806. 4:34:05add a key up type let me Zoom this for
  5807. 4:34:08you up Type U ID I want to send some
  5808. 4:34:11random string okay random uid do2
  5809. 4:34:17string so while publishing the messages
  5810. 4:34:20I'm sending the key along with that I'm
  5811. 4:34:22sending the abro messages and if I'll
  5812. 4:34:25open the
  5813. 4:34:26consumer in consumer we are consuming
  5814. 4:34:29both key and value key is nothing the
  5815. 4:34:33string value is nothing my ab
  5816. 4:34:35messages and we have defined all the
  5817. 4:34:38component we understand in this
  5818. 4:34:40architecture fine so I believe we are
  5819. 4:34:42good let's start the application and
  5820. 4:34:44we'll see how it works so let's go to
  5821. 4:34:48the main
  5822. 4:34:49class just start the
  5823. 4:34:55application so we are getting some error
  5824. 4:34:58here what is the error okay no group ID
  5825. 4:35:01found in consumer config so that is what
  5826. 4:35:03the mistake we have done we have not
  5827. 4:35:05specify the group ID so I'll just add
  5828. 4:35:09group ID as a some some random Bel okay
  5829. 4:35:13Java
  5830. 4:35:15Tey
  5831. 4:35:17new all good let's restart it
  5832. 4:35:22now so we are good now if You observe in
  5833. 4:35:24the console the Java new is nothing my
  5834. 4:35:27consumer group assigned to this
  5835. 4:35:30particular topic javat abro with the
  5836. 4:35:33three partition 0 1 and two can you see
  5837. 4:35:36here let me clear this now I want to
  5838. 4:35:39verify the same thing in the control
  5839. 4:35:42center okay just go to the browser this
  5840. 4:35:45is where the 9021 is my control center
  5841. 4:35:48right now this is where the cluster if
  5842. 4:35:50I'll open this it should have our topic
  5843. 4:35:53info can you see here the topic name is
  5844. 4:35:56there java abro with the three partition
  5845. 4:35:59if I'll open this and if I'll check the
  5846. 4:36:02messages you won't find any messages
  5847. 4:36:04because you have not published
  5848. 4:36:06anything so there is nothing it's still
  5849. 4:36:09loading no messages right so so let me
  5850. 4:36:12keep a duplicate page of this particular
  5851. 4:36:15thing because until you are open to this
  5852. 4:36:18page you can see only those messages so
  5853. 4:36:20this is just a tool to monitor the event
  5854. 4:36:23whether it is going through your
  5855. 4:36:24producer and consumed or not for the
  5856. 4:36:27simple purpose now if I'll check the
  5857. 4:36:30schema
  5858. 4:36:31here I don't have any schema maap to
  5859. 4:36:33this particular topic so here when
  5860. 4:36:36schema will be added when it will be
  5861. 4:36:39serialized then only capka AB serialize
  5862. 4:36:42will push that particular schema to
  5863. 4:36:44schema registry that is what we
  5864. 4:36:46understand in the theory right let's
  5865. 4:36:48verify it so what I'll do I'll go to the
  5866. 4:36:51postman and what is the end
  5867. 4:36:54point let's verify in the controller
  5868. 4:36:56class go to the
  5869. 4:36:58controller events and what is the port
  5870. 4:37:01number 8181 I believe 8181 yeah go to
  5871. 4:37:05the
  5872. 4:37:06postman
  5873. 4:37:088181 events and what is the request body
  5874. 4:37:12we have lot of field let me add those
  5875. 4:37:24field so these are the field we have
  5876. 4:37:27defined in our schema okay so we can
  5877. 4:37:29only pass this field and then we'll play
  5878. 4:37:32with the schema Evolution once we'll go
  5879. 4:37:34through one happy
  5880. 4:37:35scenario just format it before I send
  5881. 4:37:38the request let's check the status of of
  5882. 4:37:41schema registry whether we'll verify
  5883. 4:37:44whether schema is added to the schema
  5884. 4:37:46registry or not okay how can I validate
  5885. 4:37:48that so the schema registry is running
  5886. 4:37:51on Port 8081 right first let me okay let
  5887. 4:37:55me
  5888. 4:37:568081 I want to get all the topic
  5889. 4:38:01name so topic is not created here not
  5890. 4:38:04sure why it's not showing in the schema
  5891. 4:38:05registry I believe after sending one
  5892. 4:38:08object it will show but okay let me
  5893. 4:38:10verify the latis
  5894. 4:38:13schema okay we cannot do that since the
  5895. 4:38:16topic is not showing here let me refresh
  5896. 4:38:17it nothing but topic is there right
  5897. 4:38:20that's fine let me trigger the
  5898. 4:38:26request can you see here we got the
  5899. 4:38:28success result message published now if
  5900. 4:38:31you check in your console send messages
  5901. 4:38:33this is from producer end these are the
  5902. 4:38:35information we are sending and it went
  5903. 4:38:37to the upset zero and this is from
  5904. 4:38:41consumer end can you see
  5905. 4:38:44here this is what theed message and this
  5906. 4:38:47is what the messages we send from the
  5907. 4:38:49producer now to validate that just go
  5908. 4:38:52here can you see here in the messages we
  5909. 4:38:55can see the
  5910. 4:38:56message this is what the messages we
  5911. 4:38:59have sent just now right and if you now
  5912. 4:39:01validate the schema just check the
  5913. 4:39:04schema you can see the schema here these
  5914. 4:39:07are the field you have defined right ID
  5915. 4:39:10first name last name Emil with the
  5916. 4:39:12default field date of birth age and the
  5917. 4:39:16abro class name package everything all
  5918. 4:39:18the schema we have Define is imported
  5919. 4:39:20here once the abro serializer is
  5920. 4:39:22serialized and send the event to the
  5921. 4:39:24topic now now let's verify the topic
  5922. 4:39:27name yeah can you see here the topic
  5923. 4:39:30name is this now to validate the schema
  5924. 4:39:33in the schema registry what you can do
  5925. 4:39:37Local Host 8081 subjects then topic name
  5926. 4:39:40what is the topic name copy
  5927. 4:39:43again just replace the topic
  5928. 4:39:48name can you see here let me Zoom this
  5929. 4:39:50for you subject is nothing the topic
  5930. 4:39:53name I mean the value as a suffix will
  5931. 4:39:56be appened by the kfka conflent and
  5932. 4:39:58version is one ID is 61 this is what the
  5933. 4:40:01schema we can see the schema in the
  5934. 4:40:03schema registry so we concluded that
  5935. 4:40:06schema registry has the schema
  5936. 4:40:08information while abro serializer
  5937. 4:40:10serialize it it added to the schema
  5938. 4:40:12registry and since we are able to
  5939. 4:40:14receive the messages from the consumer
  5940. 4:40:16and ab dis realizer dis realize it okay
  5941. 4:40:20and which version of schema we have the
  5942. 4:40:23current version is one because there is
  5943. 4:40:24no change this is the fres schema added
  5944. 4:40:27to the schema registry so this is the
  5945. 4:40:30happy scenario we validate right we can
  5946. 4:40:32able to produce the message and we can
  5947. 4:40:34able to consume the message by taking
  5948. 4:40:36the help of capka bro serializer and der
  5949. 4:40:38serializer and also we validate the
  5950. 4:40:40schema
  5951. 4:40:41in schema registry and we can able to
  5952. 4:40:44visualize the messages and everything
  5953. 4:40:45from the control center that's fine but
  5954. 4:40:49Our intention here to check the schema
  5955. 4:40:52evaluation related things so if I'm
  5956. 4:40:54doing any change on my producer data
  5957. 4:40:56whether it will impact to my consumer or
  5958. 4:40:59not that is what we want to verify and
  5959. 4:41:01that is why we are using this schema
  5960. 4:41:03registry so let's jump into the
  5961. 4:41:05presentation and then we'll perform
  5962. 4:41:08these schema changes when I say schema
  5963. 4:41:10changes we just want to do some
  5964. 4:41:13modification on our object which we want
  5965. 4:41:15to produce and consume so what we'll do
  5966. 4:41:19we'll remove the date of birth field and
  5967. 4:41:21age field and we'll rename this
  5968. 4:41:24particular field email to email ID in
  5969. 4:41:26our existing schema so just go to the
  5970. 4:41:31schema so the schema is employee.
  5971. 4:41:34absc here we want to remove the Dov and
  5972. 4:41:38age just remove
  5973. 4:41:40it and then I want to rename this email
  5974. 4:41:44to email
  5975. 4:41:45ID so we have done two changes here we
  5976. 4:41:48have removed two field do and age and we
  5977. 4:41:52rename one of the existing field now
  5978. 4:41:55let's see if I run the application
  5979. 4:41:57whether it will break my consumer or my
  5980. 4:42:00consumer will work as it is without any
  5981. 4:42:02impact okay that is what we want to
  5982. 4:42:04verify but since we have done the
  5983. 4:42:06changes on the schema we need to
  5984. 4:42:08regenerate the object abro object let me
  5985. 4:42:11stop the
  5986. 4:42:14application then just execute the mavin
  5987. 4:42:17goal
  5988. 4:42:19install so the build is succeed now to
  5989. 4:42:22validate whether those field are
  5990. 4:42:24excluded from our abro object generated
  5991. 4:42:27by the abro plugin we can go to the dto
  5992. 4:42:31and we can validate can you see here
  5993. 4:42:34those fields are not part of the Abra
  5994. 4:42:37object
  5995. 4:42:38now now let's run the application and
  5996. 4:42:41we'll trigger the end point to publish
  5997. 4:42:43the event then we'll validate whether
  5998. 4:42:46the consumer is working or it is giving
  5999. 4:42:48any error or exception okay so that is
  6000. 4:42:51the reason we are using schema registry
  6001. 4:42:53to manage the schema if I'm doing any
  6002. 4:42:56change on my produce object or abro
  6003. 4:42:59object okay so let's wait it to
  6004. 4:43:02complete so it started now I'll go to
  6005. 4:43:05the postman and I'll change the field
  6006. 4:43:09actually we have removed these two field
  6007. 4:43:10right d and and AG just remove it age
  6008. 4:43:13and do is removed and then this will be
  6009. 4:43:16email ID that is what the changes we
  6010. 4:43:18have done cool now let's trigger the
  6011. 4:43:23API we got the response message
  6012. 4:43:25published now if you'll go to the
  6013. 4:43:28console you can see here right ID first
  6014. 4:43:32name last name and email ID this is what
  6015. 4:43:35the object we have produced from the
  6016. 4:43:37producer and this is what the serialized
  6017. 4:43:40as part of the
  6018. 4:43:42capka abro serializer and then if You
  6019. 4:43:44observe here this are the message we
  6020. 4:43:46have received in the consumer end and in
  6021. 4:43:48both the place producer and consumer we
  6022. 4:43:50don't have those field now if you'll go
  6023. 4:43:53and check in the control
  6024. 4:43:56center if I'll go on schema if I'll come
  6025. 4:44:00back to the messages so message might
  6026. 4:44:03not be present here so I can retrigger
  6027. 4:44:05it to validate
  6028. 4:44:06that so just send the request
  6029. 4:44:10again
  6030. 4:44:13you can see the messages here
  6031. 4:44:15right those field is not part of the
  6032. 4:44:18messages
  6033. 4:44:19itself nothing is there right now if
  6034. 4:44:22I'll go and check the schema Let me
  6035. 4:44:25refresh this I'll come back to schema
  6036. 4:44:28again can you see here schema is also
  6037. 4:44:32updated ID first name last name email ID
  6038. 4:44:36now if you'll check the version history
  6039. 4:44:38there are two version the initial
  6040. 4:44:40version and second version in initial
  6041. 4:44:43version we have the fields right d age
  6042. 4:44:47and email but in the current version
  6043. 4:44:51those fields are not there so if you
  6044. 4:44:53want to compare you can click on this
  6045. 4:44:55turn on version difference and you can
  6046. 4:44:57see here these are the field has been
  6047. 4:45:01removed so you can see the red mark here
  6048. 4:45:04and the value is renamed you can see
  6049. 4:45:06this okay this is are the difference now
  6050. 4:45:09if you want to validate the the same
  6051. 4:45:11thing in the schema registry instead of
  6052. 4:45:13this control center UI just trigger this
  6053. 4:45:16request again can you see here the
  6054. 4:45:19version is two and the schema is this
  6055. 4:45:23this is are the latest schema okay I
  6056. 4:45:26have done the changes on the schema but
  6057. 4:45:29still my consumer is not breaking I'm
  6058. 4:45:31able to consume the messages even the
  6059. 4:45:33field has been removed from the payload
  6060. 4:45:35or abro messages itself so that is the
  6061. 4:45:38main purpose of using this schema
  6062. 4:45:40registry If You observe here it
  6063. 4:45:42maintains the schema history okay so it
  6064. 4:45:45maintains the different version of your
  6065. 4:45:47schema since it has the backward
  6066. 4:45:50compatibility it cross validate your
  6067. 4:45:52abro messages with all the schema
  6068. 4:45:55present in the schema registry now let's
  6069. 4:45:57do another changes and we'll validate
  6070. 4:46:00whether the schema evolution is working
  6071. 4:46:02with this particular implementation or
  6072. 4:46:04not so what changes when I say changes
  6073. 4:46:07let's add one more field okay so go go
  6074. 4:46:11to the project go to the schema I want
  6075. 4:46:14to add some field so as for the
  6076. 4:46:17discussion we need to add some different
  6077. 4:46:20field like middle name or something like
  6078. 4:46:21that okay so let me add that field first
  6079. 4:46:25name last name let me copy the
  6080. 4:46:27same and I want to
  6081. 4:46:30add middle
  6082. 4:46:33name now since I have done the changes
  6083. 4:46:35on the schema I need to rebuild the
  6084. 4:46:37project let me stop the capka I just
  6085. 4:46:41need to run the M install
  6086. 4:46:45again so you can see here build is
  6087. 4:46:48succeed now if I'll go to my dto class
  6088. 4:46:51and if I'll open it let me see whether
  6089. 4:46:54the field is added or
  6090. 4:46:56not yeah can you see here the middle
  6091. 4:46:59name is added here now let's do one
  6092. 4:47:01thing let's start the
  6093. 4:47:04server and we'll add this middle name as
  6094. 4:47:07part of our
  6095. 4:47:09payload
  6096. 4:47:12just
  6097. 4:47:13check okay it's still running let's writ
  6098. 4:47:17it to
  6099. 4:47:20complete yeah so it is started now let
  6100. 4:47:22me clear this and now what I'll do I
  6101. 4:47:26will trigger the request okay again we
  6102. 4:47:28have done the schema changes we have
  6103. 4:47:30added the new field which is not present
  6104. 4:47:33in my both the schema I mean schema
  6105. 4:47:35version one and two does not have the
  6106. 4:47:37information about this new field now
  6107. 4:47:39let's see whether it is working or we
  6108. 4:47:40are getting any error then we'll try to
  6109. 4:47:43find out the solution of it send the
  6110. 4:47:49request we are getting 5 internal server
  6111. 4:47:53error now if you go and check in your
  6112. 4:47:55console the error itself
  6113. 4:47:58self-explanatory invalid configuration
  6114. 4:48:00exception let me Zoom this for you
  6115. 4:48:03schema being registered is incompatible
  6116. 4:48:06with an earlier schema error code
  6117. 4:48:0949 it means means whatever the schema I
  6118. 4:48:12have with me and the value we you are
  6119. 4:48:15giving now is not compatible then how
  6120. 4:48:19can I make my schema as a comforable to
  6121. 4:48:22avoid this 49 error so what you can do
  6122. 4:48:26if you are adding any new field then
  6123. 4:48:29initially mark it as a
  6124. 4:48:33default okay then what you can do since
  6125. 4:48:36you have done the changes just build it
  6126. 4:48:38again then we'll start the server and
  6127. 4:48:40and
  6128. 4:48:42validate so build is succeed now let me
  6129. 4:48:45restart the
  6130. 4:48:46server so it started now go to the
  6131. 4:48:49postman and send the request
  6132. 4:48:52again the message has been published now
  6133. 4:48:55if you go and check in the messages can
  6134. 4:48:57you see the message here with the new
  6135. 4:49:01field middle name can you see here we
  6136. 4:49:04got the response now if Will validate
  6137. 4:49:06the schema
  6138. 4:49:08again version history there are total
  6139. 4:49:11three version in first version it was
  6140. 4:49:13the happy scenario we have all the field
  6141. 4:49:16in second version we have removed the do
  6142. 4:49:18and age and we rename email ID then
  6143. 4:49:21let's see what is there in the third
  6144. 4:49:23version third version we have just added
  6145. 4:49:26this field middle name now if you'll
  6146. 4:49:28compare it you can see this field is
  6147. 4:49:31newly added okay and we are not getting
  6148. 4:49:35any error so this is how schema registry
  6149. 4:49:38maintains the schema and valid against
  6150. 4:49:41the abro messages what you are producing
  6151. 4:49:44and what you are dis realizing or
  6152. 4:49:46consuming and this way you can avoid the
  6153. 4:49:49failure in the schema Evolution which
  6154. 4:49:51will not break your entire system okay
  6155. 4:49:54so this is what the straightforward
  6156. 4:49:55approach we have demonstrate about the
  6157. 4:49:57schema evalution using schema registry
  6158. 4:50:00and Abra producer and consumer
  6159. 4:50:03example that's all about this particular
  6160. 4:50:06video guys thanks for watching this
  6161. 4:50:09video meet you soon with A New
  6162. 4:50:14Concept

About this transcript

This page contains the full transcript of πŸš€ Apache Kafka Crash Course With Spring Boot 3.0.x | @Javatechie by Java Techie, generated from the public captions YouTube serves with the video. The transcript has 41,182 words across 6,162 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator β€” no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.