<?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 DJ Bowden on Medium]]></title>
        <description><![CDATA[Stories by DJ Bowden on Medium]]></description>
        <link>https://medium.com/@djbowden?source=rss-e69322050d94------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sv2mq1XHK3UiA1Si2snsRw.jpeg</url>
            <title>Stories by DJ Bowden on Medium</title>
            <link>https://medium.com/@djbowden?source=rss-e69322050d94------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:55:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@djbowden/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[Writing a microservice with Spring boot, JAX-RS, and Mongo DB]]></title>
            <link>https://medium.com/@djbowden/writing-a-microservice-with-spring-boot-jax-rs-and-mongo-db-a0ee68ffe5b3?source=rss-e69322050d94------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0ee68ffe5b3</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[jax-rs]]></category>
            <dc:creator><![CDATA[DJ Bowden]]></dc:creator>
            <pubDate>Mon, 20 Feb 2017 21:15:28 GMT</pubDate>
            <atom:updated>2017-02-20T21:36:02.462Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*FUwb6dxf4cvXjRhX44hd2w.png" /></figure><p>For information on what a microservice is and how they are used, head over to this other post I made outlining the basics.</p><p><a href="https://medium.com/@djbowden/what-is-microservice-architecture-ec829004532d">What is microservice architecture?</a></p><p>I used to write all of my services using Java but started shying away from it once I got more and more familiar with other languages and frameworks like Node JS and Express. Node JS is great for writing services because of how simple the configuration is, and how fast you can start developing. The example service I’m going to walk through uses Spring boot with JAX-RS and Mongo DB as a datastore. Spring boot gives a similar feeling to Node JS projects by quickly letting you set up a project with minimal dependencies and configuration.</p><p>First head over to the Spring Initializr page to get your project skeleton created. <a href="http://start.spring.io/">http://start.spring.io/</a></p><p>In this example project we will only need the JAX-RS implementation (Jersey) and spring-boot-starter-data-mongodb dependencies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tw8sfcYEQXCZltXIeFYcLg.png" /></figure><p>Make sure you have Java 8 installed and the most recent version of Spring tool suite. You will also need to make sure your JAVA_HOME environment variable is set to your jdk8 installation directory.</p><p>Download the project and import it as an existing maven project into STS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*ekidhsd2hZwaA7STaKzyNQ.jpeg" /><figcaption>Basic project structure</figcaption></figure><p>I have a local Mongo DB server running, so I’m going to create some test data for the service to interact with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*UQ_1YQpo4zcfAm2_us-IDw.png" /><figcaption>Using Robomongo for data visualization</figcaption></figure><p>Next we will update our application properties with the name of our database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*to2wjGjZVcIt4KXQj0Uhmg.png" /></figure><p>Next configure our Application.java to register our rest resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*y7VKc5FDPPPqNS_PKcW_VA.png" /></figure><p>In this snippet I’ve updated the Application class to extend Jersey ResourceConfig and added a constructor for us to register our resources. You can see here I originally added them by package name because I could set it and forget it, but later I discovered there is a bug in Jersey when you compile your project into a JAR and try to run it standalone. In order to mitigate it you have to register the endpoints manually.</p><p>Next I created a POJO representation for our data entity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*V1Igsr8rOxtC6INP2zDJ_w.png" /></figure><p>I configured a DAO (data access object) for retrieving data from Mongo by creating an interface extending Springs MongoRepository interface. This allows you to retrieve data by creating specific method signatures that map to individual queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*a166lohRFy0n4hB1cIit7g.png" /></figure><p>In this example I’ve exposed a findAll method. By mentioning the word “all” and by returning a collection of my specific entity, the repository knows that I’m just doing a general “all” query. Same goes for the getExpenseById method signature. By returning 1 instance of Expense and passing a parameter of “id” which matches the id in our entity representation, it knows to do a findById in Mongo. Typically once you create an interface, you need to create a corresponding implementation. But by using the MongoRepository, this implementation is created for us in Spring’s IOC container and can be injected wherever necessary. There is also a spring Transactional annotation, which allows us to specify that the methods in this class should rollback if they don’t complete all the way through successfully. This is good if some inserts succeed but others fail, you wouldn’t want any orphaned records so you back out everything.</p><p>Lastly lets set up our endpoint so we can expose the data</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*3yat_4OFJX0oujkeu7IAxg.png" /></figure><p>In this example I’ve injected the implementation of ExpenseDao that was created for us so that I can access the data. I’ve also set up a few GET methods for retrieving the data over http. All of this is pretty standard for JAX-RS. I’ve also added the ManagedAsync annotation to the method. Similar to how NodeJS has an event driven non blocking IO, we can use Jersey’s ManagedAsync and inject a Suspended asyncResponse to allow us to asynchronously perform computationally heavy operations and return the data when we are done. This prevents the process from waiting for data from the database and frees up resources for other operations while you wait. For more information on this, check out this other post on Medium by <a href="https://medium.com/u/5fdb8606e795">Bruno Simioni</a>.</p><p><a href="https://medium.com/@brunosimioni/jersey-jax-rs-with-non-blocking-io-ec9ab3be6275">Jersey / JAX-RS with non-blocking IO</a></p><p>In order to run the project just right click on it and click run as -&gt; spring boot application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*jOJRwFc9N5PRLsZ89cwJzQ.png" /></figure><p>If everything works you should see your application fire up like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7xFXGLtcYGJCIHurPVm3Kg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*4kq3gpwTXU_EyNhtPVylWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*uU_Jwgf3n7eqyWlRIQMuSQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0ee68ffe5b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is microservice architecture?]]></title>
            <link>https://medium.com/@djbowden/what-is-microservice-architecture-ec829004532d?source=rss-e69322050d94------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec829004532d</guid>
            <category><![CDATA[client-side-architecture]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[DJ Bowden]]></dc:creator>
            <pubDate>Mon, 20 Feb 2017 20:37:19 GMT</pubDate>
            <atom:updated>2017-02-20T21:44:08.771Z</atom:updated>
            <content:encoded><![CDATA[<p>A microservice is a web resource acting as a single facet that comes together with other microservices to comprise an entire application. Microservice architecture is becoming increasingly popular due to the modularity, reusability, scalability, and speed of development. A typical example of this would be a browser UI or mobile app retrieving and sending data to several of the microservices in order to facilitate a business capability. Each of these services can be modified and redeployed without impacting or taking down any of the others. The consumer is agnostic to the technology stack or datastore used in these services and thus they could hypothetically be written in different languages and consuming all different types of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*pcVDadn6qHv3TrAeT29F6Q.png" /><figcaption>Made using Violet UML</figcaption></figure><p>In the above example you can see the separation of concerns between the different web resources. I’ve used JWT just to exemplify how a user can be authenticated across many resources and share important user information without coupling the services. If an update needs to be done to the email service, we can gracefully redeploy it by taking down 1 process and a time, reducing our potential to cause any downtime. If going forward we have more users, we can horizontally scale by increasing the number of these microservice processes and putting them behind a load balancer like PM2 or HAproxy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec829004532d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>