-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicroservices_Tutorial.html
More file actions
2018 lines (1993 loc) · 162 KB
/
Microservices_Tutorial.html
File metadata and controls
2018 lines (1993 loc) · 162 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="generator" content="pandoc">
<meta name="description" content="">
<title>Microservices_Tutorial</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="https://maxcdn.bootstrapcdn.com/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="https://mushiyo.github.io/pandoc-toc-sidebar/css/dashboard.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">.sidebar ul{padding-left: 10px;} .sidebar{background-color: #dadada;}</style>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div id="sidebar" class="col-sm-3 col-md-2 sidebar">
<!--<ul class="nav nav-sidebar">
<li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li>
</ul>-->
<ul>
<li><a href="#microservices-tutorial"
id="toc-microservices-tutorial">Microservices Tutorial</a>
<ul>
<li><a href="#web-service" id="toc-web-service">Web
Service</a></li>
</ul></li>
<li><a href="#building-rest-api"
id="toc-building-rest-api">Building REST API</a>
<ul>
<li><a href="#advanced-rest-api-features"
id="toc-advanced-rest-api-features">Advanced Rest API
Features</a></li>
</ul></li>
<li><a href="#microservicesv1"
id="toc-microservicesv1">Microservices(V1)</a></li>
<li><a href="#microservicesv3"
id="toc-microservicesv3"><strong>Microservices(V3)</strong></a>
<ul>
<li><a href="#ports-and-urls" id="toc-ports-and-urls">Ports
and URLs</a>
<ul>
<li><a href="#standardized-ports"
id="toc-standardized-ports">Standardized Ports</a></li>
<li><a href="#standardized-local-urls"
id="toc-standardized-local-urls">Standardized Local
URLs</a></li>
<li><a href="#hosted-urls" id="toc-hosted-urls">Hosted
URLs</a></li>
<li><a href="#devops-hosted-urls"
id="toc-devops-hosted-urls">Devops Hosted URLs</a></li>
<li><a href="#architecture---currency-microservice"
id="toc-architecture---currency-microservice">Architecture -
Currency Microservice</a></li>
</ul></li>
<li><a href="#currency-config-repository"
id="toc-currency-config-repository">Currency Config
Repository</a></li>
<li><a href="#config-server-microservice"
id="toc-config-server-microservice">Config Server
Microservice</a></li>
<li><a href="#limits-microservice"
id="toc-limits-microservice">Limits Microservice</a></li>
<li><a href="#currency-exchange"
id="toc-currency-exchange">Currency Exchange</a></li>
<li><a href="#currency-conversion"
id="toc-currency-conversion">Currency Conversion</a>
<ul>
<li><a href="#feign-client-integration"
id="toc-feign-client-integration">Feign Client
Integration</a></li>
</ul></li>
<li><a href="#eureka-naming-server"
id="toc-eureka-naming-server"><strong>Eureka Naming
Server</strong></a></li>
<li><a href="#load-balancing-with-eureka"
id="toc-load-balancing-with-eureka"><strong>Load Balancing
with Eureka</strong></a></li>
<li><a href="#spring-cloud-api-gateway"
id="toc-spring-cloud-api-gateway"><strong>Spring Cloud API
Gateway</strong></a>
<ul>
<li><a
href="#auto-routing-with-cloud-gateway-discovery-locator"
id="toc-auto-routing-with-cloud-gateway-discovery-locator">Auto
Routing with Cloud Gateway Discovery Locator</a></li>
<li><a
href="#custom-routing-and-custom-filter-for-specific-api"
id="toc-custom-routing-and-custom-filter-for-specific-api">Custom
Routing and Custom Filter for specific API</a></li>
<li><a href="#gateway-global-filters"
id="toc-gateway-global-filters">Gateway Global
Filters</a></li>
</ul></li>
<li><a href="#circuit-breaker--resilience4j"
id="toc-circuit-breaker--resilience4j"><strong>Circuit
Breaker- Resilience4j</strong></a></li>
<li><a href="#observability-and-opentelemetry"
id="toc-observability-and-opentelemetry"><strong>Observability
and OpenTelemetry</strong></a></li>
<li><a href="#zipkin---distributed-tracing"
id="toc-zipkin---distributed-tracing"><strong>Zipkin -
Distributed Tracing</strong></a>
<ul>
<li><a href="#connecting-zipkin-with-other-microservices"
id="toc-connecting-zipkin-with-other-microservices">Connecting
Zipkin with other Microservices</a></li>
</ul></li>
<li><a href="#docker---container-orchestration"
id="toc-docker---container-orchestration">Docker - Container
Orchestration</a>
<ul>
<li><a href="#create-docker-image"
id="toc-create-docker-image">Create Docker Image</a></li>
<li><a href="#docker-compose" id="toc-docker-compose">Docker
Compose</a></li>
</ul></li>
<li><a href="#logging---elk-stack"
id="toc-logging---elk-stack"><strong>Logging - ELK
Stack</strong></a></li>
<li><a href="#kubernetes"
id="toc-kubernetes">Kubernetes</a></li>
</ul></li>
<li><a href="#todo" id="toc-todo">#TODO</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 id="microservices-tutorial">Microservices Tutorial</h1>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="#web-service">Web Service</a></li>
<li><a href="#building-rest-api">Building REST API</a></li>
<li><a href="#microservicesv1">Microservices(V1)</a></li>
<li><a href="#microservicesv3"><strong>Microservices(V3)</strong></a>
<ul>
<li><a href="#ports-and-urls">Ports and URLs</a></li>
<li><a href="#currency-config-repository">Currency Config
Repository</a></li>
<li><a href="#config-server-microservice">Config Server
Microservice</a></li>
<li><a href="#limits-microservice">Limits Microservice</a></li>
<li><a href="#currency-exchange">Currency Exchange</a></li>
<li><a href="#currency-conversion">Currency Conversion</a></li>
<li><a href="#eureka-naming-server"><strong>Eureka Naming
Server</strong></a></li>
<li><a href="#load-balancing-with-eureka"><strong>Load Balancing with
Eureka</strong></a></li>
<li><a href="#spring-cloud-api-gateway"><strong>Spring Cloud API
Gateway</strong></a></li>
<li><a href="#circuit-breaker--resilience4j"><strong>Circuit Breaker-
Resilience4j</strong></a></li>
<li><a href="#observability-and-opentelemetry"><strong>Observability and
OpenTelemetry</strong></a></li>
<li><a href="#zipkin---distributed-tracing"><strong>Zipkin - Distributed
Tracing</strong></a></li>
<li><a href="#docker---container-orchestration">Docker - Container
Orchestration</a></li>
<li><a href="#logging---elk-stack"><strong>Logging - ELK
Stack</strong></a></li>
<li><a href="#kubernetes">Kubernetes</a></li>
</ul></li>
<li><a href="#todo">#TODO</a></li>
</ul>
<p><strong>Tech Stack :</strong></p>
<p><img src="https://pbs.twimg.com/profile_images/1235868806079057921/fTL08u_H_400x400.png" alt="Spring Boot (@springboot) / X" style="zoom: 33%;" />
<img src="https://static.javatpoint.com/tutorial/spring-cloud/images/spring-cloud.png" alt="Spring Cloud Tutorial - Javatpoint" style="zoom: 50%;" />
<img src="https://miro.medium.com/v2/resize:fit:486/1*mwUghPGDjdVNOe8y7Pkrpg.png" alt="Implementing Service Discovery Using Netflix Eureka | by Seonggil Jeong | Medium" style="zoom: 33%;" />
<img src="https://content.cdntwrk.com/files/aHViPTYzOTc1JmNtZD1pdGVtZWRpdG9yaW1hZ2UmZmlsZW5hbWU9aXRlbWVkaXRvcmltYWdlXzY0MjYxYmY1NzQ0ODEucG5nJnZlcnNpb249MDAwMCZzaWc9NDBhNTg4NmQ3ZGFjMzliZmY2ZDQ3Y2JhMjU5MTlhNTA%253D" alt="Announcing Spring Cloud Gateway for Kubernetes 2.0" style="zoom: 40%;" />
<img src="https://avatars.githubusercontent.com/u/11860887?v=4" alt="GitHub - openzipkin/zipkin: Zipkin is a distributed tracing system" style="zoom:25%;" />
<img src="https://i.postimg.cc/Px3XB3VL/res.png" alt="Knoldus Blogs Java - Introduction To Resilience4j" style="zoom: 50%;" />
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS5hPnQgYIb2fp0KenorFRSOXY268hay_nISrnJtv-6ng&s" alt="Docker full logo transparent PNG - StickPNG" style="zoom: 70%;" />
<img src="https://sue.eu/wp-content/uploads/sites/6/2022/06/kubernetes-logo-920x920-sue-v0.png" alt="Kubernetes | SUE Cloud & IT Professionals" style="zoom: 16%;" />
<img src="https://avatars.githubusercontent.com/u/20077752?s=64&v=4" alt="OpenFeign · GitHub" style="zoom: 25%;" />
<img src="https://howtodoinjava.com/wp-content/uploads/2019/12/spring-hateoas.png" alt="Spring Boot HATEOAS Links Example" style="zoom: 25%;" />
<img src="https://miro.medium.com/v2/resize:fit:720/1*FNJ6C1uNvCAhkJR3i7pvoQ.jpeg" alt="Hystrix + Spring Boot Implementation | by Vinesh | The Jabberjays | Medium" style="zoom: 35%;" />
<img src="https://camo.githubusercontent.com/c9c03fc8fd1261971c38aafd0b95f59eee0af2b435277586949579dfe8b5198d/68747470733a2f2f692e696d6775722e636f6d2f6d52536f7345702e706e67" alt="GitHub - Netflix/zuul: Zuul is a gateway service that provides dynamic routing, monitoring, resiliency, security, and more." style="zoom: 12%;" /></p>
<p><a
href="https://www.udemy.com/course/microservices-with-spring-boot-and-spring-cloud/?couponCode=UPGRADE02223">Udemy
Course Link</a></p>
<p><img src="images/roadmap1.png" alt="" style="zoom: 67%;" /></p>
<p><img src="images/roadmap2.png" alt="" style="zoom: 67%;" /></p>
<h2 id="web-service">Web Service</h2>
<blockquote>
<p><strong>Definition : </strong> Software system designed to support
interoperable machine-to-machine interaction over a network.</p>
</blockquote>
<ul>
<li><p><strong>3 Keys of Web Service</strong></p>
<ul>
<li><p>Designed for machine-to-machine (or application-to-application)
interaction</p></li>
<li><p>Should be interoperable - Not platform dependent. As it shouldn’t
matter which language our web service made i.e. Java, PHP, .Net
etc.</p></li>
<li><p>Should allow communication over a network</p></li>
</ul></li>
<li><p>How does data exchange between applications take place?</p>
<ul>
<li>By Request and Response</li>
</ul></li>
<li><p>How can we make web services platform independent?</p>
<ul>
<li>There are 2 popular formats widely accepted by most of frontend and
backend languages - <strong>XML</strong> and <strong>JSON</strong></li>
</ul></li>
</ul>
<p><strong>Transport</strong> - It defines how a service is called.</p>
<ul>
<li><p><strong>HTTP</strong> - It is the service exposed over the
internet.</p></li>
<li><p><strong>MQ</strong> - Message Queue (e.g. WebSphere MQ) is the
service exposed over a queue. <em>Here Service requestor place a message
in queue, Service Provider listening on the queue and as soon as there
is a request on the queue, it would take the request, do the processing
of it, create the response and put it back into the queue.</em></p>
<p><img src="images/transport.png" alt="transport" style="zoom: 80%;" /></p></li>
</ul>
<p><strong>Web Service Groups</strong> : There are 2 types of web
services -</p>
<ol type="1">
<li><p><em>SOAP (Simple Object Access Protocol)</em></p></li>
<li><p><em>REST (Representational State Transfer)</em></p></li>
<li><p><strong><em>SOAP (Simple Object Access
Protocol)</em></strong></p>
<ul>
<li>Format - SOAP XML Request - SOAP XML Response</li>
<li>Transport : MQ or HTTP , There is no restriction.</li>
<li>Service Definition : WSDL (Web Services Description Language)</li>
</ul>
<p><img src="images/soap.png" alt="transport" style="zoom: 50%;" /></p>
<p>SOAP Example Request / Response :</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode xml"><code class="sourceCode xml"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">SOAP-ENV:Envelope</span><span class="ot"> xmlns:SOAPENV=</span><span class="st">"http://schemas.xmlsoap.org/soap/envelope/"</span>></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <<span class="kw">SOAP-ENV:Header</span>/></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">SOAP-ENV:Body</span>></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <<span class="kw">ns2:getCourseDetailsResponse</span><span class="ot"> xmlns:ns2=</span><span class="st">"http://in28minutes.com/courses"</span>></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <<span class="kw">ns2:course</span>></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <<span class="kw">ns2:id</span>>Course1</<span class="kw">ns2:id</span>></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <<span class="kw">ns2:name</span>>Spring</<span class="kw">ns2:name</span>></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <<span class="kw">ns2:description</span>>10 Steps</<span class="kw">ns2:description</span>></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> </<span class="kw">ns2:course</span>></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> </<span class="kw">ns2:getCourseDetailsResponse</span>></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> </<span class="kw">SOAP-ENV:Body</span>></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a></<span class="kw">SOAP-ENV:Envelope</span>></span></code></pre></div></li>
<li><p><strong><em>REST (Representational State
Transfer)</em></strong></p>
<ul>
<li>Data Exchange Format - No Restriction. JSON is popular</li>
<li>Transport : Only HTTP</li>
<li>Service Definition : No Standard. WADL/Swagger/…</li>
</ul></li>
</ol>
<ul>
<li><strong>HOW to build a great REST API?</strong>
<ul>
<li>Identifying Resources (/users, /users/{id}/posts)</li>
<li>Identifying Actions (GET, POST, PUT, DELETE, …)</li>
<li>Defining Request and Response structures</li>
<li>Using appropriate Response Status (200, 404, 500, ..)</li>
<li>Understanding REST API Best Practices
<ul>
<li>Thinking from the perspective of your consumer</li>
<li><strong>Validation, Internationalization - i18n, Exception Handling,
HATEOAS, Versioning,</strong> <strong>Documentation, Content
Negotiation</strong> and a lot more!</li>
</ul></li>
</ul></li>
</ul>
<hr />
<h1 id="building-rest-api">Building REST API</h1>
<p><strong>What’s Happening in the Background?</strong></p>
<p>Let’s explore some Spring Boot Magic: Enable Debug Logging. WARNING:
Log change frequently!</p>
<ol type="1">
<li><p>How are our requests handled?</p>
<ul>
<li>DispatcherServlet - Front Controller Pattern
<ul>
<li>Mapping servlets: dispatcherServlet urls=[/]</li>
<li>Auto Configuration (DispatcherServletAutoConfiguration)</li>
</ul></li>
</ul></li>
<li><p>How does HelloWorldBean object get converted to JSON?</p>
<ul>
<li><span class="citation"
data-cites="ResponseBody">@ResponseBody</span> +
JacksonHttpMessageConverters</li>
<li>Auto Configuration (JacksonHttpMessageConvertersConfiguration)</li>
</ul></li>
<li><p>Who is configuring error mapping?</p>
<ul>
<li>Auto Configuration (ErrorMvcAutoConfiguration)</li>
</ul></li>
<li><p>How are all jars available(Spring, Spring MVC, Jackson,
Tomcat)?</p>
<ul>
<li>Starter Projects - Spring Boot Starter Web (spring-webmvc,
spring-web, springboot-starter-tomcat, spring-boot-starter-json)</li>
</ul></li>
</ol>
<h3 id="advanced-rest-api-features">Advanced Rest API Features</h3>
<ul>
<li>Documentation - Swagger</li>
<li>Content Negotiation (What if consumer expect a XML response back ?
)</li>
<li>Internationalization - i18n (How to customize API response according
to language of user throughout the world ? )</li>
<li>Versioning</li>
<li>HATEOAS</li>
<li>Static Filtering</li>
<li>Dynamic Filtering</li>
<li>Monitoring</li>
</ul>
<h4 id="documentation"><strong>Documentation</strong></h4>
<p>We need to use springdoc-openapi version 2+ for Spring Boot 3 and
JDK17.</p>
<div class="sourceCode" id="cb2"><pre
class="sourceCode xml"><code class="sourceCode xml"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">dependency</span>></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <<span class="kw">groupId</span>>org.springdoc</<span class="kw">groupId</span>></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">artifactId</span>>springdoc-openapi-starter-webmvc-ui</<span class="kw">artifactId</span>></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <<span class="kw">version</span>>2.0.0</<span class="kw">version</span>></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a></<span class="kw">dependency</span>></span></code></pre></div>
<h4 id="content-negotiation"><strong>Content Negotiation</strong></h4>
<ul>
<li><p>Same Resource - Same URI</p></li>
<li><p>HOWEVER Different Representations are possible</p>
<ul>
<li>Example: Different Content Type - XML or JSON (Accept header (MIME
types - application/xml, application/json, …)</li>
<li>Example: Different Language - English or Dutch or french
(Accept-Language header (en, nl, fr, ..))</li>
</ul></li>
</ul>
<p><strong>Steps of Content Negotiation</strong></p>
<ul>
<li><p>STEP 1: add this in <strong><em>pom.xml</em></strong></p>
<div class="sourceCode" id="cb3"><pre
class="sourceCode xml"><code class="sourceCode xml"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"><!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-xml --></span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><<span class="kw">dependency</span>></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">groupId</span>>com.fasterxml.jackson.dataformat</<span class="kw">groupId</span>></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <<span class="kw">artifactId</span>>jackson-dataformat-xml</<span class="kw">artifactId</span>></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a></<span class="kw">dependency</span>></span></code></pre></div></li>
<li><p>STEP 2: Add <code>Accept</code> header in postman for
<code>application/xml</code>. If we don’t provide this header, default
is <code>application/json</code></p>
<div class="sourceCode" id="cb4"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="ex">curl</span> <span class="at">--location</span> <span class="st">'http://localhost:8080/users'</span> <span class="dt">\</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>--header <span class="st">'Accept: application/xml'</span></span></code></pre></div></li>
</ul>
<h4 id="internationalization"><strong>Internationalization</strong></h4>
<p>Typically HTTP Request Header - <code>Accept-Language</code> is used.
<code>Accept-Language</code> - indicates natural language and locale
that the consumer prefers</p>
<ul>
<li>Example: en - English (Good Morning)</li>
<li>Example: nl - Dutch (Goedemorgen)</li>
<li>Example: fr - French (Bonjour)</li>
<li>Example: de - Deutsch (Guten Morgen)</li>
</ul>
<h4 id="versioning"><strong>Versioning</strong></h4>
<ol type="1">
<li><strong>URI Versioning - Twitter</strong>
<ul>
<li>http://localhost:8080/v1/person</li>
<li>http://localhost:8080/v2/person</li>
</ul></li>
<li><strong>Request Parameter versioning - Amazon</strong>
<ul>
<li>http://localhost:8080/person?version=1</li>
<li>http://localhost:8080/person?version=2</li>
</ul></li>
<li><strong>(Custom) headers versioning - Microsoft</strong></li>
</ol>
<ul>
<li>SAME-URL headers=[X-API-VERSION=1]</li>
<li>SAME-URL headers=[X-API-VERSION=2]</li>
</ul>
<ol start="4" type="1">
<li><strong>Media type versioning (a.k.a “content negotiation” or
“accept header”) - GitHub</strong></li>
</ol>
<ul>
<li><p>SAME-URL produces=application/vnd.company.app-v1+json</p></li>
<li><p>SAME-URL produces=application/vnd.company.app-v2+json</p></li>
<li><p>Factors to consider</p>
<ul>
<li>URI Pollution</li>
<li>Misuse of HTTP Headers</li>
<li>Caching</li>
<li>Can we execute the request on the browser?</li>
<li>API Documentation</li>
<li>Summary: No Perfect Solution</li>
</ul></li>
<li><p>Recommendations</p>
<ul>
<li>Think about versioning even before you need it!</li>
<li>One Enterprise - One Versioning Approach</li>
</ul></li>
</ul>
<h4
id="hateoas-hypermedia-as-the-engine-of-application-state"><strong>HATEOAS
(Hypermedia as the Engine of Application State)</strong></h4>
<ul>
<li><p>Websites allow you to: See Data AND Perform Actions (using
links)</p></li>
<li><p>How about enhancing your REST API to tell consumers how to
perform subsequent actions?</p>
<ul>
<li><p>HATEOAS (In below image, <code>_links</code> section coming from
<code>hateoas</code>)</p>
<p><img src="images/hateoas.png" alt="transport" style="zoom: 50%;" /></p></li>
</ul></li>
<li><p>Implementation Options:</p>
<ul>
<li>1: Custom Format and Implementation</li>
<li>Difficult to maintain</li>
<li>2: Use Standard Implementation
<ul>
<li>HAL (JSON Hypertext Application Language): Simple format that gives
a consistent and easy way to hyperlink between resources in your
API</li>
<li>Spring HATEOAS: Generate HAL responses with hyperlinks to
resources</li>
</ul></li>
</ul></li>
<li><p>Steps :</p>
<ul>
<li><p>STEP 1: <strong><em>pom.xml</em></strong></p>
<div class="sourceCode" id="cb5"><pre
class="sourceCode xml"><code class="sourceCode xml"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">dependency</span>></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <<span class="kw">groupId</span>>org.springframework.boot</<span class="kw">groupId</span>></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">artifactId</span>>spring-boot-starter-hateoas</<span class="kw">artifactId</span>></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a></<span class="kw">dependency</span>></span></code></pre></div></li>
<li><p>STEP 2: <a
href="https://github.com/in28minutes/spring-microservices/blob/master/02.restful-web-services/backup07-improving-documentation-with-swagger.md#srcmainjavacomin28minutesrestwebservicesrestfulwebservicesuseruserresourcejava-1"><strong><em>UserResource.java</em></strong></a>
: Here we have added <code>all-users</code> link section of response
which is of generic type <code>hateoas.Resource</code></p>
<div class="sourceCode" id="cb6"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="kw">static</span><span class="im"> org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">hateoas</span><span class="op">.</span><span class="im">mvc</span><span class="op">.</span><span class="im">ControllerLinkBuilder</span><span class="op">.</span><span class="im">linkTo</span><span class="op">;</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="kw">static</span><span class="im"> org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">hateoas</span><span class="op">.</span><span class="im">mvc</span><span class="op">.</span><span class="im">ControllerLinkBuilder</span><span class="op">.</span><span class="im">methodOn</span><span class="op">;</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">hateoas</span><span class="op">.</span><span class="im">Resource</span><span class="op">;</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">hateoas</span><span class="op">.</span><span class="im">mvc</span><span class="op">.</span><span class="im">ControllerLinkBuilder</span><span class="op">;</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="kw">...</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="at">@RestController</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> <span class="kw">public</span> <span class="kw">class</span> UserResource <span class="op">{</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> <span class="at">@GetMapping</span><span class="op">(</span><span class="st">"/users/{id}"</span><span class="op">)</span></span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a> <span class="kw">public</span> <span class="bu">Resource</span><span class="op"><</span>User<span class="op">></span> <span class="fu">retrieveUser</span><span class="op">(</span><span class="at">@PathVariable</span> <span class="dt">int</span> id<span class="op">)</span> <span class="op">{</span></span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a> User user <span class="op">=</span> service<span class="op">.</span><span class="fu">findOne</span><span class="op">(</span>id<span class="op">);</span></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span><span class="op">(</span>user<span class="op">==</span><span class="kw">null</span><span class="op">)</span><span class="cf">throw</span> <span class="kw">new</span> <span class="fu">UserNotFoundException</span><span class="op">(</span><span class="st">"id-"</span><span class="op">+</span> id<span class="op">);</span></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a> <span class="co">//"all-users", SERVER_PATH + "/users"</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a> <span class="co">//retrieveAllUsers</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a> <span class="bu">Resource</span><span class="op"><</span>User<span class="op">></span> resource <span class="op">=</span> <span class="kw">new</span> <span class="bu">Resource</span><span class="op"><</span>User<span class="op">>(</span>user<span class="op">);</span></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true" tabindex="-1"></a> ControllerLinkBuilder linkTo <span class="op">=</span> <span class="fu">linkTo</span><span class="op">(</span><span class="fu">methodOn</span><span class="op">(</span><span class="kw">this</span><span class="op">.</span><span class="fu">getClass</span><span class="op">()).</span><span class="fu">retrieveAllUsers</span><span class="op">());</span></span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true" tabindex="-1"></a> resource<span class="op">.</span><span class="fu">add</span><span class="op">(</span>linkTo<span class="op">.</span><span class="fu">withRel</span><span class="op">(</span><span class="st">"all-users"</span><span class="op">));</span></span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true" tabindex="-1"></a> <span class="co">//HATEOAS</span></span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> resource<span class="op">;</span></span>
<span id="cb6-24"><a href="#cb6-24" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb6-25"><a href="#cb6-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-26"><a href="#cb6-26" aria-hidden="true" tabindex="-1"></a> <span class="at">@PostMapping</span><span class="op">(</span><span class="st">"/users"</span><span class="op">)</span></span>
<span id="cb6-27"><a href="#cb6-27" aria-hidden="true" tabindex="-1"></a> <span class="kw">public</span> ResponseEntity<span class="op"><</span><span class="bu">Object</span><span class="op">></span> <span class="fu">createUser</span><span class="op">(</span><span class="at">@Valid</span> <span class="at">@RequestBody</span> User user<span class="op">)</span> <span class="op">{</span></span>
<span id="cb6-28"><a href="#cb6-28" aria-hidden="true" tabindex="-1"></a> User savedUser <span class="op">=</span> service<span class="op">.</span><span class="fu">save</span><span class="op">(</span>user<span class="op">);</span></span>
<span id="cb6-29"><a href="#cb6-29" aria-hidden="true" tabindex="-1"></a> <span class="co">// CREATED</span></span>
<span id="cb6-30"><a href="#cb6-30" aria-hidden="true" tabindex="-1"></a> <span class="co">// /user/{id} savedUser.getId()</span></span>
<span id="cb6-31"><a href="#cb6-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-32"><a href="#cb6-32" aria-hidden="true" tabindex="-1"></a> <span class="bu">URI</span> location <span class="op">=</span> ServletUriComponentsBuilder</span>
<span id="cb6-33"><a href="#cb6-33" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">fromCurrentRequest</span><span class="op">()</span></span>
<span id="cb6-34"><a href="#cb6-34" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">path</span><span class="op">(</span><span class="st">"/{id}"</span><span class="op">)</span></span>
<span id="cb6-35"><a href="#cb6-35" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">buildAndExpand</span><span class="op">(</span>savedUser<span class="op">.</span><span class="fu">getId</span><span class="op">()).</span><span class="fu">toUri</span><span class="op">();</span></span>
<span id="cb6-36"><a href="#cb6-36" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> ResponseEntity<span class="op">.</span><span class="fu">created</span><span class="op">(</span>location<span class="op">).</span><span class="fu">build</span><span class="op">();</span></span>
<span id="cb6-37"><a href="#cb6-37" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb6-38"><a href="#cb6-38" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div></li>
</ul></li>
</ul>
<h4 id="hal-explorer"><strong>HAL Explorer</strong></h4>
<ul>
<li>An API explorer for RESTful Hypermedia APIs using HAL</li>
<li>Enable your non-technical teams to play with APIs</li>
<li>Spring Boot HAL Explorer
<ul>
<li>Auto-configures HAL Explorer for Spring Boot Projects</li>
<li>Import in pom.xml using
<code>spring-data-rest-hal-explorer</code></li>
</ul></li>
</ul>
<p><img src="images/halExplorer.png" alt="transport" style="zoom: 43%;" /></p>
<h1 id="microservicesv1">Microservices(V1)</h1>
<p>This is a older version compatible with Spring boot < 2.3.0, For
newer Versions, Please refer []</p>
<p><strong>Problems and Solutions for each problem :</strong></p>
<ul>
<li>CENTRALIZED CONFIGURATION MANAGEMENT - <strong><em>Spring Cloud
Config Server</em></strong></li>
<li>LOCATION TRANSPARANCY - Naming Server
(<strong><em>Eureka</em></strong>)</li>
<li>LOAD BALANCING - <strong><em>Ribbon</em></strong> (Client Side)</li>
<li>VISIBILITY AND MONITORING -
<ul>
<li><strong><em>Zipkin Distributed Tracing</em></strong></li>
<li><strong><em>Netflix API Gateway</em></strong></li>
</ul></li>
<li>FAULT TOLERANCE - <strong><em>Hystrix</em></strong></li>
</ul>
<hr />
<h1 id="microservicesv3"><strong>Microservices(V3)</strong></h1>
<p><strong><a
href="https://github.com/in28minutes/spring-microservices-v3">Reference
Git Repo</a></strong></p>
<p><strong>Problems and Solutions for each problem :</strong></p>
<ul>
<li>CENTRALIZED CONFIGURATION MANAGEMENT - <strong><em>Spring Cloud
Config Server</em></strong></li>
<li>LOCATION TRANSPARANCY - Naming Server
(<strong><em>Eureka</em></strong>)</li>
<li>LOAD BALANCING - <strong><em>Spring Cloud
Load-balancer</em></strong> instead of <em>Ribbon</em> (Client
Side)</li>
<li>VISIBILITY AND MONITORING -
<ul>
<li><strong><em>Zipkin Distributed Tracing</em></strong></li>
<li><strong><em>Spring Cloud Gateway</em></strong> instead of
<em>Netflix Zuul API Gateway</em></li>
</ul></li>
<li>FAULT TOLERANCE - <strong><em>Resilience4j</em></strong> instead of
<em>Hystrix</em></li>
<li><strong>OpenTelemetry</strong> : One Standard - Logs, Traces &
Metrics</li>
<li><strong>Micrometer</strong> (Replaces Spring Cloud Sleuth)</li>
</ul>
<p><img src="images/dia1.png" alt="transport" style="zoom: 43%;" /></p>
<h2 id="ports-and-urls">Ports and URLs</h2>
<h3 id="standardized-ports">Standardized Ports</h3>
<table>
<thead>
<tr class="header">
<th>Application</th>
<th>Port</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Limits Service</td>
<td>8080, 8081, …</td>
</tr>
<tr class="even">
<td>Spring Cloud Config Server</td>
<td>8888</td>
</tr>
<tr class="odd">
<td>Currency Exchange Service</td>
<td>8000, 8001, 8002, ..</td>
</tr>
<tr class="even">
<td>Currency Conversion Service</td>
<td>8100, 8101, 8102, …</td>
</tr>
<tr class="odd">
<td>Netflix Eureka Naming Server</td>
<td>8761</td>
</tr>
<tr class="even">
<td>Spring Cloud API Gateway</td>
<td>8765</td>
</tr>
<tr class="odd">
<td>Zipkin Distributed Tracing Server</td>
<td>9411</td>
</tr>
</tbody>
</table>
<h3 id="standardized-local-urls">Standardized Local URLs</h3>
<table>
<colgroup>
<col style="width: 36%" />
<col style="width: 63%" />
</colgroup>
<thead>
<tr class="header">
<th>Application</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Spring Cloud Config Server</td>
<td><a
href="http://localhost:8888/limits-service/default">http://localhost:8888/limits-service/default</a>
<br /><a
href="http://localhost:8888/limits-service/dev">http://localhost:8888/limits-service/dev</a></td>
</tr>
<tr class="even">
<td>Limits Service</td>
<td><a
href="http://localhost:8080/limits">http://localhost:8080/limits</a>
<br /><a
href="http://localhost:8080/actuator/refresh">http://localhost:8080/actuator/refresh</a>
(POST)<br />http://localhost:8080/actuator/bus-refresh (POST) - Spring
Cloud Bus Refresh</td>
</tr>
<tr class="odd">
<td>Currency Exchange Service</td>
<td><a
href="http://localhost:8000/currency-exchange/from/EUR/to/INR">http://localhost:8000/currency-exchange/from/EUR/to/INR</a>
<br /><a
href="http://localhost:8000/currency-exchange/from/USD/to/INR">http://localhost:8000/currency-exchange/from/USD/to/INR</a></td>
</tr>
<tr class="even">
<td>Currency Conversion Service</td>
<td><a
href="http://localhost:8100/currency-conversion/from/USD/to/INR/quantity/10">http://localhost:8100/currency-conversion/from/USD/to/INR/quantity/10</a></td>
</tr>
<tr class="odd">
<td>Eureka Naming Server</td>
<td><a href="http://localhost:8761/registry/">Eureka Console -
http://localhost:8761/registry/</a></td>
</tr>
<tr class="even">
<td>Spring Cloud API Gateway</td>
<td><a
href="http://localhost:8765/api/currency-exchange/from/USD/to/INR">http://localhost:8765/api/currency-exchange/from/USD/to/INR</a><br /><a
href="http://localhost:8765/api/currency-conversion/from/USD/to/INR/quantity/10">http://localhost:8765/api/currency-conversion/from/USD/to/INR/quantity/10</a><br /><a
href="http://localhost:8765/api/currency-conversion-new/from/USD/to/INR/quantity/10">http://localhost:8765/api/currency-conversion-new/from/USD/to/INR/quantity/10</a></td>
</tr>
<tr class="odd">
<td>Zipkin Distributed Tracing</td>
<td><a
href="http://localhost:9411/zipkin/">http://localhost:9411/zipkin/</a></td>
</tr>
<tr class="even">
<td>Logging- ELK Stack - Elastic Search</td>
<td><a href="http://localhost:9200/">http://localhost:9200/</a></td>
</tr>
<tr class="odd">
<td>Logging- ELK Stack - LogStash</td>
<td></td>
</tr>
<tr class="even">
<td>Logging- ELK Stack - Kibana</td>
<td><a href="http://localhost:5601/">http://localhost:5601/</a></td>
</tr>
</tbody>
</table>
<h3 id="hosted-urls">Hosted URLs</h3>
<table style="width:100%;">
<colgroup>
<col style="width: 23%" />
<col style="width: 52%" />
<col style="width: 23%" />
</colgroup>
<thead>
<tr class="header">
<th>Application</th>
<th>URL</th>
<th>Supervisor Application Name</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Limits Service</td>
<td><a
href="http://localhost:8080/limits">http://localhost:8080/limits</a>
<br /><a
href="http://localhost:8080/actuator/refresh">http://localhost:8080/actuator/refresh</a>
(POST)</td>
<td></td>
</tr>
<tr class="even">
<td>Spring Cloud Config Server</td>
<td><a
href="http://localhost:8888/limits-service/default">http://localhost:8888/limits-service/default</a>
<br /><a
href="http://localhost:8888/limits-service/dev">http://localhost:8888/limits-service/dev</a></td>
<td>config-server</td>
</tr>
<tr class="odd">
<td>Currency Exchange Service</td>
<td><a
href="http://swarnadeep.centralindia.cloudapp.azure.com:8000/currency-exchange/from/EUR/to/INR">http://swarnadeep.centralindia.cloudapp.azure.com:8000/currency-exchange/from/EUR/to/INR</a>
<br /><a
href="http://swarnadeep.centralindia.cloudapp.azure.com:8000/currency-exchange/from/USD/to/INR">http://swarnadeep.centralindia.cloudapp.azure.com:8000/currency-exchange/from/USD/to/INR</a></td>
<td>currency-exchange</td>
</tr>
<tr class="even">
<td>Currency Conversion Service</td>
<td><a
href="http://swarnadeep.centralindia.cloudapp.azure.com:8100/currency-conversion/from/USD/to/INR/quantity/10">http://swarnadeep.centralindia.cloudapp.azure.com:8100/currency-conversion/from/USD/to/INR/quantity/10</a></td>
<td>currency-conversion</td>
</tr>
<tr class="odd">
<td>Eureka Naming Server</td>
<td><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/registry/">https://swarnadeep.centralindia.cloudapp.azure.com/registry/</a></td>
<td>naming-server</td>
</tr>
<tr class="even">
<td>Spring Cloud API Gateway</td>
<td><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/api/currency-exchange/from/USD/to/INR">https://swarnadeep.centralindia.cloudapp.azure.com/api/currency-exchange/from/USD/to/INR</a><br /><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/api/currency-conversion/from/USD/to/INR/quantity/10">https://swarnadeep.centralindia.cloudapp.azure.com/api/currency-conversion/from/USD/to/INR/quantity/10</a><br /><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/api/currency-conversion-new/from/USD/to/INR/quantity/10">https://swarnadeep.centralindia.cloudapp.azure.com/api/currency-conversion-new/from/USD/to/INR/quantity/10</a></td>
<td>api-gateway</td>
</tr>
<tr class="odd">
<td>Zipkin Distributed Tracing</td>
<td><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/zipkin/">https://swarnadeep.centralindia.cloudapp.azure.com/zipkin/</a></td>
<td>zipkin</td>
</tr>
</tbody>
</table>
<h3 id="devops-hosted-urls">Devops Hosted URLs</h3>
<table style="width:100%;">
<colgroup>
<col style="width: 19%" />
<col style="width: 50%" />
<col style="width: 20%" />
<col style="width: 10%" />
</colgroup>
<thead>
<tr class="header">
<th>Service</th>
<th>URL</th>
<th>Username</th>
<th>Password</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Jenkins</td>
<td><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/">https://swarnadeep.centralindia.cloudapp.azure.com/</a></td>
<td>swarnadeep</td>
<td>swarnadeep</td>
</tr>
<tr class="even">
<td>Tomcat</td>
<td><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/tomcat/">https://swarnadeep.centralindia.cloudapp.azure.com/tomcat/</a></td>
<td>swarnadeep</td>
<td>swarnadeep</td>
</tr>
<tr class="odd">
<td>Sonarqube</td>
<td><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/sonar/">https://swarnadeep.centralindia.cloudapp.azure.com/sonar/</a></td>
<td>swarnadeep<br />or admin</td>
<td>Password@123</td>
</tr>
<tr class="even">
<td>Supervisor - Monitoring</td>
<td><a
href="https://swarnadeep.centralindia.cloudapp.azure.com/monitor/">https://swarnadeep.centralindia.cloudapp.azure.com/monitor/</a></td>
<td>swarnadeep</td>
<td>swarnadeep</td>
</tr>
</tbody>
</table>
<h3 id="architecture---currency-microservice">Architecture - Currency
Microservice</h3>
<p><img src="images/Currency-Microservice-Diagram.jpg" alt="transport" style="zoom: 67%;" /></p>
<h2 id="currency-config-repository">Currency Config Repository</h2>
<ul>
<li><p><a href="https://github.com/SwarnadeepGhosh/Microservices">Git
Repo Link</a></p></li>
<li><p>File name pattern :
<strong><code><microservice-name>-<profile>.properties</code></strong></p></li>
<li><p>Spring Cloud Config Repository is having highest priority. That
means, if someone write same property within project and also he is
fetching that property value from Git repo, then the property of git
repo will overwrite the property value present in microservice property
file.</p></li>
<li><p><strong>STEP 1:</strong> Create property files</p>
<ul>
<li><p><strong><em>limits-service.properties</em></strong></p>
<pre class="properties"><code>limits.service.minimum=4
limits.service.maximum=996</code></pre></li>
<li><p><strong><em>limits-service-dev.properties</em></strong></p>
<pre class="properties"><code>limits.service.minimum=5
limits.service.maximum=995</code></pre></li>
<li><p><strong><em>limits-service-qa.properties</em></strong></p>
<pre class="properties"><code>limits.service.minimum=6
limits.service.maximum=994</code></pre></li>
</ul></li>
<li><p><strong>STEP 2:</strong> Initialize a git repository and push
changes into master branch</p>
<ul>
<li><div class="sourceCode" id="cb10"><pre
class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> git init</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> git add .</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">$</span> git commit <span class="at">-m</span> <span class="st">"added files"</span></span></code></pre></div></li>
<li>If its a remote branch , then we need to create api key from :
Github > Settings > Developer Settings</li>
</ul></li>
</ul>
<hr />
<h2 id="config-server-microservice">Config Server Microservice</h2>
<ul>
<li><p><a
href="https://start.spring.io/#!type=maven-project&language=java&platformVersion=3.2.4&packaging=jar&jvmVersion=21&groupId=com.swarna.microservices&artifactId=config-server&name=config-server&description=Centralized%20config%20server%20microservice&packageName=com.swarna.microservices.config-server&dependencies=devtools,cloud-config-server">Starting
Project - Config Server Microservice (Spring.io)</a></p></li>
<li><p><a href="https://github.com/SwarnadeepGhosh/Microservices">Git
Repo Link</a></p></li>
<li><p>Connecting with Git Repo :</p>
<ul>
<li><p><strong>STEP 1</strong> : Import downloaded Zip from
start.spring.io and add <code>@EnableConfigServer</code> annotation in
main class : <strong><em>ConfigServerApplication.java</em></strong></p>
<div class="sourceCode" id="cb11"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">cloud</span><span class="op">.</span><span class="im">config</span><span class="op">.</span><span class="im">server</span><span class="op">.</span><span class="im">EnableConfigServer</span><span class="op">;</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="at">@EnableConfigServer</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="at">@SpringBootApplication</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> ConfigServerApplication <span class="op">{</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">public</span> <span class="dt">static</span> <span class="dt">void</span> <span class="fu">main</span><span class="op">(</span><span class="bu">String</span><span class="op">[]</span> args<span class="op">)</span> <span class="op">{</span> SpringApplication<span class="op">.</span><span class="fu">run</span><span class="op">(</span>ConfigServerApplication<span class="op">.</span><span class="fu">class</span><span class="op">,</span> args<span class="op">);</span> <span class="op">}</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div></li>
<li><p><strong>STEP 2</strong>:
<strong><em>application.properties</em></strong></p>
<pre class="properties"><code>spring.application.name=config-server
server.port=8888
#Sample URI for local git repo in Windows local system
#spring.cloud.config.server.git.uri=file:///D:/Microservices/config-repo
#Sample URI for Git repo from Github
spring.cloud.config.server.git.uri=https://github.com/SwarnadeepGhosh/currency-config-repo
spring.cloud.config.server.git.default-label=master
spring.cloud.config.server.git.username=SwarnadeepGhosh
spring.cloud.config.server.git.password=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
#spring.cloud.config.server.git.ignore-local-ssh-settings=true
#spring.cloud.config.server.git.private-key=<private-key></code></pre></li>
<li><p><strong>STEP 3</strong>: Fetch Config using GET api calls :</p>
<ul>
<li>Default: <a
href="http://localhost:8888/limits-service/default">http://localhost:8888/limits-service/default</a></li>
<li>Dev: <a
href="http://localhost:8888/limits-service/dev">http://localhost:8888/limits-service/dev</a></li>
<li>Qa: <a
href="http://localhost:8888/limits-service/qa">http://localhost:8888/limits-service/qa</a></li>
</ul></li>
</ul></li>
</ul>
<hr />
<h2 id="limits-microservice">Limits Microservice</h2>
<ul>
<li><p><a
href="https://start.spring.io/#!type=maven-project&language=java&platformVersion=3.2.4&packaging=jar&jvmVersion=21&groupId=com.swarna.microservices&artifactId=limit-service&name=limit-service&description=Limit%20Microservice&packageName=com.swarna.microservices.limit-service&dependencies=web,devtools,actuator,lombok,cloud-config-client">Starting
Project - Limits Microservice (Spring.io)</a></p></li>
<li><p><a href="https://github.com/SwarnadeepGhosh/Microservices">Git
Repo Link</a></p></li>
<li><p>Connecting with Config server and eventually fetching config from
config repo :</p>
<ul>
<li><p><strong>STEP 1</strong> : Import downloaded Zip from
start.spring.io and add below in
<strong><em>application.properties</em></strong></p>
<pre class="properties"><code>spring.application.name=limits-service
spring.config.import=optional:configserver:http://localhost:8888
spring.profiles.active=dev
spring.cloud.profiles.active=dev</code></pre></li>
<li><p><strong>STEP 2</strong>:
<strong><em>PropertyConfig.java</em></strong> - This will fetch data
from property files, so that we can use it in application.</p>
<div class="sourceCode" id="cb14"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="at">@ConfigurationProperties</span><span class="op">(</span><span class="st">"limits.service"</span><span class="op">)</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="at">@Component</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Data</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> PropertyConfig <span class="op">{</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="dt">int</span> minimum<span class="op">;</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="dt">int</span> maximum<span class="op">;</span></span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div></li>
<li><p><strong>STEP 3</strong>:
<strong><em>LimitController.java</em></strong> - This will fetch data
from property files, so that we can use it in application.</p>
<div class="sourceCode" id="cb15"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="at">@RestController</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> LimitController <span class="op">{</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a> <span class="at">@Autowired</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a> PropertyConfig propertyConfig<span class="op">;</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a> <span class="at">@GetMapping</span><span class="op">(</span><span class="st">"/limits"</span><span class="op">)</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">public</span> Limits <span class="fu">retrieveLimits</span><span class="op">(){</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="kw">new</span> <span class="fu">Limits</span><span class="op">(</span>propertyConfig<span class="op">.</span><span class="fu">getMinimum</span><span class="op">(),</span> propertyConfig<span class="op">.</span><span class="fu">getMaximum</span><span class="op">());</span></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div></li>
<li><p><strong>STEP 3</strong>: Fetch response using GET api calls : <a
href="http://localhost:8080/limits">http://localhost:8080/limits</a> .
Here property coming from git repo to config server and to limit
service.</p></li>
</ul></li>
</ul>
<hr />
<h2 id="currency-exchange">Currency Exchange</h2>
<ul>
<li><p>URLs</p>
<ul>
<li><a
href="https://start.spring.io/#!type=maven-project&language=java&platformVersion=3.2.4&packaging=jar&jvmVersion=21&groupId=com.swarna.microservices&artifactId=currency-exchange&name=currency-exchange&description=Currency%20Exchange%20Microservice&packageName=com.swarna.microservices.currency-exchange&dependencies=web,devtools,actuator,lombok,cloud-config-client">Starting
Project - Currency Exchange Microservice (Spring.io)</a></li>
<li><a href="https://github.com/SwarnadeepGhosh/Microservices">Git Repo
Link</a></li>
<li>H2 Console : <a
href="http://localhost:8000/h2-console">http://localhost:8000/h2-console</a></li>
<li><a
href="http://localhost:8000/currency-exchange/from/USD/to/INR">http://localhost:8000/currency-exchange/from/USD/to/INR</a></li>
</ul></li>
<li><p><strong>Service Working example :</strong></p>
<ul>
<li><p>If you ask it the value of 1 USD in INR, or 1 Australian Dollar
in INR, the Currency Exchange Service answers</p>
<ul>