{"id":41333,"date":"2015-07-02T13:00:18","date_gmt":"2015-07-02T10:00:18","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=41333"},"modified":"2015-07-01T12:12:56","modified_gmt":"2015-07-01T09:12:56","slug":"learning-spring-cloud-writing-a-microservice","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html","title":{"rendered":"Learning Spring-Cloud &#8211; Writing a microservice"},"content":{"rendered":"<p>Continuing my Spring-Cloud learning journey, <a href=\"http:\/\/www.javacodegeeks.com\/2015\/06\/learning-spring-cloud-infrastructure-and-configuration.html\">earlier<\/a> I had covered how to write the infrastructure components of a typical <a href=\"http:\/\/projects.spring.io\/spring-cloud\/\">Spring-Cloud<\/a> and <a href=\"http:\/\/netflix.github.io\/\">Netflix OSS<\/a> based micro-services environment &#8211; in this specific instance two critical components, Eureka to register and discover services and Spring Cloud Configuration to maintain a centralized repository of configuration for a service. Here I will be showing how I developed two dummy micro-services, one a simple &#8220;pong&#8221; service and a &#8220;ping&#8221; service which uses the &#8220;pong&#8221; service.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/Sample-ping-pong1.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-41377\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/Sample-ping-pong1.png\" alt=\"Sample-ping-pong\" width=\"640\" height=\"506\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/Sample-ping-pong1.png 640w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/Sample-ping-pong1-300x237.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<h2>Sample-Pong microservice<\/h2>\n<p>The endpoint handling the &#8220;ping&#8221; requests is a typical Spring MVC based endpoint:<\/p>\n<pre class=\" brush:java\">@RestController\r\npublic class PongController {\r\n\r\n    @Value(\"${reply.message}\")\r\n    private String message;\r\n\r\n    @RequestMapping(value = \"\/message\", method = RequestMethod.POST)\r\n    public Resource&lt;MessageAcknowledgement&gt; pongMessage(@RequestBody Message input) {\r\n        return new Resource&lt;&gt;(\r\n                new MessageAcknowledgement(input.getId(), input.getPayload(), message));\r\n    }\r\n\r\n}<\/pre>\n<p>It gets a message and responds with an acknowledgement. Here the service utilizes the Configuration server in sourcing the <i>&#8220;reply.message&#8221;<\/i> property. So how does the &#8220;pong&#8221; service find the configuration server, there are potentially two ways &#8211; directly by specifying the location of the configuration server, or by finding the Configuration server via Eureka. I am used to an approach where Eureka is considered a source of truth, so in this spirit I am using Eureka to find the Configuration server. Spring Cloud makes this entire flow very simple, all it requires is a &#8220;bootstrap.yml&#8221; property file with entries along these lines:<\/p>\n<pre class=\" brush:java\">---\r\nspring:\r\n  application:\r\n    name: sample-pong\r\n  cloud:\r\n    config:\r\n      discovery:\r\n        enabled: true\r\n        serviceId: SAMPLE-CONFIG\r\n\r\neureka:\r\n  instance:\r\n    nonSecurePort: ${server.port:8082}\r\n  client:\r\n    serviceUrl:\r\n      defaultZone: http:\/\/${eureka.host:localhost}:${eureka.port:8761}\/eureka\/<\/pre>\n<p>The location of Eureka is specified through the <i>&#8220;eureka.client.serviceUrl&#8221;<\/i> property and the &#8220;spring.cloud.config.discovery.enabled&#8221; is set to &#8220;true&#8221; to specify that the configuration server is discovered via the specified Eureka server.<\/p>\n<p><b>Just a note<\/b>, this means that the Eureka and the Configuration server have to be completely up before trying to bring up the actual services, they are the pre-requisites and the underlying assumption is that the Infrastructure components are available at the application boot time.<\/p>\n<p>The Configuration server has the properties for the &#8220;sample-pong&#8221; service, this can be validated by using the Config-servers endpoint &#8211; http:\/\/localhost:8888\/sample-pong\/default, 8888 is the port where I had specified for the server endpoint, and should respond with a content along these lines:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\" brush:java\">\"name\": \"sample-pong\",\r\n  \"profiles\": [\r\n    \"default\"\r\n  ],\r\n  \"label\": \"master\",\r\n  \"propertySources\": [\r\n    {\r\n      \"name\": \"classpath:\/config\/sample-pong.yml\",\r\n      \"source\": {\r\n        \"reply.message\": \"Pong\"\r\n      }\r\n    }\r\n  ]\r\n}<\/pre>\n<p>As can be seen the <i>&#8220;reply.message&#8221;<\/i> property from this central configuration server will be used by the pong service as the acknowledgement message<\/p>\n<p>Now to set up this endpoint as a service, all that is required is a Spring-boot based entry point along these lines:<\/p>\n<pre class=\" brush:java\">@SpringBootApplication\r\n@EnableDiscoveryClient\r\npublic class PongApplication {\r\n    public static void main(String[] args) {\r\n        SpringApplication.run(PongApplication.class, args);\r\n    }\r\n}<\/pre>\n<p>and that completes the code for the &#8220;pong&#8221; service.<\/p>\n<h2>Sample-ping micro-service<\/h2>\n<p>So now onto a consumer of the &#8220;pong&#8221; micro-service, very imaginatively named the &#8220;ping&#8221; micro-service. Spring-Cloud and Netflix OSS offer a lot of options to invoke endpoints on Eureka registered services, to summarize the options that I had:<\/p>\n<ol>\n<li>Use raw Eureka DiscoveryClient to find the instances hosting a service and make calls using Spring&#8217;s <a href=\"http:\/\/docs.spring.io\/spring\/docs\/current\/javadoc-api\/org\/springframework\/web\/client\/RestTemplate.html\">RestTemplate<\/a>.<\/li>\n<li>Use <a href=\"http:\/\/projects.spring.io\/spring-cloud\/spring-cloud.html#spring-cloud-ribbon\">Ribbon<\/a>, a client side load balancing solution which can use Eureka to find service instances<\/li>\n<li>Use <a href=\"http:\/\/projects.spring.io\/spring-cloud\/spring-cloud.html#spring-cloud-feign\">Feign<\/a>, which provides a declarative way to invoke a service call. It internally uses Ribbon.<\/li>\n<\/ol>\n<p>I went with Feign. All that is required is an interface which shows the contract to invoke the service:<\/p>\n<pre class=\" brush:java\">package org.bk.consumer.feign;\r\n\r\nimport org.bk.consumer.domain.Message;\r\nimport org.bk.consumer.domain.MessageAcknowledgement;\r\nimport org.springframework.cloud.netflix.feign.FeignClient;\r\nimport org.springframework.http.MediaType;\r\nimport org.springframework.web.bind.annotation.RequestBody;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.ResponseBody;\r\n\r\n@FeignClient(\"samplepong\")\r\npublic interface PongClient {\r\n\r\n    @RequestMapping(method = RequestMethod.POST, value = \"\/message\",\r\n            produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)\r\n    @ResponseBody\r\n    MessageAcknowledgement sendMessage(@RequestBody Message message);\r\n}<\/pre>\n<p>The annotation <i>@FeignClient(&#8220;samplepong&#8221;)<\/i> internally points to a Ribbon &#8220;named&#8221; client called &#8220;samplepong&#8221;. This means that there has to be an entry in the property files for this named client, in my case I have these entries in my application.yml file:<\/p>\n<pre class=\" brush:java\">samplepong:\r\n  ribbon:\r\n    DeploymentContextBasedVipAddresses: sample-pong\r\n    NIWSServerListClassName: com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList\r\n    ReadTimeout: 5000\r\n    MaxAutoRetries: 2<\/pre>\n<p>The most important entry here is the &#8220;samplepong.ribbon.DeploymentContextBasedVipAddresses&#8221; which points to the &#8220;pong&#8221; services Eureka registration address using which the service instance will be discovered by Ribbon.<\/p>\n<p>The rest of the application is a routine Spring Boot application. I have exposed this service call behind <a href=\"http:\/\/projects.spring.io\/spring-cloud\/spring-cloud.html#_circuit_breaker_hystrix_clients\">Hystrix<\/a> which guards against service call failures and essentially wraps around this FeignClient:<\/p>\n<pre class=\" brush:java\">package org.bk.consumer.service;\r\n\r\nimport com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;\r\nimport org.bk.consumer.domain.Message;\r\nimport org.bk.consumer.domain.MessageAcknowledgement;\r\nimport org.bk.consumer.feign.PongClient;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.beans.factory.annotation.Qualifier;\r\nimport org.springframework.stereotype.Service;\r\n\r\n@Service(\"hystrixPongClient\")\r\npublic class HystrixWrappedPongClient implements PongClient {\r\n\r\n    @Autowired\r\n    @Qualifier(\"pongClient\")\r\n    private PongClient feignPongClient;\r\n\r\n    @Override\r\n    @HystrixCommand(fallbackMethod = \"fallBackCall\")\r\n    public MessageAcknowledgement sendMessage(Message message) {\r\n        return this.feignPongClient.sendMessage(message);\r\n    }\r\n\r\n    public MessageAcknowledgement fallBackCall(Message message) {\r\n        MessageAcknowledgement fallback = new MessageAcknowledgement(message.getId(), message.getPayload(), \"FAILED SERVICE CALL! - FALLING BACK\");\r\n        return fallback;\r\n    }\r\n}<\/pre>\n<h2>&#8220;Boot&#8221;ing up<\/h2>\n<p>I have dockerized my entire set-up, so the simplest way to start up the set of applications is to first build the docker images for all of the artifacts this way:<\/p>\n<pre class=\" brush:java\">mvn clean package docker:build -DskipTests<\/pre>\n<p>and bring all of them up using the following command, the assumption being that both docker and docker-compose are available locally:<\/p>\n<pre class=\" brush:java\">docker-compose up<\/pre>\n<p>Assuming everything comes up cleanly, Eureka should show all the registered services, at http:\/\/dockerhost:8761 url &#8211;<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/EurekaConsole-fullping.png\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-41378\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/EurekaConsole-fullping-1024x466.png\" alt=\"EurekaConsole-fullping\" width=\"620\" height=\"282\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/EurekaConsole-fullping-1024x466.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/EurekaConsole-fullping-300x137.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/EurekaConsole-fullping.png 1600w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/a><\/p>\n<p>The UI of the ping application should be available at http:\/\/dockerhost:8080 url &#8211;<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/SampleSpringCloudView.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-41379\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/SampleSpringCloudView.png\" alt=\"SampleSpringCloudView\" width=\"678\" height=\"458\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/SampleSpringCloudView.png 678w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/SampleSpringCloudView-300x203.png 300w\" sizes=\"(max-width: 678px) 100vw, 678px\" \/><\/a><\/p>\n<p>Additionally a Hystrix dashboard should be available to monitor the requests to the &#8220;pong&#8221; app at this url http:\/\/dockerhost:8989\/hystrix\/monitor?stream=http%3A%2F%2Fsampleping%3A8080%2Fhystrix.stream:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/SpringCloud-Hystrix.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-41380\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/SpringCloud-Hystrix.png\" alt=\"SpringCloud-Hystrix\" width=\"969\" height=\"544\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/SpringCloud-Hystrix.png 969w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/SpringCloud-Hystrix-300x168.png 300w\" sizes=\"(max-width: 969px) 100vw, 969px\" \/><\/a><\/p>\n<h2>References<\/h2>\n<ol>\n<li>The code is available at <a href=\"https:\/\/github.com\/bijukunjummen\/spring-cloud-ping-pong-sample\">my github location<\/a> &#8211; https:\/\/github.com\/bijukunjummen\/spring-cloud-ping-pong-sample<\/li>\n<li>Most of the code is heavily borrowed from <a href=\"https:\/\/github.com\/spring-cloud-samples\">the spring-cloud-samples repository<\/a> &#8211; https:\/\/github.com\/spring-cloud-samples<\/li>\n<\/ol>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/www.java-allandsundry.com\/2015\/06\/learning-spring-cloud-writing.html\">Learning Spring-Cloud &#8211; Writing a microservice<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\/\">JCG partner<\/a> Biju Kunjummen at the <a href=\"http:\/\/www.java-allandsundry.com\/\">all and sundry<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Continuing my Spring-Cloud learning journey, earlier I had covered how to write the infrastructure components of a typical Spring-Cloud and Netflix OSS based micro-services environment &#8211; in this specific instance two critical components, Eureka to register and discover services and Spring Cloud Configuration to maintain a centralized repository of configuration for a service. Here I &hellip;<\/p>\n","protected":false},"author":236,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[960,30,992],"class_list":["post-41333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-microservices","tag-spring","tag-spring-cloud"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Learning Spring-Cloud - Writing a microservice - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Continuing my Spring-Cloud learning journey, earlier I had covered how to write the infrastructure components of a typical Spring-Cloud and Netflix OSS\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learning Spring-Cloud - Writing a microservice - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Continuing my Spring-Cloud learning journey, earlier I had covered how to write the infrastructure components of a typical Spring-Cloud and Netflix OSS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-07-02T10:00:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Biju Kunjummen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Biju Kunjummen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html\"},\"author\":{\"name\":\"Biju Kunjummen\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/802eedfe6f17c3c13fa656af46b6b0e5\"},\"headline\":\"Learning Spring-Cloud &#8211; Writing a microservice\",\"datePublished\":\"2015-07-02T10:00:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html\"},\"wordCount\":760,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Microservices\",\"Spring\",\"Spring Cloud\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html\",\"name\":\"Learning Spring-Cloud - Writing a microservice - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2015-07-02T10:00:18+00:00\",\"description\":\"Continuing my Spring-Cloud learning journey, earlier I had covered how to write the infrastructure components of a typical Spring-Cloud and Netflix OSS\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2015\\\/07\\\/learning-spring-cloud-writing-a-microservice.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Learning Spring-Cloud &#8211; Writing a microservice\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/802eedfe6f17c3c13fa656af46b6b0e5\",\"name\":\"Biju Kunjummen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g\",\"caption\":\"Biju Kunjummen\"},\"sameAs\":[\"http:\\\/\\\/biju-allandsundry.blogspot.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Biju-Kunjummen\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learning Spring-Cloud - Writing a microservice - Java Code Geeks","description":"Continuing my Spring-Cloud learning journey, earlier I had covered how to write the infrastructure components of a typical Spring-Cloud and Netflix OSS","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html","og_locale":"en_US","og_type":"article","og_title":"Learning Spring-Cloud - Writing a microservice - Java Code Geeks","og_description":"Continuing my Spring-Cloud learning journey, earlier I had covered how to write the infrastructure components of a typical Spring-Cloud and Netflix OSS","og_url":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-07-02T10:00:18+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Biju Kunjummen","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Biju Kunjummen","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html"},"author":{"name":"Biju Kunjummen","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/802eedfe6f17c3c13fa656af46b6b0e5"},"headline":"Learning Spring-Cloud &#8211; Writing a microservice","datePublished":"2015-07-02T10:00:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html"},"wordCount":760,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Microservices","Spring","Spring Cloud"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html","url":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html","name":"Learning Spring-Cloud - Writing a microservice - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2015-07-02T10:00:18+00:00","description":"Continuing my Spring-Cloud learning journey, earlier I had covered how to write the infrastructure components of a typical Spring-Cloud and Netflix OSS","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2015\/07\/learning-spring-cloud-writing-a-microservice.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Learning Spring-Cloud &#8211; Writing a microservice"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/802eedfe6f17c3c13fa656af46b6b0e5","name":"Biju Kunjummen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/66af1504c76f011746c89812efce168850f07dce91ce881e62795e10c99d30b3?s=96&d=mm&r=g","caption":"Biju Kunjummen"},"sameAs":["http:\/\/biju-allandsundry.blogspot.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/Biju-Kunjummen"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/41333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/236"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=41333"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/41333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=41333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=41333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=41333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}