{"id":6110,"date":"2018-03-31T20:52:59","date_gmt":"2018-03-31T20:52:59","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=6110"},"modified":"2018-03-31T20:56:22","modified_gmt":"2018-03-31T20:56:22","slug":"service-discovery-using-zookeeper-with-vert-x","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/service-discovery-using-zookeeper-with-vert-x\/","title":{"rendered":"Service Discovery using ZooKeeper with Vert.x"},"content":{"rendered":"<p>Following on from my post <a href=\"http:\/\/putridparrot.com\/blog\/service-discovery-with-vert-x\/\" rel=\"noopener\" target=\"_blank\">Service discovery with Vert.x<\/a>, let&#8217;s switch from using the Vert.x built-in Service Discovery to using ZooKeeper.<\/p>\n<p>You can fire up a docker container running ZooKeeper using<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\ndocker run --name zookeeper --restart always -d zookeeper\r\n<\/pre>\n<p>Now we&#8217;ll need to add the following to our pom.xml<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;dependency&gt;\r\n   &lt;groupId&gt;io.vertx&lt;\/groupId&gt;\r\n   &lt;artifactId&gt;vertx-service-discovery-bridge-zookeeper&lt;\/artifactId&gt;\r\n   &lt;version&gt;${vertx.version}&lt;\/version&gt;\r\n&lt;\/dependency&gt;\r\n<\/pre>\n<p><em>Note: vertx.version is set to 3.5.1<\/em><\/p>\n<p>The code to create the Service Discovery to ZooKeeper is, as follows<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nServiceDiscovery discovery = ServiceDiscovery.create(vertx)\r\n   .registerServiceImporter(new ZookeeperServiceImporter(),\r\n      new JsonObject()\r\n        .put(&quot;connection&quot;, &quot;172.17.0.2:2181&quot;)\r\n        .put(&quot;basePath&quot;, &quot;\/services\/hello-service&quot;));\r\n<\/pre>\n<p><em>Replace the ip address with the one create by Docker or if you&#8217;re running on localhost.<\/em><\/p>\n<p>We register the ZooKeeperServiceImporter and supply at least the &#8220;connection&#8221;, the &#8220;basePath&#8221; is not required, a default will be supplied if none is explicitly supplied.<\/p>\n<p>Don&#8217;t forget you&#8217;ll need the import<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport io.vertx.servicediscovery.zookeeper.ZookeeperServiceImporter;\r\n<\/pre>\n<p><strong>References<\/strong><\/p>\n<p><a href=\"https:\/\/hub.docker.com\/_\/zookeeper\/\" rel=\"noopener\" target=\"_blank\">Docker ZooKeeper<\/a><br \/>\n<a href=\"https:\/\/vertx.io\/docs\/vertx-service-discovery\/java\/#_service_discovery_bridges\" rel=\"noopener\" target=\"_blank\">Vert.x Service Discovery<\/a><\/p>\n<p><strong>Code<\/strong><\/p>\n<p>Source code relating to these posts on Vert.x can be found at <a href=\"https:\/\/github.com\/putridparrot\/blog-projects\/tree\/master\/VertxSamples\" rel=\"noopener\" target=\"_blank\">VertxSamples<\/a>. The code differs from the posts in that in some cases it&#8217;s been refactored to reduce some code duplication etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following on from my post Service discovery with Vert.x, let&#8217;s switch from using the Vert.x built-in Service Discovery to using ZooKeeper. You can fire up a docker container running ZooKeeper using docker run &#8211;name zookeeper &#8211;restart always -d zookeeper Now we&#8217;ll need to add the following to our pom.xml &lt;dependency&gt; &lt;groupId&gt;io.vertx&lt;\/groupId&gt; &lt;artifactId&gt;vertx-service-discovery-bridge-zookeeper&lt;\/artifactId&gt; &lt;version&gt;${vertx.version}&lt;\/version&gt; &lt;\/dependency&gt; Note: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[161,210],"tags":[],"class_list":["post-6110","post","type-post","status-publish","format-standard","hentry","category-java","category-vert-x"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=6110"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6110\/revisions"}],"predecessor-version":[{"id":6115,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6110\/revisions\/6115"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=6110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=6110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=6110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}