{"id":1333,"date":"2022-02-27T12:29:59","date_gmt":"2022-02-27T19:29:59","guid":{"rendered":"https:\/\/bullyrooks.com\/?p=1333"},"modified":"2022-02-27T15:03:17","modified_gmt":"2022-02-27T22:03:17","slug":"kube-cloud-pt5-create-a-consumer-service","status":"publish","type":"post","link":"https:\/\/bullyrooks.com\/index.php\/2022\/02\/27\/kube-cloud-pt5-create-a-consumer-service\/","title":{"rendered":"Kube Cloud Pt5 | Create a Consumer Service"},"content":{"rendered":"\n<p>In this course we&#8217;re going to migrate the repository storage function out of cloud-application and migrate it into a new service called message-repository.  Although this is a relatively minor change in behavior (in exchange for a significant effort), there are some real world benefits that this example will provide<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>cloud-application service performance will significantly improve.  Most of the time spent in this application, if you review the traces we implemented last session, is spent writing to mongodb and waiting for its response.  <\/li><li>By emitting an event, we can have multiple listeners consume that event and improve the flexibility of our application design.  If a new feature was added (logging to a reporting database, for example) we can just pipe the event to that system.<\/li><\/ul>\n\n\n\n<p>But more importantly events are just fun (IMHO) and provide many flexible design patterns such as a event processing stream which can turn something that might have been implemented as a multi-stage batch process into a scalable real time processing workflow.<\/p>\n\n\n\n<p>There are some downsides to pay attention to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Event driven architecture comes with a cost in terms of complexity<\/li><li>They can take more time to build<\/li><li>There are more failure points<\/li><li>They <em>can<\/em> be slower <\/li><\/ul>\n\n\n\n<p>These can all be mitigated with a good design.  In fact, event driven systems can be <em>faster<\/em> than traditional synchronous systems when used properly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Spring Cloud Stream<\/h2>\n\n\n\n<p><a href=\"https:\/\/spring.io\/projects\/spring-cloud-stream\">Spring cloud stream<\/a> is an event streaming library that allows you to easily chain together event producers, processors and consumers via functions.  Although I&#8217;m not very proficient with functional design, the concept overlays onto the event streaming concept well.  This also allows you to build upon <a href=\"https:\/\/www.enterpriseintegrationpatterns.com\/\">a great wealth of enterprise integration patterns<\/a> that have been developed over time.  Essentially, you can create functions that encapsulate single responsibility concerns and chain them together through the integration patterns.  It&#8217;s very powerful, but we&#8217;re not going to cover any of it here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Kafka<\/h2>\n\n\n\n<p>Everyone seems to love kafka these days (for good reason) and my goal here is not to get into the details of kafka, but build a simple messaging system that barely scratches the surface of what kafka can do.  For this, we&#8217;ll be using <a href=\"https:\/\/www.confluent.io\/\">confluent kafka<\/a> as our cloud based provider.  You&#8217;ll need to setup an account there to get started.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up a Confluent Account<\/h2>\n\n\n\n<p>Click get started free<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"126\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-38.png?resize=960%2C126&#038;ssl=1\" alt=\"\" class=\"wp-image-1334\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-38.png?w=1020&amp;ssl=1 1020w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-38.png?resize=300%2C39&amp;ssl=1 300w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-38.png?resize=768%2C101&amp;ssl=1 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>I don&#8217;t have screens for the whole login process, but you can figure it out.  You will have to provide a credit card, but we&#8217;re not going to get close to being charged in our example.  Additionally, I believe that there are many ways to get additional credits if necessary.  <\/p>\n\n\n\n<p>Once we get to the point where we can create a cluster we&#8217;ll follow this process.  Create a Basic cluster<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"757\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg1.png?resize=960%2C757&#038;ssl=1\" alt=\"\" class=\"wp-image-1335\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg1.png?w=994&amp;ssl=1 994w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg1.png?resize=300%2C237&amp;ssl=1 300w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg1.png?resize=768%2C606&amp;ssl=1 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>Create an AWS cluster in us-east-1 with single availability (we don&#8217;t need failover)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"725\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg2-1024x773.png?resize=960%2C725&#038;ssl=1\" alt=\"\" class=\"wp-image-1336\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg2.png?resize=1024%2C773&amp;ssl=1 1024w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg2.png?resize=300%2C226&amp;ssl=1 300w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg2.png?resize=768%2C580&amp;ssl=1 768w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg2.png?w=1048&amp;ssl=1 1048w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>Name your cluster and launch it<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"938\" height=\"804\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg3.png?resize=938%2C804&#038;ssl=1\" alt=\"\" class=\"wp-image-1337\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg3.png?w=938&amp;ssl=1 938w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg3.png?resize=300%2C257&amp;ssl=1 300w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/pg3.png?resize=768%2C658&amp;ssl=1 768w\" sizes=\"auto, (max-width: 938px) 100vw, 938px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>Now we&#8217;ve got a cluster and we&#8217;ll have to update our services to publish and consume from it.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"entry-summary\">\nIn this course we&#8217;re going to migrate the repository storage function out&hellip;\n<\/div>\n<div class=\"link-more\"><a href=\"https:\/\/bullyrooks.com\/index.php\/2022\/02\/27\/kube-cloud-pt5-create-a-consumer-service\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &ldquo;Kube Cloud Pt5 | Create a Consumer Service&rdquo;<\/span>&hellip;<\/a><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[189,191,90,192,190,43,193],"course":[188],"class_list":["post-1333","post","type-post","status-publish","format-standard","hentry","category-software-development","tag-confluent","tag-confluent-io","tag-event-driven-architecture","tag-events","tag-kafka","tag-spring-boot","tag-spring-boot-streaming","course-kube-cloud-pt5-kafka-events","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":1356,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/02\/27\/kube-cloud-pt5-create-an-event-consumer\/","url_meta":{"origin":1333,"position":0},"title":"Kube Cloud Pt5 | Create an Event Consumer","author":"Bullyrook","date":"February 27, 2022","format":false,"excerpt":"Now that we've got messages being published to kafka, we are going to need to build our consumer that receives those events and stores them into the mongo database. Go ahead and create a new repository called message-repository according to the microservice startup course here. This is the pom.xml that\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-49.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-49.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-49.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1141,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/01\/02\/kubernetes-application-hosted-in-the-cloud\/","url_meta":{"origin":1333,"position":1},"title":"Kubernetes Application Hosted in the Cloud","author":"Bullyrook","date":"January 2, 2022","format":false,"excerpt":"It's been a few years since my last spring boot based kubernetes application. That course ended with a microservice deployed into kubernetes via minikube locally. I'm using this course to expand on that effort. In this course I'm going to show a few ways to do the same things in\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1339,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/02\/27\/kube-cloud-pt5-create-an-event-publisher\/","url_meta":{"origin":1333,"position":2},"title":"Kube Cloud Pt5 | Create an Event Publisher","author":"Bullyrook","date":"February 27, 2022","format":false,"excerpt":"We're going to be updating cloud-application to remove the mongodb repository logic and replace it with an event publisher. Create a new branch from main git checkout -b migrate Update the pom.xml first, remove the mongodb dependencies <dependency> <groupId>org.springframework.boot<\/groupId> <artifactId>spring-boot-starter-data-mongodb<\/artifactId> <\/dependency> ... <dependency> <groupId>org.testcontainers<\/groupId> <artifactId>mongodb<\/artifactId> <version>1.16.3<\/version> <scope>test<\/scope> <\/dependency> and add\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-39.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-39.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/02\/image-39.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":826,"url":"https:\/\/bullyrooks.com\/index.php\/2020\/03\/30\/simple-spring-boot-service-to-kubernetes-application-step-9-55fd26c1dffb\/","url_meta":{"origin":1333,"position":3},"title":"Docker Registry","author":"Bullyrook","date":"March 30, 2020","format":false,"excerpt":"In the previous article we created a docker image as part of our build process and stored it into our local repository. In order to deploy it in an automated fashion we should create a remote image repository in the cloud. This will expand the types of tools that we\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1242,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/02\/13\/kube-cloud-pt3-synchronous-service-interaction\/","url_meta":{"origin":1333,"position":4},"title":"Kube Cloud Pt3 | Synchronous Service Interaction","author":"Bullyrook","date":"February 13, 2022","format":false,"excerpt":"In this course I'm going to show you how to make another spring boot microservice (message-generator), deploy it with our first service (cloud-application). I'll show how cloud-application service can discover message-generator via kubernetes services, call an endpoint in message-generator with a feign based REST client as well as how to\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-45.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-45.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-45.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-45.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-45.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":827,"url":"https:\/\/bullyrooks.com\/index.php\/2020\/03\/30\/simple-spring-boot-service-to-kubernetes-application-step-1-d67f80487848\/","url_meta":{"origin":1333,"position":5},"title":"Setup: IDE and New Project","author":"Bullyrook","date":"March 30, 2020","format":false,"excerpt":"\u00a0Its very easy to get a spring boot microservice up and running. You can read any variety of articles on medium (or other service) on how to do that. However, there\u2019s little about how to do some of the more complicated things that you need in order to support a\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/comments?post=1333"}],"version-history":[{"count":3,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1333\/revisions"}],"predecessor-version":[{"id":1352,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1333\/revisions\/1352"}],"wp:attachment":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/categories?post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/tags?post=1333"},{"taxonomy":"course","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/course?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}