YouTube2Text

Microservices with Kafka: ECommerce Example (.NET 8) — Transcript

by Code Overdose · 1,827 words · 336 segments · language en · Watch on YouTube

Full transcript

  1. 0:00hello everyone welcome to code
  2. 0:02overdose in this video I will show you
  3. 0:05how to implement a microservice
  4. 0:07architecture inet 8 using the message
  5. 0:10broker Kafka I will use an example of an
  6. 0:14e-commerce app if you don't know what
  7. 0:16microservice architecture is comment
  8. 0:19below to let me know and I will make
  9. 0:21another video for
  10. 0:23you now you can see this overview of our
  11. 0:26solution our solution will have two
  12. 0:29services product service and Order
  13. 0:31service each using different databases
  14. 0:35and capable of making API calls to each
  15. 0:37other in this sample I will use Entity
  16. 0:40framework code first and SQL server for
  17. 0:43these Services these two services will
  18. 0:46use Kafka to produce and consume
  19. 0:49messages additionally there will be one
  20. 0:52web app to show the interface which will
  21. 0:55call the apis from the product service
  22. 0:57and Order
  23. 0:58service okay before we start creating
  24. 1:01the solution don't forget to subscribe
  25. 1:03to get the latest content and now let's
  26. 1:15start now let's create a
  27. 1:19project first of all we will create a
  28. 1:22web frontend project using Blazer web
  29. 1:27app name it e-commerce do web
  30. 1:33and set the solution name to
  31. 1:36e-commerce choose the target.
  32. 1:42net8 next we will create a product
  33. 1:47service search API and create a web
  34. 1:54API I will name it e-commerce
  35. 1:57productservice
  36. 2:02then create another web API for the
  37. 2:04order
  38. 2:07service and name it e-commerce do
  39. 2:10orderservice
  40. 2:19add a library to store our
  41. 2:26models and name it e-commerce dood
  42. 2:34to run this I will add a project.net
  43. 2:37Aspire app
  44. 2:47host and name it e-commerce app
  45. 2:51host now we have the basic folder
  46. 2:54structure for our microservice
  47. 2:56architecture solution in the apphost
  48. 2:59project open
  49. 3:01program.is we will configure our project
  50. 3:03here first I will configure the product
  51. 3:15service we need to add a project
  52. 3:18reference to see the options
  53. 3:20here apphost should have references to
  54. 3:23the web product service and Order
  55. 3:25service projects
  56. 3:30the rest of the projects should have
  57. 3:31references to the model
  58. 3:48library now we can add the product
  59. 3:50service
  60. 3:58project then add the same for the order
  61. 4:01service
  62. 4:10project next add the web frontend
  63. 4:26project with references to product
  64. 4:29service service and Order
  65. 4:35service let's set startup project to
  66. 4:38apphost and run
  67. 4:47it I will open each project to check for
  68. 4:51any errors
  69. 5:00it seems to be working okay
  70. 5:02now next let's create some model for
  71. 5:06product and order I will change the name
  72. 5:08to product
  73. 5:13model and product should have integer
  74. 5:18ID string
  75. 5:23name decimal price
  76. 5:29integer
  77. 5:33quantity and another for order
  78. 5:44model should have integer
  79. 5:48ID string customer
  80. 5:53name integer product ID
  81. 6:00integer
  82. 6:05quantity and datetime Order
  83. 6:14date now let's create DB context for
  84. 6:17product service I will create a
  85. 6:20folder name it data and create a
  86. 6:26class name it product DB contact
  87. 6:33to use Entity framework I will install
  88. 6:36Entity framework
  89. 6:39package search
  90. 6:47Entity and install package Entity
  91. 6:49framework
  92. 6:53core and entityframework core. SQL
  93. 6:57Server
  94. 7:03now it can inherit DB
  95. 7:09context and create a Constructor for
  96. 7:23it run
  97. 7:26database ensure created to autocreate
  98. 7:29dat
  99. 7:31database and create a DB set for product
  100. 7:39model then let's init some data for
  101. 7:41products by override on model
  102. 7:48creating I will put some initial data
  103. 7:50for it
  104. 8:28then go to program and add DB context
  105. 8:31for product DB
  106. 8:42context have option use SQL server and
  107. 8:45put the connection string into
  108. 8:49it here I use SQL Express and set
  109. 8:53database name is e-commerce product
  110. 9:02then create a controller to return a
  111. 9:04list products create an empty API
  112. 9:07controller name it product
  113. 9:13controller let's inject product DB
  114. 9:16context by primary
  115. 9:24Constructor and create an HTTP get
  116. 9:27method
  117. 9:30return list product
  118. 9:36model have name get
  119. 9:40products and return list of
  120. 9:50products let's run to check that our
  121. 9:52product service doesn't have any errors
  122. 10:00open product API let's execute API get
  123. 10:03list
  124. 10:05product great it return a list of
  125. 10:08initial products then I will create
  126. 10:10another DB context for order
  127. 10:20service name it order DB
  128. 10:25context then install the package like we
  129. 10:28do in product service
  130. 10:43now it can inherit DB
  131. 10:47context create Constructor
  132. 11:05create DB
  133. 11:12set then go to program and add DB
  134. 11:22context and the option use SQL server
  135. 11:25with database name e-commerce order
  136. 11:37then create an empty API
  137. 11:42controller name it order
  138. 11:52controller let's inject order DB
  139. 11:57service and create an API I to return
  140. 12:00list of
  141. 12:25orders let's run app again to check it
  142. 12:28doesn't have any errors
  143. 12:38great it returns success
  144. 12:43200 now I will create a page to show
  145. 12:46list of products where the user can see
  146. 12:49and buy a product in Pages folder create
  147. 12:52a razor component name it product list
  148. 13:01Define the root is
  149. 13:06products defin a list
  150. 13:18products and override uninitialized
  151. 13:26async and get product here by inject
  152. 13:29HTTP
  153. 13:37client and get from Json
  154. 13:54async to get the path of product service
  155. 13:57let's go to properties folder
  156. 13:59in launch settings you can copy the
  157. 14:01https
  158. 14:05address then put it in
  159. 14:11here about the UI of products list I
  160. 14:15will use bootstrap card for it search
  161. 14:18bootstrap
  162. 14:23card and I will copy this
  163. 14:39I will for each list of product and each
  164. 14:41product will be displayed as a
  165. 14:52card it will show product name
  166. 15:05price
  167. 15:09quantity and button
  168. 15:15by and remove this style let's run to
  169. 15:18see
  170. 15:25it we have a list of products here
  171. 15:29when I click by I want to go to the cart
  172. 15:32page where we can create an
  173. 15:37order in Pages folder create a razor
  174. 15:40component name it cart.
  175. 15:46Riser Define the route is
  176. 15:52cart and have param product
  177. 15:57ID then Define par
  178. 15:59product
  179. 16:06ID and defined a model for
  180. 16:17order and another model for
  181. 16:27product override uninitialized async and
  182. 16:31set product ID for
  183. 16:41order then get product information by ID
  184. 17:21I will create a simple form here
  185. 17:38it will have an input for customer name
  186. 18:02an input for showing product
  187. 18:11name and an input for
  188. 18:17quantity now we don't have an API to get
  189. 18:20product info by ID let's create it in
  190. 18:23product
  191. 18:27controller create create a HTTP get
  192. 18:30allowed to pass
  193. 18:46ID and return the product map with that
  194. 18:48ID
  195. 19:07then go to product list and set the URL
  196. 19:09when click buy button to cart SL product
  197. 19:21ID okay let's run it now
  198. 19:34Click
  199. 19:35by we missing a button to create the
  200. 19:45order I will add button here
  201. 20:03and it will call an HTTP post to order
  202. 20:05service to create an
  203. 20:22order let's copy the URL of order
  204. 20:24service
  205. 20:48if the API returns success I will alert
  206. 20:50an success message
  207. 21:13let create an API to create order in
  208. 21:16order
  209. 21:20service create a hhtp post
  210. 21:34set order date and saving it
  211. 22:00it should be JJ's
  212. 22:04runtime let's run it
  213. 22:14again let's create a new
  214. 22:18order set customer name and
  215. 22:23quantity it shows success
  216. 22:33I will create a page to show a list of
  217. 22:43orders I will copy from product
  218. 22:52list set route is orders
  219. 23:03change to order and fix the
  220. 23:24URL I will create a table to show order
  221. 23:27information for
  222. 24:24then create another link to navigate to
  223. 24:26the list of orders
  224. 24:41we have one order
  225. 24:44here but the quantity of the product has
  226. 24:47not changed because this information
  227. 24:49comes from the product service so when
  228. 24:52order service creates a new order it
  229. 24:54should send a message to product service
  230. 24:57then product service can update the
  231. 24:59quantity of that product we will use
  232. 25:01Kafka to produce and consume the
  233. 25:03messages here when finish creating an
  234. 25:07order we can produce a message here but
  235. 25:10you must run Kafka Client First I will
  236. 25:13use Docker to run it so make sure you
  237. 25:15have Docker desktop on your machine in
  238. 25:18apphost Project create a file name it
  239. 25:21Kafka diml
  240. 25:29here I config two
  241. 25:35Services one is Zookeeper use image from
  242. 25:38confluent Inc have Port
  243. 25:412181 and one is Kafka use image from
  244. 25:45confluent Inc also have port
  245. 25:489092 and set some environment variable
  246. 25:50to connect Kafka to zookeeper then let's
  247. 25:53start the docker desktop
  248. 26:00and open the terminal from App
  249. 26:04host and run Docker compose file name
  250. 26:13up the container will be created
  251. 26:26now you can see the log of Kafka the
  252. 26:30Kafka client work okay
  253. 26:34now then I will create a Kafka producer
  254. 26:37in order
  255. 26:41service create a folder
  256. 26:47Kafka and create a class name it Kafka
  257. 26:55producer create an interface
  258. 27:07and add scope for
  259. 27:20it it will have a function produce a
  260. 27:23sync allowed to pass topic and Kafka
  261. 27:25message
  262. 27:33we need to install confluent Kafka
  263. 27:48package and message with type string and
  264. 27:51string
  265. 28:00Define a field eye
  266. 28:11producer and in
  267. 28:14Constructor Define a consume
  268. 28:24config have group ID is Order Group
  269. 28:32bootstrap servers is address of CFA
  270. 28:37client set auto offset reset to
  271. 28:45earliest then use producer Builder
  272. 29:00then just return prodor async
  273. 29:07function in order service let's inject
  274. 29:11iafa
  275. 29:15producer then we can use produce a sync
  276. 29:20function set the topic is order topic
  277. 29:33and message have key is order
  278. 29:37ID and value is Json order
  279. 29:53model I will set a debugger here
  280. 30:07create a new
  281. 30:11order press F10 to go to the next
  282. 30:15step if it passes this step it will
  283. 30:18successfully push the message to
  284. 30:23Kafka now I will create a Kafka consumer
  285. 30:26in product service to consume that
  286. 30:29message create folder
  287. 30:32Kafka and create a class name it kofka
  288. 30:41consumer it should be inherited
  289. 30:43background service so it will run when
  290. 30:45the app starts let's Implement abstract
  291. 30:50class then add hosted service for it
  292. 31:00defined a function name it consume
  293. 31:05async allow to pass topic and
  294. 31:08cancellation
  295. 31:14token Define a config like we do for
  296. 31:17Kafka producer and use consumer
  297. 31:23Builder consumer will subcribe the topic
  298. 31:29then we need a while loop to get consume
  299. 31:41result then we can get the message from
  300. 31:43that
  301. 31:46topic and convert it to order model
  302. 32:01to use product DB context to update the
  303. 32:04product to DB we need to inject service
  304. 32:07scope
  305. 32:10Factory then create a
  306. 32:18scope and get required service product
  307. 32:21DB context
  308. 32:30find the
  309. 32:37product and update the
  310. 32:56quantity then close the
  311. 33:01consumer I will put some debugger
  312. 33:12here and execute async should return
  313. 33:15task
  314. 33:20run call the function consume a
  315. 33:25sync set topic is order
  316. 33:30topic now let's run the
  317. 33:41app press F10 to go to the next
  318. 33:49step you can see it received the
  319. 33:51previous message now let's continue
  320. 33:58and you can see the quantity have been
  321. 34:00updated now I will create a new order to
  322. 34:05test clear the debugger every time order
  323. 34:09service vve produce a message the
  324. 34:11product service will receive the message
  325. 34:13and handle it right
  326. 34:17away and the quantity has been updated
  327. 34:20wonderful in a real project before
  328. 34:23updating the quantity we would have a
  329. 34:25lot of steps to check but in in this
  330. 34:28sample I just want to show you the flow
  331. 34:30to implement it if you have any
  332. 34:32questions about this please comment
  333. 34:35below I will reply to you as soon as
  334. 34:38possible thanks for watching and see you
  335. 34:40in the next video
  336. 34:43[Music]

About this transcript

This page contains the full transcript of Microservices with Kafka: ECommerce Example (.NET 8) by Code Overdose, generated from the public captions YouTube serves with the video. The transcript has 1,827 words across 336 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 choose a caption track available on the video.

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, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.