{"id":58,"date":"2019-11-14T14:27:07","date_gmt":"2019-11-14T14:27:07","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/microservices\/?p=58"},"modified":"2019-11-24T13:02:23","modified_gmt":"2019-11-24T13:02:23","slug":"cqrs-with-axon-tutorial-part-1-introduction-and-setup-in-intellij","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/microservices\/cqrs-with-axon-tutorial-part-1-introduction-and-setup-in-intellij\/","title":{"rendered":"CQRS With Axon Tutorial &#8211; Part 1 &#8211; Introduction and Setup in Intellij"},"content":{"rendered":"<p>In this series, I would teach you how to build a microservice that uses CQRS and Event Sourcing using the <a href=\"https:\/\/www.kindsonthegenius.com\/microservices\/axon-the-best-platform-for-microservices\/\">Axon Framework<\/a>. In this Part 1, we would take an overview of the application we&#8217;ll build and the tools we&#8217;ll use.<\/p>\n<p>I recommend you read up the concept of <a href=\"https:\/\/www.kindsonthegenius.com\/microservices\/8-fundamental-microservices-patterns-and-concepts\/\">CQRS and Event Sourcing here.<\/a><\/p>\n<ol>\n<li><a href=\"#t1\">The Application we&#8217;ll Build<\/a><\/li>\n<li><a href=\"#t2\">What You&#8217;ll Learn in this Tutorial<\/a><\/li>\n<li><a href=\"#t3\">What We&#8217;ll Use in this Tutorial<\/a><\/li>\n<li><a href=\"#t4\">Setup in IntelliJ<\/a><\/li>\n<li><a href=\"#t5\">Setup Axon Server<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t1\">1. The Application we&#8217;ll Build<\/strong><\/h5>\n<p>We would build a gift card application step by step.<\/p>\n<p>A gift card has a particular amount associated with it. I can be issued to someone. Then the recipient can redeem the amount. Also, the amount could be redeemed in parts. As such, when an amount is redeemed, the balance is updated\/reduced.<\/p>\n<p>Note: This demo was actually done in a webinar in 2018. However as of Axon Version 2019, the procedure in that webinar has many issues. Besides, the pace was such that beginners and intermediates in Axon Framework could not catch up.<\/p>\n<p>So I have taken time to break it down to very simple, easy and clear bits. Besides, I&#8217;ll take time to explain the likely problems you&#8217;ll encounter and how to solve them<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t2\">2. What You&#8217;ll Learn in this Tutorial<\/strong><\/h5>\n<ul>\n<li><strong>Axon Framework<\/strong>: for implementing CQRS and Event Sourcing<\/li>\n<li><strong>Axon Server<\/strong>: for managing Axon applications<\/li>\n<li><strong>AxonHub<\/strong>: used to connect among microservices<\/li>\n<li><strong>Vaadin<\/strong>: used for building robust User Interface<\/li>\n<li><strong>Kotlin<\/strong>: programming language that simplifies creating of classes<\/li>\n<li><strong>Kubernetes<\/strong>: we&#8217;ll deploy the application to Kubernetes cluster running on Google Cloud<\/li>\n<li><strong>Microservices<\/strong>: you can read it up here<\/li>\n<li><strong>Spring Profiles:<\/strong> enables mapping of your beans conditionally to profiles<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t3\">3. What we&#8217;ll Use in this Tutorial<\/strong><\/h5>\n<p>As mention we&#8217;ll use Axon Platform(Axon Framework + Axon Server), Vaadin, Kotlin.<\/p>\n<p>In addition, we would use the following:<\/p>\n<ul>\n<li><strong>Intellij IDEA<\/strong> Community Edition (you can get it for free)<\/li>\n<li><strong>Spring Boot<\/strong>: for easily building web applications<\/li>\n<li><strong>Maven<\/strong>: dependency management<\/li>\n<\/ul>\n<p><strong>Prerequisite<\/strong>: You need to have Intellij installed.<\/p>\n<p>Let&#8217;s dive right into Part 1!<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t4\">4. Part 1 &#8211; Setup in Intellij<\/strong><\/h5>\n<p>Follow the four steps below to set up the application<\/p>\n<p><strong>Step 1:<\/strong> Create a new Project in Intellij. Make sure to select Kotlin as the Language. You selection would be as shown below:<\/p>\n<p><a href=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/New-Axon-Project.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-70 aligncenter\" src=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/New-Axon-Project.jpg\" alt=\"New Axon Project\" width=\"604\" height=\"377\" srcset=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/New-Axon-Project.jpg 941w, https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/New-Axon-Project-300x187.jpg 300w, https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/New-Axon-Project-768x479.jpg 768w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><\/p>\n<p><strong>Step 2:<\/strong> Click on Next and select the following dependencies:<\/p>\n<p>Vaadin, H2 and Jpa. The screenshot is shown below. We&#8217;ll add more dependencies using the pom.xml file<\/p>\n<p><a href=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/Dependency-Selection-for-Axon-Project.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-72 \" src=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/Dependency-Selection-for-Axon-Project.jpg\" alt=\"Dependency Selection for Axon Project\" width=\"533\" height=\"334\" srcset=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/Dependency-Selection-for-Axon-Project.jpg 807w, https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/Dependency-Selection-for-Axon-Project-300x188.jpg 300w, https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/Dependency-Selection-for-Axon-Project-768x482.jpg 768w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 3:<\/strong> Click on Next, then Finish<\/p>\n<p>Wait for a few second for the project setup to complete<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong> Create three packages inside the com.kindsonthegenius.gcwebinar package. The packages would be as follows<\/p>\n<ul>\n<li>commands: package for the commands service<\/li>\n<li>query: package for the query service<\/li>\n<li>gui: package for the gui application<\/li>\n<\/ul>\n<p>This three packages would eventually correspond to three microservices<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t5\">5. Setup and Test Axon Server<\/strong><\/h5>\n<p>We now need to set up Axon Server so we can monitor our services. To setup Axon Server, follow the steps below.<\/p>\n<p><strong>Step 1:<\/strong> Download Axon Server from <a href=\"https:\/\/download.axoniq.io\/axonserver\/AxonServer.zip\">here<\/a>. (Its a zip file containing the axonserver jar file)<\/p>\n<p><strong>Step 2:<\/strong> Unzip the file into a local directory<\/p>\n<p><strong>Step 3:<\/strong> To start the server, open command prompt. Navigate to the axonserver jar file directory<\/p>\n<p><strong>Step 4:<\/strong> Run the command below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><strong>java -jar axonserver.jar\r\n<\/strong><\/pre>\n<p>The command starts the server<\/p>\n<p><strong>Step 5:<\/strong> Visit <a href=\"#\">http:\/\/localhost:8024<\/a><\/p>\n<p>You will see the AxonDashboard as shown below<\/p>\n<figure id=\"attachment_67\" aria-describedby=\"caption-attachment-67\" style=\"width: 535px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/AxonDashbaord.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-67 \" src=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/AxonDashbaord.jpg\" alt=\"AxonDashbaord\" width=\"535\" height=\"330\" srcset=\"https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/AxonDashbaord.jpg 846w, https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/AxonDashbaord-300x185.jpg 300w, https:\/\/www.kindsonthegenius.com\/microservices\/wp-content\/uploads\/sites\/18\/2019\/11\/AxonDashbaord-768x474.jpg 768w\" sizes=\"auto, (max-width: 535px) 100vw, 535px\" \/><\/a><figcaption id=\"caption-attachment-67\" class=\"wp-caption-text\">AxonDashbaord<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>At this point, you have completed the initial setup. Next, we would modify the pom.xml to add the needed dependencies, plugins and other modification. We&#8217;ll do this in Part 2<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this series, I would teach you how to build a microservice that uses CQRS and Event Sourcing using the Axon Framework. In this Part &hellip; <\/p>\n","protected":false},"author":1,"featured_media":62,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,27,2],"tags":[26,6,8,24,20,22,23,25,21],"class_list":["post-58","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-axon","category-axonframework","category-microservices","tag-axon-framework","tag-cqrs","tag-event-sourcing","tag-intellij","tag-kotlin","tag-kubernetes","tag-maven","tag-spring-boot","tag-vaadin"],"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":8,"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":122,"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/posts\/58\/revisions\/122"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/media\/62"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/microservices\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}