<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Wai Loon on Medium]]></title>
        <description><![CDATA[Stories by Wai Loon on Medium]]></description>
        <link>https://medium.com/@vxavictor513?source=rss-7925d9e40ad4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-hF9dt9Vmtw4sTUysTd7Pw.jpeg</url>
            <title>Stories by Wai Loon on Medium</title>
            <link>https://medium.com/@vxavictor513?source=rss-7925d9e40ad4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:14:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vxavictor513/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Generate Standalone SSL Certificate with Let’s Encrypt for AWS Route 53 using Docker]]></title>
            <link>https://medium.com/w-logs/generate-standalone-ssl-certificate-with-lets-encrypt-for-aws-route-53-25a30ca3062?source=rss-7925d9e40ad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/25a30ca3062</guid>
            <category><![CDATA[lets-encrypt]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[route-53]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Wai Loon]]></dc:creator>
            <pubDate>Thu, 20 Aug 2020 04:27:12 GMT</pubDate>
            <atom:updated>2020-08-20T04:44:43.593Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E52UWyCR1YN94KzeAIftLw.png" /></figure><h3>Scenario</h3><ul><li>Have a domain name in AWS Route 53.</li><li>Need to generate standalone certificate without web server. (In my case, the certificate is to be used for <a href="https://docs.pivotal.io/ops-manager/2-10/aws/prepare-env-terraform.html">deploying Ops Manager using Terraform</a>.)</li></ul><h3>TLDR</h3><p>Use the following command to run <a href="https://hub.docker.com/r/certbot/dns-route53">certbot/dns-route53</a> Docker image to generate the certificate. Once successfully generated, find the file at &lt;PUT_YOUR_LOCAL_DIR&gt;/letsencrypt directory.</p><pre>docker run -it --rm --name certbot \<br>    --env AWS_ACCESS_KEY_ID=&lt;PUT_YOUR_OWN_ID&gt; \<br>    --env AWS_SECRET_ACCESS_KEY=&lt;PUT_YOUR_OWN_KEY&gt; \<br>    --env AWS_SESSION_TOKEN=&lt;PUT_YOUR_OWN_TOKEN&gt; \<br>    -v &quot;&lt;PUT_YOUR_LOCAL_DIR&gt;/letsencrypt:/etc/letsencrypt&quot; \<br>    -v &quot;&lt;PUT_YOUR_LOCAL_DIR&gt;/letsencrypt:/var/lib/letsencrypt&quot; \<br>    certbot/dns-route53 certonly \<br>    -d my-subdomain.example.com \<br>    -d &#39;*.sys.my-subdomain.example.com&#39; \<br>    -d &#39;*.login.sys.my-subdomain.example.com&#39; \<br>    -d &#39;*.uaa.sys.my-subdomain.example.com&#39; \<br>    -d &#39;*.apps.my-subdomain.example.com&#39; \<br>    -m &lt;PUT_YOUR_EMAIL&gt; \<br>    --agree-tos --server <a href="https://acme-v02.api.letsencrypt.org/directory">https://acme-v02.api.letsencrypt.org/directory</a></pre><h4>Notes</h4><ol><li>If you are not using <a href="https://aws.amazon.com/premiumsupport/knowledge-center/authenticate-mfa-cli/">MFA for AWS CLI</a>, can omit AWS_SESSION_TOKEN.</li><li>Consider using <a href="https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file">--env-file</a> to pass the AWS credentials instead of clear text.</li><li><a href="https://docs.docker.com/engine/reference/commandline/run/#mount-volume--v---read-only">-v</a> mounts a local directory to the Docker container, that’s how the certificate files are created at &lt;PUT_YOUR_LOCAL_DIR&gt;/letsencrypt. <em>Note that this above sample is for Linux/macOS; the path syntax for Windows would be different.</em></li><li>--agree-tos is for automatically agreeing to the terms and conditions.</li><li>Use --server https://acme-v02.api.letsencrypt.org/directory only if you are generating a wildcard certificate.</li></ol><h3>Renew Certificate</h3><p>Let’s Encrypt certificate is only valid for 90 days. To automate the renewal, you can use the same certbot/dns-route53 image and run renew command.</p><pre>docker run -it --rm --name certbot \<br>    --env AWS_ACCESS_KEY_ID=&lt;PUT_YOUR_OWN_ID&gt; \<br>    --env AWS_SECRET_ACCESS_KEY=&lt;PUT_YOUR_OWN_KEY&gt; \<br>    --env AWS_SESSION_TOKEN=&lt;PUT_YOUR_OWN_TOKEN&gt; \<br>    -v &quot;&lt;PUT_YOUR_LOCAL_DIR&gt;/letsencrypt:/etc/letsencrypt&quot; \<br>    -v &quot;&lt;PUT_YOUR_LOCAL_DIR&gt;/letsencrypt:/var/lib/letsencrypt&quot; \<br>    certbot/dns-route53 renew \<br>    --agree-tos --server <a href="https://acme-v02.api.letsencrypt.org/directory">https://acme-v02.api.letsencrypt.org/directory</a></pre><h3>References</h3><p>More comprehensive explanations can be found in references below.</p><ol><li>Automating Certificates with Certbot in Docker, <a href="https://coderevolve.com/certbot-in-docker/">https://coderevolve.com/certbot-in-docker/</a></li><li>Certbot — Running with Docker, <a href="https://certbot.eff.org/docs/install.html#running-with-docker">https://certbot.eff.org/docs/install.html#running-with-docker</a></li><li>Let’s Encrypt Wildcard Certificate Configuration with AWS Route 53, <a href="https://medium.com/prog-code/lets-encrypt-wildcard-certificate-configuration-with-aws-route-53-9c15adb936a7">https://medium.com/prog-code/lets-encrypt-wildcard-certificate-configuration-with-aws-route-53-9c15adb936a7</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25a30ca3062" width="1" height="1" alt=""><hr><p><a href="https://medium.com/w-logs/generate-standalone-ssl-certificate-with-lets-encrypt-for-aws-route-53-25a30ca3062">Generate Standalone SSL Certificate with Let’s Encrypt for AWS Route 53 using Docker</a> was originally published in <a href="https://medium.com/w-logs">w:Logs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting Docusaurus on AWS + CI/CD with Azure DevOps]]></title>
            <link>https://medium.com/w-logs/hosting-docusaurus-on-aws-ci-cd-with-azure-devops-a89565bf97f0?source=rss-7925d9e40ad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a89565bf97f0</guid>
            <category><![CDATA[docusaurus]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Wai Loon]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 16:22:10 GMT</pubDate>
            <atom:updated>2020-06-08T23:04:18.536Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hosting Docusaurus on AWS S3 + CI/CD with Azure DevOps</h3><h3>Background</h3><p>At work, I came to a scenario where my team needs to create a live documentation website to advocate DevOps and Software Engineering practices across an enterprise. The best solution should be <a href="https://www.atlassian.com/software/confluence">Confluence</a>, but we opt for an open source option. We considered using <a href="https://docs.microsoft.com/en-us/azure/devops/project/wiki/about-readme-wiki#wiki">Azure DevOps Wiki</a>, but the continuous need to enroll readers into the Azure DevOps project is a hassle.</p><p>Eventually, it was decided to use a self-hosted WordPress site. In plain sight, it was a decent choice as it complies to the enterprise design language by default and the WYSIWYG editing seemed convenient. However, over time, I realize there are a few downsides:</p><ul><li>It is hard to ensure content quality without proper content review process. Our WordPress content is not integrated to Git, thus we cannot use pull request. We can compare revisions, but it is not user-friendly.</li><li>WYSIWYG allows writers to save their changes frequently. At times we would see tens of revisions, where each changes only one or two lines.</li><li>The design language did not provide a good support for tables and code blocks, thus it looks very ugly.</li><li>The WordPress template has limitations, for instance, there is finite number of levels we can create at the side bar. And it does not support blogging (for future plan) and search features.</li></ul><p>Though the above downsides/limitations should be solvable by plugins and customization, but I reckon migrating to a modern JavaScript site could make it more maintainable.</p><h3>Getting Started with Docusaurus v2</h3><p>After a quick research, I narrowed down to two options: <a href="https://docusaurus.io/">Docusaurus</a> and <a href="https://www.docz.site/">Docz</a>. Both are reputable and have similar features. I eventually chose Docusaurus because I think it is easier to use.</p><p>To be adventurous, I decided to try out the Docusaurus v2, which is still in 2.0.0-alpha.56 at the time of writing.</p><p>To <a href="https://v2.docusaurus.io/docs/installation">get started</a>, I ran an npx command that initializes the project.</p><pre>npx <a href="http://twitter.com/docusaurus/init">@docusaurus/init</a>@next init [name] classic</pre><p>After that, yarn start will run the site on http://localhost:3000 and it looks very nice already.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2vVsrDCE3kWqpWnHph-AYg.png" /><figcaption>The built-in dark mode has a pleasant looking.</figcaption></figure><h3>Fail Attempt to Enable Search</h3><p>Next up, I want to enable the <a href="https://v2.docusaurus.io/docs/search">search using Algolia DocSearch</a>. As the site is expected to run on private network, <a href="https://docsearch.algolia.com/docs/run-your-own/#run-the-crawl-from-the-docker-image">running the crawl from Docker image</a> is the way to go.</p><pre>docker run -it --env-file=.env -e &quot;CONFIG=$(cat algolia-config.json | jq -r tostring)&quot; algolia/docsearch-scraper</pre><p>After a few fail attempts, I realize:</p><ul><li>Algolia DocSearch crawler <a href="https://discourse.algolia.com/t/locally-hosted-docsearch-scraper-unable-to-crawl-site-running-on-a-local-web-server/5847/2">could not handle port number in site URL</a>. To make it works, we need to host our site at HTTP port (80) or HTTPS port (443).</li><li>Despite <a href="https://v2.docusaurus.io/docs/cli#docusaurus-cli-commands">Docusaurus CLI</a> has --port option, it doesn’t allow port 80. If the port option is set as 80, it will be automatically changed to 1024 instead (or other port if your port 1024 is occupied).</li></ul><p>That leaves me no choice but to host the Docusaurus somewhere, instead of running on my local. I decided to use AWS S3.</p><h3>Hosting on S3</h3><p><a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html">AWS official docs</a> should be the best place to start with. I followed the steps and did the following:</p><ul><li>Created S3 bucket with public access (untick “Block <em>all</em> public access”)</li><li><a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/EnableWebsiteHosting.html">Enabled website hosting</a> and <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/IndexDocumentSupport.html">configured index document</a> (set as index.html)</li><li><a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html#bucket-policy-static-site">Add bucket policy</a> to make objects publicly readable</li></ul><p>To make it even nicer, I went extra mile to configure SSL with AWS Certificate Manager (ACM) then expose it via AWS CloudFront. I mainly followed this <a href="https://www.freecodecamp.org/news/simple-site-hosting-with-amazon-s3-and-https-5e78017f482a/">freeCodeCamp guide</a>, and here are some notes and mistakes I made:</p><ul><li>In my case, I already have a domain name from AWS Route 53, that makes things simpler. I just need to request a certificate from ACM and configure accordingly.</li><li>When configuring CloudFront, set the <strong>Origin Domain Name</strong> as &lt;BUCKET_NAME&gt;.s3-website-&lt;REGION&gt;.amazonaws.com. Do not choose the S3 option from drop down, that might cause routing problems to your site later. I faced a situation where the homepage is loading fine, and I can navigate to child pages from there; however, if I go directly to a child page, it will return HTTP 403 to me.</li></ul><h3>Reattempt to Enable Search</h3><p>With the static site up and running, I reattempted to enable search with a trial Algolia account and a sample config found <a href="https://docsearch.algolia.com/docs/config-file/">here</a>. Turned out it is not compatible for Docusaurus! I kept getting nbHits 0 that indicates nothing is indexed.</p><p>Eventually I found a <a href="https://github.com/algolia/docsearch-configs/blob/master/configs/docusaurus-2.json">correct sample</a> from the config list in algolia/docsearch-configs repo. Below is a <strong>working sample</strong>.</p><pre>{<br>    &quot;index_name&quot;: &quot;example&quot;,<br>    &quot;start_urls&quot;: [&quot;https://www.example.com/docs&quot;],<br>    &quot;selectors&quot;: {<br>        &quot;lvl0&quot;: {<br>            &quot;selector&quot;: &quot;.menu__link--sublist.menu__link--active&quot;,<br>            &quot;global&quot;: true,<br>            &quot;default_value&quot;: &quot;Documentation&quot;<br>        },<br>        &quot;lvl1&quot;: &quot;header h1&quot;,<br>        &quot;lvl2&quot;: &quot;article h2&quot;,<br>        &quot;lvl3&quot;: &quot;article h3&quot;,<br>        &quot;lvl4&quot;: &quot;article h4&quot;,<br>        &quot;lvl5&quot;: &quot;article h5&quot;,<br>        &quot;lvl6&quot;: &quot;article h6&quot;,<br>        &quot;text&quot;: &quot;article p, article li&quot;<br>    }<br>}</pre><p>Here is how the working search feature looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v03J2KdL61ZjlZxYCdBDqg.png" /><figcaption>I didn’t expect a live search preview!</figcaption></figure><h3>CI/CD with Azure DevOps</h3><p>Unlike the WordPress that we have, Docusaurus has markdown support and all its content are versioned on Git.</p><p>To maximize the features and provide a better content creation process, I decided to integrate it with CI/CD. It will automatically build and deploy the site whenever new changes are made.</p><p>The enterprise is using Azure DevOps, thus it is my go-to CI/CD tool. I used a <strong>Node.js with React</strong> template for the YAML, then made it a multi-stage pipeline. The build is done by yarn build, while the deployment is simply an upload to S3 (the new files will replace the old ones). The only thing to note is remember to invalidate CloudFront cache, so that your content will be refreshed upon deployment.</p><pre># Node.js with React<br># Build a Node.js project that uses React.<br># Add steps that analyze code, save build artifacts, deploy, and more:<br># <a href="https://docs.microsoft.com/azure/devops/pipelines/languages/javascript">https://docs.microsoft.com/azure/devops/pipelines/languages/javascript</a></pre><pre>trigger:<br>  - master</pre><pre>stages:<br>  - stage: Build<br>    jobs:<br>      - job: Build<br>        pool:<br>          vmImage: &quot;ubuntu-latest&quot;<br>        steps:<br>          - task: NodeTool@0<br>            inputs:<br>              versionSpec: &quot;10.x&quot;<br>            displayName: &quot;Install Node.js&quot;<br>          - script: |<br>              yarn<br>              yarn build<br>            displayName: &quot;yarn and yarn build&quot;<br>          - task: CopyFiles@2<br>            inputs:<br>              SourceFolder: &quot;build/&quot;<br>              Contents: &quot;**&quot;<br>              TargetFolder: &quot;$(Build.ArtifactStagingDirectory)&quot;<br>          - task: PublishBuildArtifacts@1<br>            inputs:<br>              PathtoPublish: &quot;$(Build.ArtifactStagingDirectory)&quot;<br>              ArtifactName: &quot;drop&quot;<br>              publishLocation: &quot;Container&quot;<br>  - stage: Deployment<br>    displayName: Deploy to S3<br>    dependsOn: Build<br>    condition: succeeded()<br>    jobs:<br>      - deployment:<br>        pool:<br>          vmImage: &quot;ubuntu-latest&quot;<br>        environment: dev<br>        variables:<br>          - name: DistributionId<br>            value: &quot;YOUR_DISTRIBUTION_ID&quot;<br>        strategy:<br>          runOnce:<br>            deploy:<br>              steps:<br>                - task: S3Upload@1<br>                  inputs:<br>                    awsCredentials: &quot;YOUR_AWS_SERVICE_CONNECTION&quot;<br>                    regionName: &quot;YOUR_AWS_REGION_NAME&quot;<br>                    bucketName: &quot;YOUR_BUCKET_NAME&quot;<br>                    sourceFolder: &quot;$(Pipeline.Workspace)/drop/&quot;<br>                    globExpressions: &quot;**&quot;<br>                - task: AWSCLI@1<br>                  inputs:<br>                    awsCredentials: &quot;YOUR_AWS_SERVICE_CONNECTION&quot;<br>                    awsCommand: &quot;cloudfront&quot;<br>                    awsSubCommand: &quot;create-invalidation&quot;<br>                    awsArguments: &#39;--distribution-id $(DistributionId) --paths &quot;/*&quot;&#39;<br>                  displayName: &quot;Invalidate CloudFront Cache&quot;</pre><p>To make it even more perfect, we should include a step to <strong>automatically re-crawl the site</strong> to update the search index after deployment. I reckon docker run would not work in Microsoft-hosted agent, the crawler should be <a href="https://docsearch.algolia.com/docs/run-your-own/#running-the-crawler-from-the-code-base">running from code base</a>. But I didn’t add this step as part of this exercise.</p><h3>Final Thoughts</h3><p>This served as a nice weekend exercise. I learnt how easy it is to bring up a nice documentation site with awesome features, integrate with Algoria DocSearch, and hosting static site on AWS.</p><p>The outcome is very satisfying because the rich features of Docusaurus can easily overkill WordPress sites.</p><ul><li>Search with Algolia DocSearch</li><li>Blogging</li><li>Integrated with Git</li><li>Markdown support</li><li>Customizable (built in React)</li><li>Automatically deploy content changes with CI/CD</li></ul><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a89565bf97f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/w-logs/hosting-docusaurus-on-aws-ci-cd-with-azure-devops-a89565bf97f0">Hosting Docusaurus on AWS + CI/CD with Azure DevOps</a> was originally published in <a href="https://medium.com/w-logs">w:Logs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JDBC for Spring WebFlux: Spring Data R2DBC]]></title>
            <link>https://medium.com/w-logs/jdbc-for-spring-webflux-spring-data-r2dbc-99690208cfeb?source=rss-7925d9e40ad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/99690208cfeb</guid>
            <category><![CDATA[jdbc]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[webflux]]></category>
            <dc:creator><![CDATA[Wai Loon]]></dc:creator>
            <pubDate>Sat, 18 May 2019 04:44:21 GMT</pubDate>
            <atom:updated>2019-05-18T04:45:51.367Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Disclaimer: The project is still in experiment mode, do not use it in production.</em></p><blockquote>Sample project on GitHub:<br><a href="https://github.com/vxavictor513/kubenote/tree/master/r2dbc-and-flyway">https://github.com/vxavictor513/kubenote/tree/master/r2dbc-and-flyway</a></blockquote><p><a href="https://spring.io/projects/spring-data-r2dbc"><strong>Spring Data R2DBC</strong></a> 1.0 is the reactive/non-blocking alternative for JDBC in Spring WebFlux world, and it has recently hit <a href="https://spring.io/blog/2019/05/15/spring-data-r2dbc-1-0-m2-and-spring-boot-starter-released">milestone 2</a>, with several nice improvements, such as:</p><ol><li>MySQL support using <a href="https://github.com/jasync-sql/jasync-sql">jasync-sql</a></li><li>Url-based configuration</li><li>Connection pool support</li></ol><p>However, the announcement and documentation available in the internet is rather scarce, thus I am writing this to share some tips I learnt when playing with Spring Data R2DBC.</p><h3>Dependencies</h3><h4>spring-boot-starter-data-r2dbc</h4><p>This is the primary dependency to enable Spring Data R2DBC. Don’t be confused with spring-boot-starter-r2dbc that only enables R2DBC client without Spring Data implementation.</p><p>r2bdc-pool and spring-jdbc are required for connection pooling.</p><pre>&lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.boot.experimental&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-boot-starter-data-r2dbc&lt;/artifactId&gt;<br>   &lt;version&gt;0.1.0.M1&lt;/version&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>   &lt;groupId&gt;io.r2dbc&lt;/groupId&gt;<br>   &lt;artifactId&gt;r2dbc-pool&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><h4>jasync-r2dbc-mysql</h4><p>Add this when you’re using MySQL.</p><pre>&lt;dependency&gt;<br>   &lt;groupId&gt;com.github.jasync-sql&lt;/groupId&gt;<br>   &lt;artifactId&gt;jasync-r2dbc-mysql&lt;/artifactId&gt;<br>   &lt;version&gt;0.9.41&lt;/version&gt;<br>&lt;/dependency&gt;</pre><h4>r2dbc-postgresql</h4><p>Add this when you’re using PostgreSQL.</p><pre>&lt;dependency&gt;<br>   &lt;groupId&gt;io.r2dbc&lt;/groupId&gt;<br>   &lt;artifactId&gt;r2dbc-postgresql&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><h4>Repository</h4><p>As the dependencies are still in experiment mode, we need to add the following Maven repositories to download the dependencies.</p><pre>&lt;repositories&gt;<br>   &lt;repository&gt;<br>      &lt;id&gt;spring-libs-milestone&lt;/id&gt;<br>      &lt;url&gt;https://repo.spring.io/libs-milestone&lt;/url&gt;<br>   &lt;/repository&gt;<br>   &lt;repository&gt;<br>      &lt;id&gt;spring-libs-snapshot&lt;/id&gt;<br>      &lt;url&gt;https://repo.spring.io/libs-snapshot&lt;/url&gt;<br>   &lt;/repository&gt;<br>&lt;/repositories&gt;</pre><h3>Configuration</h3><p>Spring Data R2DBC has auto configuration that does the magic to initialize all necessary beans. All we need to do is just configuring properties at application.properties.</p><blockquote>Some documentations show examples with<em>rdbc driver, </em>e.g.rdbc:postgresql://127.0.0.1:5432/demo, but that is outdated.</blockquote><pre># MySQL<br>spring.r2dbc.url=r2dbc:pool:mysql://127.0.0.1:3306/demo<br>spring.r2dbc.username=user<br>spring.r2dbc.password=password<br>spring.r2dbc.pool.initial-size=100<br>spring.r2dbc.pool.max-size=500<br>spring.r2dbc.pool.max-idle-time=30m<br>spring.r2dbc.pool.validation-query=SELECT 1</pre><p>For PostgreSQL, use postgresql protocol.</p><pre># PostgreSQL<br>spring.r2dbc.url=r2dbc:pool:postgresql://127.0.0.1:5432/demo</pre><p>To omit connection pooling, remove :pool.</p><pre>spring.r2dbc.url=r2dbc:mysql://127.0.0.1:3306/demo</pre><h3>Into the Code</h3><ol><li>Add @EnableR2dbcRepositories in your application class.</li></ol><pre>@SpringBootApplication<br>@EnableR2dbcRepositories<br>public class R2dbcApplication {<br><br>   public static void main(String[] args) {<br>      SpringApplication.<em>run</em>(R2dbcApplication.class, args);<br>   }<br><br>}</pre><p>2. Auto-wire DatabaseClient in your repository class. It is just like JdbcTemplate.</p><pre>@Repository<br>public class PetRepository {<br><br>   @Autowired<br>   private DatabaseClient databaseClient;<br><br>   public Mono&lt;Pet&gt; getOne(String name) {<br>      return databaseClient<br>            .execute().sql(&quot;SELECT name, sound FROM pets WHERE name = :name&quot;)<br>            .bind(&quot;name&quot;, name)<br>            .map((row, rowMetadata) -&gt; new Pet(<br>                  row.get(&quot;name&quot;, String.class),<br>                  row.get(&quot;sound&quot;, String.class)<br>            )).one()<br>            .switchIfEmpty(Mono.<em>error</em>(new RuntimeException(&quot;Pet not found!&quot;)));<br>   }<br>}</pre><p>Or using fluent API provided by Spring Data.</p><pre>@Repository<br>public class PetRepository {<br><br>   @Autowired<br>   private DatabaseClient databaseClient;<br><br>   public Mono&lt;Pet&gt; getOne(String name) {<br>      return databaseClient<br>            .select().from(&quot;pets&quot;)<br>            .matching(Criteria.<em>where</em>(&quot;pets&quot;).is(name))<br>            .as(Pet.class).fetch().one()<br>            .switchIfEmpty(Mono.<em>error</em>(new RuntimeException(&quot;Pet not found!&quot;)));<br>   }<br>}</pre><p>3. You can also implement ReactiveCrudRepository interface if you prefer ORM style.</p><h3>That’s it!</h3><p>Do check out my sample project on GitHub where you can see the Spring Data R2DBC in action.</p><blockquote><a href="https://github.com/vxavictor513/kubenote/tree/master/r2dbc-and-flyway">https://github.com/vxavictor513/kubenote/tree/master/r2dbc-and-flyway</a></blockquote><p>Thanks for reading!</p><h3>Extended Reading</h3><ol><li><a href="https://spring.io/blog/2019/03/20/spring-tips-reactive-mysql-support-with-jasync-sql-and-r2dbc">https://spring.io/blog/2019/03/20/spring-tips-reactive-mysql-support-with-jasync-sql-and-r2dbc</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99690208cfeb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/w-logs/jdbc-for-spring-webflux-spring-data-r2dbc-99690208cfeb">JDBC for Spring WebFlux: Spring Data R2DBC</a> was originally published in <a href="https://medium.com/w-logs">w:Logs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Log Exception Properly]]></title>
            <link>https://medium.com/w-logs/how-to-log-exception-properly-6aa80b62ff8a?source=rss-7925d9e40ad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6aa80b62ff8a</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Wai Loon]]></dc:creator>
            <pubDate>Tue, 29 Jan 2019 00:50:37 GMT</pubDate>
            <atom:updated>2019-01-29T00:55:27.296Z</atom:updated>
            <content:encoded><![CDATA[<p>Logging is simple, but not everyone knows how to do it right.</p><p>Junior developers often find their application logs unhelpful because it doesn’t tell how their codes went wrong. Eventually they spam logs between every single method invocation, at every IF junction, and print out every values that they can find, hoping the logs would cover every single step and give a better picture of what is happening in the code. And there we are, having lots of redundant logging and messy code.</p><p>There are two common root causes that I observe:</p><ol><li>Developer does not know how to log exception properly, thus no stack trace is printed when exception occurred.</li><li>Developer doesn’t know how to do debugging using breakpoint in their IDE.</li></ol><p>We will discuss about how to log exception properly today.</p><p>Below is a Java Spring Boot snippet. We have a logic in a try statement that throws NullPointerException, then we log it in different formats to see the difference.</p><pre>public String someMethod() {<br>    Integer a = null;<br>    try {<br>        if (a.toString().equals(&quot;1&quot;)) {<br>            a = 0;<br>        }<br>    } catch (Exception ex) {<br>        <em>log</em>.error(&quot;someMethod ::&quot; + &quot;exception&quot;);<br>        <em>log</em>.error(&quot;Error happened. a is &quot;, a);<br>        <em>log</em>.error(ex.getMessage());<br>        <em>log</em>.error(&quot;Hello&quot;, ex.getMessage());<br>        <em>log</em>.error(&quot;Hello again&quot;, ex);<br>    }<br>    return &quot;OK&quot;;<br>}</pre><h4>Common Mistake 1: Not logging anything in `catch` statement</h4><pre>try {<br>    if (a.toString().equals(&quot;1&quot;)) {<br>        a = 0;<br>    }<br>} catch (Exception ex) {<br>    return &quot;error&quot;;<br>}<br>return &quot;OK&quot;;</pre><p>The problem with this is developer would not know that an error has happened.</p><h4>Common Mistake 2: Only log developer’s message</h4><pre>log.error(&quot;someMethod ::&quot; + &quot;exception&quot;);<br><em>log</em>.error(&quot;Error happened. a is &quot;, a);</pre><p>It might look ridiculous, but these are real-life examples. Without any information about the exception, the log almost always useless.</p><h4>Common Mistake 3: Log the message of the exception</h4><pre>log.error(ex.getMessage());<br><em>log</em>.error(&quot;Hello&quot;, ex.getMessage());</pre><p>In this example, the message of NullPointerException is just null. Not helpful.</p><pre>2019-01-29 08:00:41.009 ERROR 42147 --- [ctor-http-nio-3] com.example.rsocketdemo.DemoController   : null</pre><h3>Best Practice: Log the exception object.</h3><pre><em>log</em>.error(&quot;Hello again&quot;, ex);</pre><p>By logging the developer message together with the whole exception object, we can see the developer message is printed first, followed by the exception name and message, then the stack trace.</p><p>This gives us a complete picture of what methods were invoked when exception occurred, down to the library level.</p><blockquote>Note: Stack trace below is trimmed with ... because the full one is too long to display here.</blockquote><pre>2019-01-29 08:30:42.142 ERROR 42218 --- [ctor-http-nio-2] com.example.rsocketdemo.DemoController   : Hello again</pre><pre>java.lang.NullPointerException: null<br> at com.example.rsocketdemo.DemoController.someMethod(DemoController.java:14) ~[classes/:na]<br> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]<br> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]<br> ...<br> at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897) ~[netty-common-4.1.31.Final.jar:4.1.31.Final]<br> at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6aa80b62ff8a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/w-logs/how-to-log-exception-properly-6aa80b62ff8a">How to Log Exception Properly</a> was originally published in <a href="https://medium.com/w-logs">w:Logs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Java 11 on MacOS with HomeBrew]]></title>
            <link>https://medium.com/w-logs/installing-java-11-on-macos-with-homebrew-7f73c1e9fadf?source=rss-7925d9e40ad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f73c1e9fadf</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[homebrew]]></category>
            <dc:creator><![CDATA[Wai Loon]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 07:10:25 GMT</pubDate>
            <atom:updated>2019-01-27T07:18:35.818Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Prerequisite:</strong> <a href="https://brew.sh/">HomeBrew</a></p><h3>Before we start</h3><p>Find locations of previously installed Java JDK:</p><pre>$ /usr/libexec/java_home -V<br>Matching Java Virtual Machines (1):<br>    1.8.0_162, x86_64: &quot;Java SE 8&quot; /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home</pre><p>Find the location of a specific Java version using -v:</p><pre>$ /usr/libexec/java_home -v 1.8<br>/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home</pre><h3>Install with HomeBrew</h3><ol><li>Update HomeBrew.</li></ol><pre>$ brew update</pre><p>2. Add the casks tap.</p><pre>$ brew tap homebrew/cask-versions</pre><p>3. Install a specific version of the JDK such as java8, java10 or java for the current.</p><pre>$ brew cask install java</pre><h3>Switching versions</h3><p>Add the following aliases to .bash_profile.</p><pre>export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)<br>export JAVA_11_HOME=$(/usr/libexec/java_home -v11)<br><br>alias java8=&#39;export JAVA_HOME=$JAVA_8_HOME&#39;<br>alias java11=&#39;export JAVA_HOME=$JAVA_11_HOME&#39;<br><br># default to Java 11<br>java11</pre><p>Reload .bash_profile for the aliases to take effect.</p><pre>$ source ~/.bash_profile</pre><p>Use the alias to change version.</p><pre>$ java8<br>$ java -version<br>java version &quot;1.8.0_162&quot;<br>Java(TM) SE Runtime Environment (build 1.8.0_162-b12)<br>Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)</pre><p>Full explanation by <a href="https://stackoverflow.com/users/3679676/jayson-minard">Jayson Minard</a>: <a href="https://stackoverflow.com/a/52524114/5366727">https://stackoverflow.com/a/52524114/5366727</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f73c1e9fadf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/w-logs/installing-java-11-on-macos-with-homebrew-7f73c1e9fadf">Installing Java 11 on MacOS with HomeBrew</a> was originally published in <a href="https://medium.com/w-logs">w:Logs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forwarding IBM MQ Messages to Kafka using Kafka Connect]]></title>
            <link>https://medium.com/w-logs/forwarding-ibm-mq-messages-to-kafka-using-kafka-connect-246f8ff811f7?source=rss-7925d9e40ad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/246f8ff811f7</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kafka-connect]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <dc:creator><![CDATA[Wai Loon]]></dc:creator>
            <pubDate>Sat, 26 Jan 2019 17:53:06 GMT</pubDate>
            <atom:updated>2019-01-26T18:09:04.538Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a quick guide to demonstrate how to use<a href="https://github.com/ibm-messaging/kafka-connect-mq-source/blob/master/UsingMQwithKafkaConnect.md">kafka-connect-mq-source</a> that compliments the <a href="https://developer.ibm.com/messaging/learn-mq/mq-tutorials/mq-connect-to-queue-manager/#docker">IBM MQ Tutorial</a>.</p><p><strong>Prerequisites</strong>: <a href="https://www.docker.com/">Docker</a></p><h3>Run MQ Server in Docker</h3><ol><li>Get the latest image of MQ server from Docker Hub. Verify by docker image.</li></ol><pre>docker pull ibmcom/mq:latest</pre><p>2. Run the MQ server. Once it’s running, verify by docker ps.</p><blockquote>Queue manager: QM1<br>Queue: DEV.QUEUE.1<br>Channel: DEV.APP.SVRCONN<br>Listener DEV.LISTENER.TCP on port 1414</blockquote><pre># Create a volume to persist the data even if container is deleted.<br>docker volume create qm1data</pre><pre># Create a network.<br>docker network create mq-demo-network</pre><pre># Run the image with the following settings.<br>docker run --env LICENSE=accept --env MQ_QMGR_NAME=QM1 --volume qm1data:/mnt/mqm --publish 1414:1414 --publish 9443:9443 --network mq-demo-network --network-alias qmgr --detach --env MQ_APP_PASSWORD=password ibmcom/mq:latest</pre><h3>Run Apache Kafka</h3><ol><li>Download from <a href="https://kafka.apache.org/downloads">https://kafka.apache.org/downloads</a> (any version since 1.0.0 should do), then extract it.</li></ol><pre>tar -xzf kafka_2.11-2.1.0.tgz</pre><p>2. In one terminal, go to the Kafka root directory and run <strong>Zookeeper</strong>.</p><pre>cd kafka_2.11-2.1.0<br>bin/zookeeper-server-start.sh config/zookeeper.properties</pre><p>3. In another terminal, go to the Kafka root directory and run <strong>Kafka server</strong>.</p><pre>cd kafka_2.11-2.1.0<br>bin/kafka-server-start.sh config/server.properties</pre><p>4. In a third terminal, go to the Kafka root directory and run a <strong>Kafka consumer</strong> to listen from a TSOURCE topic (we’ll create it shortly).</p><pre>bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic TSOURCE --from-beginning</pre><blockquote>Note: On Windows platforms use bin\windows\ instead of bin/, and change the script extension to .bat.</blockquote><h3>Run MQ Source Connector</h3><ol><li>Clone and build the connector.</li></ol><pre>git clone https://github.com/ibm-messaging/kafka-connect-mq-source.git<br>cd kafka-connect-mq-source<br>mvn clean package</pre><p>2. Copy the connector configuration file to your home directory to edit it safely.</p><pre>cp config/mq-source.properties ~</pre><p>3. Configure the properties according to our MQ setup.</p><blockquote>Note: remember to uncomment mq.user.name and mq.password properties.</blockquote><pre>mq.queue.manager=QM1<br>mq.connection.name.list=localhost(1414)<br>mq.channel.name=DEV.APP.SVRCONN<br>mq.queue=DEV.QUEUE.1<br>mq.user.name=app<br>mq.password=password<br>topic=TSOURCE</pre><p>4. Run the connector</p><blockquote>Note: Replace &lt;connector-root-directory and &lt;version&gt; by yourself.</blockquote><pre>CLASSPATH=&lt;connector-root-directory&gt;/target/kafka-connect-mq-source-&lt;version&gt;-jar-with-dependencies.jar bin/connect-standalone.sh config/connect-standalone.properties ~/mq-source.properties</pre><h3>Run MQ Client in Docker</h3><ol><li>Download Dockerfile from <a href="https://raw.githubusercontent.com/ibm-messaging/mq-dev-samples/master/gettingStarted/mq-demo-client-application/Dockerfile">here</a>.</li><li>Build and run it.</li></ol><blockquote>Notice that we are connecting it to the same network as MQ server, mq-demo-network.</blockquote><pre>docker build -t mq-demo .<br>docker run --network mq-demo-network -ti mq-demo</pre><p>3. The application will prompt you to enter some settings. Just press return to skip the first 6 questions; enter password for the last one.</p><pre>1. Type the name of your queue manager (leave blank for QM1):<br><br>2. Type the host name or IP address for your queue manager:<br>qmgr<br>3. Type the listener port for your queue manager (leave blank for 1414):<br><br>4. Type the name of the application channel (leave blank for &#39;DEV.APP.SVRCONN&#39;):<br><br>5. Type the name of the queue (leave blank for &#39;DEV.QUEUE.1&#39;):<br><br>6. Type the application user name (leave blank for &#39;app&#39;):<br><br>7. Type the password for this user:<br>password</pre><p>4. When it is up, you will see:</p><pre>Connecting to queue manager &#39;QM1&#39;<br>at address &#39;mq-demo-network(1414)&#39;<br>through channel &#39;DEV.APP.SVRCONN&#39;<br>as user &#39;app&#39;<br>. . .<br>Connected!<br><br>Type PUT [number] to put a given number of messages to the queue<br>Type GET [number] to get a given number of messages to the queue<br>Type AUTO [seconds] to put and get messages automatically for a given number of seconds<br>Type EXIT to quit<br>Type HELP to display this message</pre><h3>Send message to MQ and receive in Kafka</h3><p>In the MQ Client terminal, run put &lt;n&gt; to put <em>n</em> number of messages to the DEV.QUEUE.1 queue.</p><pre>$ put 20<br>Attempting to put 20 messages to the queue...<br>Successfully put 20 messages<br>Check the MQ Console to see that these 20 messages have been added to the queue</pre><p>In the Kafka consumer terminal, you shall see messages coming into the TSOURCE topic. TA DA ~</p><pre>$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic TSOURCE --from-beginning<br>Message #0��������<br>Message #1��������<br>Message #2��������<br>Message #3��������<br>Message #4��������<br>Message #5��������<br>Message #6��������<br>Message #7��������<br>Message #8��������<br>Message #9��������<br>Message #10��������<br>Message #11��������<br>Message #12��������<br>Message #13��������<br>Message #14��������<br>Message #15��������<br>Message #16��������<br>Message #17��������<br>Message #18��������<br>Message #19��������</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=246f8ff811f7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/w-logs/forwarding-ibm-mq-messages-to-kafka-using-kafka-connect-246f8ff811f7">Forwarding IBM MQ Messages to Kafka using Kafka Connect</a> was originally published in <a href="https://medium.com/w-logs">w:Logs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Think twice before implementing Interface classes in Microservices]]></title>
            <link>https://medium.com/w-logs/think-twice-before-implementing-interface-classes-in-microservices-abc67ae11fac?source=rss-7925d9e40ad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/abc67ae11fac</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Wai Loon]]></dc:creator>
            <pubDate>Wed, 09 May 2018 08:40:18 GMT</pubDate>
            <atom:updated>2018-05-14T15:22:00.404Z</atom:updated>
            <content:encoded><![CDATA[<p>Some developers like to use interface class. In general, interface class enables polymorphism. It acts as a contract of functionalities that every implementation class must have; and hides unnecessary methods away.</p><p>However, is it really a good practice to create an interface class for every service class in your application?</p><h3>Why using Interface class?</h3><p>For instance, an AuditLogger interface defines that any audit logger implementation <strong>must</strong> be able to perform send() to send a log message. Then you can have multiple implementation classes to send log message using different broker:</p><ol><li>ActiveMqAuditLogger — send log message using Apache ActiveMQ</li><li>KafkaAuditLogger — send log message using Apache Kafka</li></ol><pre>public interface AuditLogger {<br>    void send(String logMessage);<br>}</pre><pre>public class ActiveMqAuditLogger implements AuditLogger {<br>    @Override<br>    public void send(String logMessage) {<br>        // codes to send log message to ActiveMQ<br>    }<br>}</pre><pre>public class KafkaAuditLogger implements AuditLogger {<br>    @Override<br>    public void send(String logMessage) {<br>        // codes to send log message to Kafka<br>    }<br>}</pre><p>When another class (e.g. SomeService) needs to perform audit logging, in <a href="https://spring.io/">Spring</a>, it can just auto-wire the AuditLogger interface and use @Qualifier to specify which message broker to be used. The advantage is that the developer who writes this class does not need to know what happens under the hood. And it can be easily reconfigured to send audit log using another broker simply by updating the value at @Qualifer. This is an example of <strong>polymorphism</strong>.</p><pre>@Service<br>public class SomeService {</pre><pre>    @Autowired<br>    @Qualifier(&quot;KafkaAuditLogger&quot;)<br>    private AuditLogger auditLogger;</pre><pre>    public void someMethod() {<br>        // The log message will be sent to Kafka<br>        auditLogger.send(&quot;My audit log message&quot;);<br>    }<br>}</pre><h3>But interface can be redundant. Why?</h3><p>In the example below, we have MyRepositoryImpl class implementing MyRepository interface. The interface here is redundant, especially when you’re developing microservices.</p><pre>@Controller<br>public class MyController() {<br>    <br>    @Autowired<br>    private MyService myService;</pre><pre>    @GetMapping(&quot;/&quot;)<br>    public String findNameById(int id) {<br>        return myService.findNameById(id);<br>    }<br>}</pre><pre>@Service<br>public class MyService() {<br>    <br>    @Autowired<br>    private MyRepository myRepository;</pre><pre>    public String findNameById(int id) {<br>        return myRepository.findNameById(id);<br>    }<br>}</pre><pre>@Component<br>public interface MyRepository {<br>    String findNameById(int id);<br>}</pre><pre>@Repository<br>public class MyRepositoryImpl implements MyRepository {<br>    public String findNameById(int id) {<br>        // Some codes to retrieve name from a database<br>        return name;<br>    }<br>}</pre><h4>1. Stop dreaming about “future” polymorphism</h4><p>First, the benefits of polymorphism does not exist when there is only ONE implementation class. Someone might argue that there <strong>might</strong> be multiple implementation here in the future. NO!</p><p>Evaluate these:</p><ol><li>What if multiple implementation never happen to this class in the future?</li><li>What are the chances that you would need to keep the old implementation when a new implementation is introduced? Referring to the example, let’s say the old implementation retrieves name by ID from MySQL, and a new implementation retrieves it from MongoDB. Due to data integrity, your source of data should be only one. That means nobody should ever be retrieving name from MySQL anymore!</li></ol><h4>2. Nobody uses your implementation class except your team</h4><blockquote>There are a number of situations in software engineering when it is important for disparate groups of programmers to agree to a “contract” that spells out how their software interacts. Each group should be able to write their code without any knowledge of how the other group’s code is written. Generally speaking, <em>interfaces</em> are such contracts. — <a href="https://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html">Java Documentation</a></blockquote><p>In a monolithic application, multiple teams are working on the same piece of source code. Let’s take banking app as example, there can be Team A working on customer profile functionality, Team B working on fund transfer functionality, and Team C working on bill payment functionality. <strong>To invoke a service, developers of other functionalities refer to interface classes.</strong></p><p>Translating the same use case to microservice (MS) landscape, these 3 functionalities will become 3 individual microservices: Customer MS, Transfer MS, Payment MS. By architecture, every individual microservice is isolated in its own source code, under its own git project. Naturally, no other team will need to read your microservice’s source code. When Transfer MS needs to retrieve customer profile, it calls a GET endpoint of Customer MS. REST API is the contract between microservices. <strong>To invoke a service, developers of other microservices refer to the API specs from documentation, instead of referring to interface classes.</strong></p><p>What is the point of adding interface class when the person who reads the implementation class is always be you or your teammate?</p><h4>3. Interface is not always a best practice</h4><p>Someone might still say implementing interface classes is a best practice so we should write it regardless. This statement is actually not true.</p><p>The real best practice is actually to follow <a href="https://en.wikipedia.org/wiki/KISS_principle">KISS principle</a>. Make your application simpler to achieve high readability and maintainability. Plus, microservices are meant to be lean.</p><p>To conclude, interface class exists for a purpose, but it is not something that is suitable for all use cases. It is a fallacy to think that interface should be implemented in every service classes.</p><h4>BONUS TIPS!</h4><p>When using IntelliJ, ⌘B (Windows: Control + B) on an interface class will navigate you to the interface source code. <strong>To quickly navigate to the implementation class, use ⌥⌘B (Control+Alt+B) instead!</strong></p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abc67ae11fac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/w-logs/think-twice-before-implementing-interface-classes-in-microservices-abc67ae11fac">Think twice before implementing Interface classes in Microservices</a> was originally published in <a href="https://medium.com/w-logs">w:Logs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>