YouTube2Text

Capgemini Java Interview | Core Java, Spring Boot and Microservices — Transcript

by CloudTech · 4,479 words · 652 segments · language en · Watch on YouTube

Full transcript

  1. 0:03Hello. How are you?
  2. 0:05>> Hello. I'm fine, thank you. How are you?
  3. 0:08>> I'm good, thank you. So, can you tell me
  4. 0:11a little about your role and
  5. 0:13responsibilities in your project and
  6. 0:15your tech stack on which you are working
  7. 0:17on?
  8. 0:18>> Uh, yes. So I have around uh four years
  9. 0:21of experience working in IT industry and
  10. 0:23I've worked across various domains uh
  11. 0:26starting from banking, insurance uh then
  12. 0:28uh telecom, healthcare. So in this four
  13. 0:31years uh I've learned a lot about um
  14. 0:34Java, Spring Boot, microservices and uh
  15. 0:37my current roles and responsibilities uh
  16. 0:39is to add new use cases to the
  17. 0:42application. Uh try to resolve bugs if
  18. 0:45any and try to improve the performance
  19. 0:47of the application and uh our
  20. 0:50application text tag consists of uh
  21. 0:52Java. We are using Java 17 uh then
  22. 0:55spring boot. uh we are designing our
  23. 0:57applications in uh springboard and we
  24. 0:59are using microservices architecture and
  25. 1:02finally to deploy the application we are
  26. 1:04using um AWS uh specifically EC2 then
  27. 1:08for object-oriented storage S3 and the
  28. 1:10database that we are using is MySQL so
  29. 1:14that is a brief introduction about uh
  30. 1:16the project text stack
  31. 1:19>> okay so do you have hands-on experience
  32. 1:21on Java features or Java 8 features
  33. 1:25>> uh yes yes I have hands-on experience on
  34. 1:28these features.
  35. 1:29>> Okay.
  36. 1:30Okay. So, do you know what is
  37. 1:33immutability in Java?
  38. 1:36>> Uh yes, I know about uh immutability.
  39. 1:38So, uh immutability is where once you
  40. 1:41create the object, you cannot change
  41. 1:43that object. Uh the state of the object
  42. 1:45cannot be changed. So, that is uh
  43. 1:47immutable object and string is an
  44. 1:49example of immutable object. But uh we
  45. 1:51can also write our custom uh immutable
  46. 1:54classes.
  47. 1:58>> Okay. Now can you write some code which
  48. 2:01can demonstrate
  49. 2:02this use case? Let us consider I have to
  50. 2:05create a class uh which will be
  51. 2:07immutable. So you can create a class and
  52. 2:09tell me how can I make it immutable.
  53. 2:12>> Uh great. Okay. So there are a few cases
  54. 2:15uh there are few rules for creating
  55. 2:17immutable classes. So let's try to
  56. 2:19understand that the first thing is I'm
  57. 2:22going to uh create a class and the class
  58. 2:24name is going to be a uh student. Okay.
  59. 2:27So this is my class. I want to make this
  60. 2:29object of this class immutable. The
  61. 2:32first thing is I'll make this final. So
  62. 2:34this will prevent the subclassing. So I
  63. 2:37cannot uh I cannot subass this. I cannot
  64. 2:39create the child classes. So that is the
  65. 2:42first rule. The second rule is um I'm
  66. 2:44going to mark all the fields as private
  67. 2:47and final. So let's uh try to create
  68. 2:50private string uh name. So first thing
  69. 2:54is name. So private and final, right? Uh
  70. 2:58the second thing is I'm going to do
  71. 3:00private final again uh integer role
  72. 3:04number. Okay. And uh these are the two
  73. 3:07two fields uh private final string. And
  74. 3:10the third thing is I'm going to do is uh
  75. 3:13I'm going to add one subject list. So
  76. 3:16let's try to do private final uh list of
  77. 3:21string and I'm going to give the name as
  78. 3:25subjects. So private final is done. The
  79. 3:28third is uh I want I'm going to uh do
  80. 3:31the initialization only through the
  81. 3:33constructor. So let's try to create a
  82. 3:36constructor out of this. uh right click
  83. 3:39uh
  84. 3:40right click generate constructor I'm
  85. 3:43going to create all the fields right so
  86. 3:46this is how I'm going to initialize
  87. 3:48these uh fields so initialization is
  88. 3:51only possible through uh constructor I'm
  89. 3:55going to provide the getters for this
  90. 3:57but I'm not going to provide the setters
  91. 3:59so once the object is created I'm not
  92. 4:02going to change the value through
  93. 4:03setters so whatever fields whatever
  94. 4:06values you have to provide you have to
  95. 4:07provide only through uh the constructor.
  96. 4:10So let's provide the getters but not
  97. 4:11setters. Okay. So right click uh
  98. 4:15generate
  99. 4:17generate and I want to provide only
  100. 4:19getters. Okay. So I'm going to provide
  101. 4:21getters for all of this.
  102. 4:23Okay. Uh right. But uh I provided
  103. 4:27getters. I did not provide setter. But
  104. 4:29uh for uh for fields like list okay we
  105. 4:34are not going to directly pro send back
  106. 4:36the list itself. What we are going to do
  107. 4:38we are going to do the uh defensive copy
  108. 4:41of this and then send it back. So let's
  109. 4:43try to send it
  110. 4:45uh collections. Uh there is something
  111. 4:47called as unmodifiable list and to this
  112. 4:50unmodifiable list I'm going to pass our
  113. 4:53uh subject list. Okay. So
  114. 4:58subjects.
  115. 5:00Okay. So this is how I am going to
  116. 5:02return the unmodifiable list and not the
  117. 5:04actual list. So this subject cannot be
  118. 5:07changed by the uh client. So just to
  119. 5:09summarize uh the what are the rules. So
  120. 5:11the first rule is mark the classes final
  121. 5:13which we have already marked. Then to
  122. 5:16mark the fields as private and final
  123. 5:19which we have marked. Uh we are
  124. 5:20providing only getters. So no one can
  125. 5:23set the value. And we are uh
  126. 5:25initializing the values only using the
  127. 5:27constructor. Uh so we have done that.
  128. 5:29And uh the final thing is whenever there
  129. 5:32there is uh a list date so these kind of
  130. 5:35object copy of those object should be
  131. 5:37made and then returned back to the
  132. 5:39client. So this is how I'm going to
  133. 5:41create an immutable class in uh Java.
  134. 5:46>> Okay. Great. Now uh do one thing. take a
  135. 5:49list of numbers and try to find out the
  136. 5:52second largest number from that list.
  137. 5:54You have to use stream APIs from J.
  138. 5:58>> Okay. So I have to take a a list of
  139. 6:00number and uh then try to find the
  140. 6:03second highest from that uh list. Okay.
  141. 6:06>> Correct.
  142. 6:06>> So let me create a class uh second
  143. 6:11highest number and specifically I have
  144. 6:14to use the uh stream API, right?
  145. 6:18Yes, correct.
  146. 6:19>> Yeah. So, uh let's try to create a list
  147. 6:22of uh integer. Okay. I'm going to call
  148. 6:25this as numbers. Uh let me import the
  149. 6:29list. Importing is very important.
  150. 6:31Numbers equal to new sorry I'm going to
  151. 6:34uh initialize in one line only. So
  152. 6:36arrays dot um as list and uh I'm going
  153. 6:40to provide uh the values 10 20 uh 35
  154. 6:46then 35 then 50 then 40 some values.
  155. 6:50Okay, this is my list and the goal is to
  156. 6:53find the uh second highest uh number
  157. 6:55from this using stream API. So let's try
  158. 6:57to find this. So the first thing is uh
  159. 7:00numbers dot stream. Okay, once I get the
  160. 7:04stream, uh the first thing I'm going to
  161. 7:06do is uh there are repeated numbers 35
  162. 7:08and 35. So let's try to remove the uh
  163. 7:12repeated numbers
  164. 7:15dot distinct. The distinct will remove
  165. 7:17the uh duplicate numbers. Then as I have
  166. 7:20to find the second highest then I'm
  167. 7:23going to sort this in the descending
  168. 7:25order. So let's try to use sorted. uh
  169. 7:28and how do we want to sort this from uh
  170. 7:32from the largest number to the smallest
  171. 7:35number. So we are going to use
  172. 7:37comparator
  173. 7:39uh dot reverse order. Okay. So this will
  174. 7:43sort uh my list into descending order.
  175. 7:46And once I sort the list into the
  176. 7:48descending order, I'm going to skip the
  177. 7:50first element because I want to find the
  178. 7:52second highest number. So let's uh skip
  179. 7:55the first element. Okay, skip one and
  180. 8:00after skipping the uh first element,
  181. 8:03whatever is remaining from that list, I
  182. 8:06want to find the first element. So, how
  183. 8:07to how to find the first element? Find
  184. 8:11first. Okay. And if there is uh nothing
  185. 8:14in the list, then we are going to uh
  186. 8:17return null. Okay. So, let me try to
  187. 8:20explain the logic. First, we extracted
  188. 8:22the stream. Then, we uh did the distinct
  189. 8:25on it. So we remove the duplicate once.
  190. 8:28Then we sorted the list in the reverse
  191. 8:31order. That means our list will be
  192. 8:32sorted from highest element to the
  193. 8:35lowest element. Okay. And after sorting,
  194. 8:38we are skipping the first element
  195. 8:41because we want to find the second
  196. 8:42highest number. Okay. And then whatever
  197. 8:45is remaining from that list, we are
  198. 8:47trying to find the first element. Okay.
  199. 8:50Using find first. So let's try to take
  200. 8:53this into integer.
  201. 8:55uh second highest
  202. 8:59number
  203. 9:00equal to this right and I'm going to do
  204. 9:04uh system dot out dot print uh ln okay
  205. 9:13and the number itself the second highest
  206. 9:15uh number uh let me try to run this if
  207. 9:18I'm able to run this
  208. 9:24okay it's building
  209. 9:32H. So the second hash number is 40. If
  210. 9:35you see 10, 20, 30, 35, uh, 50 and 40.
  211. 9:39So 40 is the second highest. So this is
  212. 9:41how I'm going to find the second hash
  213. 9:43number.
  214. 9:45>> No. Okay, great. Uh, can you tell me
  215. 9:48what is functional interace in Java?
  216. 9:52>> Uh, yeah. So functional interface uh is
  217. 9:54an interface where we have only one
  218. 9:57method defined one abstract method
  219. 9:59defined and we annotate uh this uh
  220. 10:02interface with addit functional
  221. 10:03interface annotation. So if we have more
  222. 10:06than one abstract method then that is
  223. 10:09not a functional interface. So
  224. 10:11functional interface has only one and
  225. 10:12one abstract method uh which class can
  226. 10:14implement.
  227. 10:17>> Okay. Can you create one function
  228. 10:18interface and show me how to create a
  229. 10:21function interface? Yeah. So let me try
  230. 10:24to create a functional interface. I'm
  231. 10:26going to uh name this as um I print
  232. 10:32tableable. Okay. And uh
  233. 10:36uh public void print. Uh it's not
  234. 10:40necessary to add public but uh still I'm
  235. 10:43going to do public void print and I can
  236. 10:46annotate this with functional interface.
  237. 10:49Okay. So this is a functional interface.
  238. 10:50Now let's try to do one more thing.
  239. 10:52Let's try to I'll try to add one more
  240. 10:55method
  241. 10:57I printable and uh is printable.
  242. 11:03Okay, you see uh it's giving me an error
  243. 11:05because I can have only one abstract
  244. 11:07method. So if I remove this that error
  245. 11:10will be gone. So this is how I'm going
  246. 11:11to create a functional interface.
  247. 11:15>> Okay. So can I write static and default
  248. 11:18methods inside this interface? Uh yeah
  249. 11:21so writing default method and static
  250. 11:23method is possible in uh functional
  251. 11:25interfaces. The default methods are when
  252. 11:28um there are multiple classes
  253. 11:29implementing this interface and you want
  254. 11:31to introduce a method but you don't want
  255. 11:33to break the existing implementation of
  256. 11:36the classes. So that is where you write
  257. 11:38default methods and you can have a
  258. 11:41method bodies for default method and
  259. 11:43static method in the interface.
  260. 11:49Okay, great. Uh, how about Spring Boot?
  261. 11:53How much you are comfortable? If I ask
  262. 11:54you to rate ourself out of five, what
  263. 11:56would be your rating?
  264. 11:57>> Uh, yeah. So, I can give uh around four
  265. 12:00for spring boot.
  266. 12:02>> Okay. So, let us consider I have to
  267. 12:06create application employee management
  268. 12:08system where I have to perform four
  269. 12:11operations basically create, read,
  270. 12:13update and delete CL operations. Okay.
  271. 12:15So you have to tell me all the steps
  272. 12:17which will be required to perform these
  273. 12:19operations. You have to explain all the
  274. 12:21packages, all the layers, how you are
  275. 12:23going to connect with the database, what
  276. 12:25are the dependencies which will be
  277. 12:26required, how you are going to create
  278. 12:28the project, all the things which will
  279. 12:29be required to perform these four
  280. 12:31operations. Instead of four operations,
  281. 12:32you can take one operation but I need uh
  282. 12:34end to end flow. Can you explain me?
  283. 12:37>> Uh yeah. So uh I'm going to explain you.
  284. 12:40Uh the first thing is I'm going to
  285. 12:43create I'm going to go to spring.io. IO
  286. 12:45and uh try to create a spring boot
  287. 12:47project. Okay. And um uh I I'm going to
  288. 12:51download that and import it to my uh
  289. 12:53Eclipse or any ID IntelliJ Eclipse or
  290. 12:56any ID you want. So after that uh import
  291. 13:00I'm going to write the first layer that
  292. 13:02we have is a controller layer. So
  293. 13:04controller layer is essential for REST
  294. 13:07API and I'm going to annotate that uh
  295. 13:10controller layer with at the rest
  296. 13:12controller annotation. So this is where
  297. 13:14I can write methods which client can
  298. 13:16call from outside as a rest API. So I'm
  299. 13:19going to write four methods. One for um
  300. 13:22get, one for post, one for uh update and
  301. 13:25one for delete. So for get I'm going to
  302. 13:28use get mapping. For uh adding a new
  303. 13:31thing or for creating an entity I'm
  304. 13:32going to use post mapping. For updating
  305. 13:35an entity I'm going to use put mapping.
  306. 13:37And for deleting I'm going to use delete
  307. 13:39mapping. So this is my controller layer.
  308. 13:42And from this controller layer we
  309. 13:44generally call a service layer. So this
  310. 13:46service layer has all the business logic
  311. 13:49which we want to execute on that
  312. 13:51request. So service layer will uh
  313. 13:53include all the business logic or the
  314. 13:56business rules that we want to
  315. 13:57implement. And this service layer is uh
  316. 13:59annotated with additate uh service
  317. 14:02annotation. Okay. And from once you
  318. 14:05write all the business logic and uh you
  319. 14:07want to save something into the database
  320. 14:09then from service layer you call the
  321. 14:12repository layer. Okay. And this
  322. 14:13repository layer we specifically use JPA
  323. 14:16repository. Okay. So this JPA repository
  324. 14:19we call it from the service layer and it
  325. 14:21has all the operation for saving for
  326. 14:24updating and fetching the entity. Okay.
  327. 14:27And this JPA represent uh repository
  328. 14:29works on underlying entity. So what is
  329. 14:32the entity? For every table in your uh
  330. 14:35uh database in your database there is
  331. 14:38corresponding entity and we create a
  332. 14:41class with the fields for example
  333. 14:43student entity. So we have role number
  334. 14:45we have name we have uh class and we
  335. 14:49annotate this uh student entity with
  336. 14:52adderate entity annotation. Once we do
  337. 14:56all this, we also create a table in the
  338. 14:58database or we set a flag uh hbm to DDL
  339. 15:04or update. So what what that will do
  340. 15:07when you run the application uh that
  341. 15:09will create the table automatically if
  342. 15:11it does not exist in your uh database.
  343. 15:13So that is about the flow. But there is
  344. 15:15one more important thing uh in the if
  345. 15:18you want to connect to the database then
  346. 15:19you want to include u the JPA uh starter
  347. 15:25uh uh the J the JPA starter um
  348. 15:29what do we say starter uh package in
  349. 15:33your pom.xml. So that will bring all the
  350. 15:36uh required entities or all the required
  351. 15:38jars in your application and then we
  352. 15:40have to include the driver. So whatever
  353. 15:42database we are connecting to, we are
  354. 15:44connecting to MySQL database. So we need
  355. 15:46MySQL driver in your um application and
  356. 15:50after that we have to create
  357. 15:51application.properties
  358. 15:52and we have to give the location or the
  359. 15:54URL of the database, the username by
  360. 15:57which we are going to connect and the
  361. 15:59password. Okay. So this is how uh the
  362. 16:02flow is designed for CR application.
  363. 16:06>> Okay. Can you tell me the annotations
  364. 16:09which will be required for
  365. 16:11implementation of this uh student
  366. 16:14management system or employee management
  367. 16:16system?
  368. 16:17>> Okay. So annotations you want
  369. 16:19annotations.
  370. 16:21>> Uh yes annotations basic annotations
  371. 16:24which will be required for implementing
  372. 16:25this flow.
  373. 16:26>> Okay. So the first annotation is uh add
  374. 16:28the rate uh rest controller for writing
  375. 16:31my controllers. Okay. Then I need add
  376. 16:34the rate uh service add the rate
  377. 16:36repository for writing my repositories.
  378. 16:38Add the rate spring boot application for
  379. 16:41my main uh main class. Add the rate
  380. 16:43entity for my uh entities. Add the
  381. 16:46generated value for my uh primary keys.
  382. 16:50Okay. And if I'm creating some custom
  383. 16:52beans then add the red bean uh for that
  384. 16:55or at the method level. And uh if I'm
  385. 16:57creating a generic component then add
  386. 16:59the red uh component. Okay. So this and
  387. 17:02then a few more annotations um enable
  388. 17:05discovery client if I'm creating uh
  389. 17:08discovery server and so on and so forth.
  390. 17:10So these are a few annotations that I've
  391. 17:12used.
  392. 17:13>> Okay. Do you know add direct auto direct
  393. 17:17request body annotation?
  394. 17:18>> Yeah. So I know about add autoire. So at
  395. 17:22the rate autowire tries to find a bean
  396. 17:25uh in your application context and then
  397. 17:27it finds the object of that bean and
  398. 17:29assigns that object uh to the field
  399. 17:32which is autodired. Uh I don't have much
  400. 17:35idea about uh the response body request
  401. 17:38body.
  402. 17:41Okay. Okay. Fine. Not an issue.
  403. 17:45Uh let's move to the next question. So
  404. 17:47uh now we are done with the floor right
  405. 17:51now where do you deploy this
  406. 17:52application?
  407. 17:54>> Yeah. So to deploy this application uh
  408. 17:56we are using EC2 machines on AWS. So AWS
  409. 18:00is Amazon web services. We have set of
  410. 18:02dedicated machines for this uh and we
  411. 18:05deploy our application to that EC2
  412. 18:07instance.
  413. 18:11>> Okay. Can you tell me the steps which
  414. 18:13will be uh required for the deployment
  415. 18:15process? Yeah. So there are few steps
  416. 18:18which we want. Uh so the first step is
  417. 18:21we want to uh dockerize the application.
  418. 18:24Okay. So let's let's try to understand
  419. 18:25how to dockerize the application. So the
  420. 18:27first thing we want is we want Maven. So
  421. 18:30uh MBN clean install or MBN package
  422. 18:34whatever command you want to use. Uh
  423. 18:35this will create a jar out of it. Okay.
  424. 18:38But uh we want to dockerize the
  425. 18:40application first. So there is a concept
  426. 18:42of docker file. We create a docker file
  427. 18:44in the application. uh which which can
  428. 18:46be used to create the image out of your
  429. 18:49application. So how do we create the
  430. 18:50image? We use uh docker build and then
  431. 18:54uh docker build dot. So this is how we
  432. 18:56create the image out of our application.
  433. 18:59Once the image is created then we take
  434. 19:01this image and uh push the image to the
  435. 19:04docker repository using docker push.
  436. 19:07Okay. So that this image becomes
  437. 19:09available to everyone uh once it is in
  438. 19:12the into the docker repository. And
  439. 19:14whenever you want to uh use that image
  440. 19:16uh we docker pull and uh then we uh do
  441. 19:20docker run. So whenever we do docker run
  442. 19:22on an image a docker docker container is
  443. 19:25spin spin up. So you can say uh the
  444. 19:27container is started from the image.
  445. 19:29Okay. Uh so this is how we uh do it. But
  446. 19:32how how we do uh into the EC2
  447. 19:35environment, we upload the jar into the
  448. 19:38EC2 environment which is uh where we
  449. 19:40have docker installed and uh we run the
  450. 19:43uh docker run command there and it it
  451. 19:46spins up the docker container on that
  452. 19:48EC2 machine and then our application is
  453. 19:50uh deployed to the uh EC2 and we use
  454. 19:54CI/CD for building the application and
  455. 19:56transferring the jar to the EC2 machine.
  456. 19:59So this is how we uh do the deployment.
  457. 20:03No. Okay. So you must be having a
  458. 20:06different environments like t stage prod
  459. 20:10right?
  460. 20:11>> Uh yeah we have different environments
  461. 20:12in the applications. Yes.
  462. 20:16>> So do you know the profiles in spring
  463. 20:18boot?
  464. 20:19>> Yeah. So profile is uh uh an important
  465. 20:23concept in spring boot. And uh if you
  466. 20:25want to create uh uh different set of
  467. 20:28beans for different sets of environment
  468. 20:30then we can use uh profiles. Okay. So uh
  469. 20:34how it works? Okay. In the development
  470. 20:35environment sometimes we use H2 database
  471. 20:38and in the testing environment we want
  472. 20:40mocking and in the production
  473. 20:41environment we want the actual actual
  474. 20:44run and connecting to the database. So
  475. 20:45how we handle this? We handle this with
  476. 20:48the uh use of profiles. Okay. So we
  477. 20:51create different classes and we annotate
  478. 20:54them with different profiles. For
  479. 20:55example, dev
  480. 20:57uh QA
  481. 20:59and production. Okay. And how do we say
  482. 21:02which profile is active? There are
  483. 21:04various ways to say which profile is
  484. 21:06active. We can say through um uh
  485. 21:09application.properties uh spring
  486. 21:12profile.active equal to dev. So a dev
  487. 21:15profile will be activated and all the
  488. 21:17beans which are corresponding to dev
  489. 21:19profile will be uh initialized during
  490. 21:22startup. If uh we want to give uh uh
  491. 21:25this active profile through a different
  492. 21:29um way uh so we can also give through
  493. 21:31the environment variable or uh we can uh
  494. 21:35give through command line parameters. So
  495. 21:36we can activate the profile using these
  496. 21:39three methods. So this is how we use
  497. 21:41profiles in the spring boot application.
  498. 21:48Now okay great uh now you mentioned you
  499. 21:53are using microservices based
  500. 21:54architecture so what are the components
  501. 21:56you have used from microservices
  502. 21:58architecture
  503. 22:00>> yeah so we have used uh various
  504. 22:02components uh one of them is API gateway
  505. 22:05uh then we have used uh service
  506. 22:07discovery uh then uh after service or
  507. 22:10database per service uh we have used uh
  508. 22:14then uh we have also used uh CQRS in our
  509. 22:18application. Okay. So these are a few
  510. 22:20things which we have used in the
  511. 22:22application.
  512. 22:25>> Okay. What is the purpose of uh API
  513. 22:28gateway or how do you configure or which
  514. 22:30API gateway you are using in your
  515. 22:32application?
  516. 22:33>> Yeah. So our application so generally
  517. 22:36what happens in microservices
  518. 22:37environment there are various components
  519. 22:39uh various microservices we can say
  520. 22:41there are consider we have three
  521. 22:42microservices microservices A and C okay
  522. 22:47so uh if if we give address of these
  523. 22:50microservices to the client then there
  524. 22:52there is a problem because tomorrow if
  525. 22:54we want to uh increase the number of uh
  526. 22:57instances of these microservices or add
  527. 22:59new microservices then we have to give
  528. 23:01those addresses to the client
  529. 23:03But um with the introduction of API
  530. 23:06gateway this problem is resolved. What
  531. 23:07we do? All the microservices will be
  532. 23:10behind this API gateway. So any
  533. 23:12communication from outside to the
  534. 23:14microservices will go through the API
  535. 23:16gateway. So API gateway is an entry
  536. 23:19point uh to the application. Okay. So if
  537. 23:21client wants to make any request, it
  538. 23:24will make a request to the API gateway
  539. 23:26and API gateway will in turn call the
  540. 23:29microservices depending upon uh the uh
  541. 23:32URL. Okay. So this is a single entry
  542. 23:34point and uh there are few common things
  543. 23:36which we can do in API gateway. For
  544. 23:39example, we can uh do rate limiting, we
  545. 23:42can do authentication and uh
  546. 23:44authorization and we can do logging. uh
  547. 23:47we can try to do some kind of uh
  548. 23:49analysis how many requests are coming.
  549. 23:52So all this common logic uh we put in
  550. 23:54API gateway and we use Netflix zuul.
  551. 23:58This is old but we use Netflix. There
  552. 24:00are uh new versions or new things which
  553. 24:03we can use. We can use Kong, we can use
  554. 24:06uh APG or uh we can use some other
  555. 24:10frameworks. So but we are using Netflix
  556. 24:12tool for the application.
  557. 24:15No. Okay.
  558. 24:18And what about service discovery?
  559. 24:21Do you know what is meant by service
  560. 24:23discovery?
  561. 24:24>> Yeah. So service discovery um as we have
  562. 24:27many microservices and each microser can
  563. 24:30have several instances. Okay. And
  564. 24:32consider one microser wants to call or
  565. 24:35communicate with other microser. In that
  566. 24:37case what will happen? We need address
  567. 24:39of that microser. Okay. And finding the
  568. 24:41address is very difficult uh if we keep
  569. 24:43on hard coding it. So that is the reason
  570. 24:46service discovery comes into picture.
  571. 24:48How it works?
  572. 24:50We have microservices and whenever uh we
  573. 24:53uh start a microser. So during startup
  574. 24:56that microser registers itself to the
  575. 25:00service discovery and service discovery
  576. 25:03knows where that microser is running on
  577. 25:06which host it is running and on which
  578. 25:08port it is running. Okay. So service
  579. 25:10discovery is like a index where it has
  580. 25:13all the details about all the running
  581. 25:15microservices and about their instances.
  582. 25:17Okay. So uh consider this scenario. Now
  583. 25:21microser A wants to call microser B.
  584. 25:24Then what will microser A do? Microser A
  585. 25:27will go to service discovery and ask uh
  586. 25:31give me the instance or give me the
  587. 25:32address of microser B. Then service
  588. 25:35discovery will return back the address
  589. 25:37of microser B. And then this address
  590. 25:40will be used to communicate uh to
  591. 25:42establish the communication between
  592. 25:44microser A and microser B. Okay. So uh
  593. 25:47there are few um there are few libraries
  594. 25:51which we can use. Uh we can use either
  595. 25:54ureka or we can use console. These are
  596. 25:58two things which we can use. Uh so we
  597. 26:01are using ureka. Okay. And then uh there
  598. 26:04are a few annotations uh at the rate um
  599. 26:06enable discovery client if you want to
  600. 26:09enable discovery server if you want to
  601. 26:11disco enable the server side of the uh
  602. 26:14we want to say that this is the server
  603. 26:15and this is the uh client. So this is
  604. 26:18how uh service discovery works.
  605. 26:26No. Okay. Okay. Fine. and how services
  606. 26:29communicates with each other.
  607. 26:32>> Uh so services communicate with each
  608. 26:34other. Uh there are two types of
  609. 26:36communication. One is synchronous
  610. 26:38communication and one is a asynchronous
  611. 26:39communication. So synchronous
  612. 26:41communication is either through rest
  613. 26:43template or through fine client and
  614. 26:46asynchronous communication is either
  615. 26:48through Kafka or message MQ rabbit MQ.
  616. 26:52So through one of the message broker or
  617. 26:54event broker. So uh let's try to
  618. 26:56understand about synchronous
  619. 26:58communication. So uh we can do
  620. 27:00synchronous communication through rest
  621. 27:02template rest template exchange method
  622. 27:05and we can uh specify the uh type of
  623. 27:08method we want to call either post, get,
  624. 27:11put or delete. Okay. But there is one
  625. 27:13better way of doing it through fine
  626. 27:15client. So find client is where we
  627. 27:17create an interface uh and uh we
  628. 27:20annotate that interface and we say about
  629. 27:23the service name that we are referring
  630. 27:24to and we give one method and this
  631. 27:27method will contain all the parameters
  632. 27:29that we want to pass to the uh rest API
  633. 27:32and the return type. Okay. So once we
  634. 27:36write the interface now if you want to
  635. 27:38call the interface we directly call uh
  636. 27:39the method of that interface and that
  637. 27:41underlying service call is automatically
  638. 27:44made. So that is how we do uh call uh
  639. 27:48the service through fine client. And if
  640. 27:50you want to do a a synchronous
  641. 27:52communication then we use either Kafka
  642. 27:54or uh rabbit MQ and uh uh then the uh
  643. 27:58service we are calling to subscribe to
  644. 28:01the uh Kafka topic and fetch the
  645. 28:05messages or fetch the events uh from the
  646. 28:09Kafka. So that is how the communication
  647. 28:11happens.
  648. 28:13>> No. Okay. Good. So, I'm done from my
  649. 28:16side. Do you have any questions for me?
  650. 28:18>> Uh, no. Thank you. Thanks for your time.
  651. 28:22>> Yeah. Thank you. Thanks. Bye-bye.
  652. 28:23>> Thanks. Bye-bye.

About this transcript

This page contains the full transcript of Capgemini Java Interview | Core Java, Spring Boot and Microservices by CloudTech, generated from the public captions YouTube serves with the video. The transcript has 4,479 words across 652 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.