<?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 Thiago Humberto on Medium]]></title>
        <description><![CDATA[Stories by Thiago Humberto on Medium]]></description>
        <link>https://medium.com/@thiago.humberto?source=rss-69568761bf83------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LjLjZX4BJRJDb-YZ98kXmg.jpeg</url>
            <title>Stories by Thiago Humberto on Medium</title>
            <link>https://medium.com/@thiago.humberto?source=rss-69568761bf83------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 00:31:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thiago.humberto/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[Enterprise integration using Pub/Sub, Cloud Functions and Elasticsearch — Part 1 The proof of…]]></title>
            <link>https://faun.pub/enterprise-integration-using-pub-sub-cloud-functions-and-elasticsearch-part-1-the-proof-of-afa80d18298d?source=rss-69568761bf83------2</link>
            <guid isPermaLink="false">https://medium.com/p/afa80d18298d</guid>
            <category><![CDATA[pub-sub]]></category>
            <category><![CDATA[google-pubsub]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[google-cloud-functions]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Thiago Humberto]]></dc:creator>
            <pubDate>Mon, 11 Feb 2019 13:35:10 GMT</pubDate>
            <atom:updated>2019-07-19T15:31:58.270Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enterprise integration using Pub/Sub, Cloud Functions and Elasticsearch</h3><p>Hi, in this article I’ll show an approach for enterprise level software integration using cloud services, the proposal is to create a fully integrated system without any hand-installed piece of software, what I mean is: We are about to create everything using cloud computing, without any software installation besides our client code. This is very worth, this software trend let you save a bunch of money used into infrastructure maintenance, specially in the enterprise level applications, take a look in the diagram below, the main idea is to use a messaging system to categorize published messages into classes without knowledge of which system is subscriber, then we’ll create a subscriber to consume our topic and integrate to the search index system. Our solution is based on Google Cloud platform. Elasticsearch is the search index, it is managed outside Google Cloud, but is hosted into Google Cloud in the same region of the other solutions. This article is a proof of concept, there is no specification about the JSON document that we’re gonna use in the message traffic, you might change by Product, Customers, Dogs, Asteroids and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*mpTwKnqJkKQuGN35kvWjlA.jpeg" /><figcaption>solution big picture</figcaption></figure><h3>Used Technologies</h3><ol><li><strong>Elasticsearch</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*9cy70lEO-FkToTDjgkvi4A.png" /></figure><p>Elasticsearch provides a fully index environment, a very stable index server that over the years has proven its efficiency, it features flexible schema and fast retrieval of records, by definition: “<strong>Elasticsearch</strong> is a <a href="https://en.wikipedia.org/wiki/Search_engine_(computing)">search engine</a> based on the <a href="https://en.wikipedia.org/wiki/Lucene">Lucene</a> library. It provides a distributed, multitenant-capable <a href="https://en.wikipedia.org/wiki/Full-text_search">full-text search</a> engine with an HTTP web interface and schema-free JSON documents”. My decision was to try Elastic Cloud <a href="https://cloud.elastic.co/">https://cloud.elastic.co</a>, they provides a 14-days trial that is enough to our tests, but feel free to use any Elasticsearch installation since it is reachable on Internet.</p><p>Search Index characteristics:</p><ul><li>Support for complex search expressions</li><li>Full text search</li><li>Stemming (reducing inflected words to their stem)</li><li>Ranking and grouping of search results</li><li>Geospatial search</li><li>Distributed search for high scalability</li></ul><p>As I mentioned, this is a proof of concept, Elastisearch is used more as an intermediary or supplementary store than a primary database, in this example the records are orders, no matter what you are going to store is very important to know that It has low durability and poor security, there’s no innate authentication or access control, usually Elasticsearch is a good option to store data that needs very fast retrieves, for instance a product catalog.</p><p><strong>2. Google Cloud PubSub</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*JHox6C-cLKRwF2_t1PIG1g.png" /><figcaption>Google Cloud PubSub</figcaption></figure><p>Google Cloud Pub/Sub is an enterprise level message-oriented middleware, that provides topics and subscriptions, as a cloud service you don’t need to mess with messaging systems configurations, installations, etc. We know that messaging systems should be reliable with great performance, would be great point this responsibility to a reliable cloud service like Google Cloud. By its definition “provides many-to-many, asynchronous messaging that decouples senders and receivers, it allows for secure and highly available communication among independently written applications. Cloud Pub/Sub delivers low-latency, durable messaging that helps developers quickly integrate systems hosted on the Google Cloud Platform and externally.”</p><p><strong>3. Google Cloud Functions</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*OS7Rp2tuMqV6wqVALod8ug.png" /></figure><p>Since this guys are fully integrated why not to use Google Cloud Functions to triggered by PubSub? Google cloud functions has native integration with PubSub, and we’ll configure them to trigger our integration. Functions can be written in Node or Python a simple scalable piece of software</p><h3>Let’s Deploy Elasticsearch</h3><p>Below are the steps to create a new deployment in <a href="https://cloud.elastic.co/">https://cloud.elastic.co</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j147BfjMaLsSkqkDLR5hEw.png" /><figcaption>Deployment creation on Elastic Cloud</figcaption></figure><p>After deployed select the instance and go to security menu in order to see the credentials, these credentials are needed to configure the Elasticsearch client in the next steps. Make sure you have selected Google Cloud, because this is a Google Cloud based article, we’re going to use GC products, and of course take a look to deploy everything in the same region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aaQb7p3yyurj9s2hMSTR-w.png" /></figure><h3>Test Elasticsearch JS client</h3><p>Ok, Before continue to the Cloud Function creation why not to test our Node/Elasticsearch integration? I used to write JS code in Visual Studio Code, but feel free to pick any other code editor.</p><p>There is a lib that provides a very good client for Elasticsearch, let’s init a new proof-of-concept project. Make sure you have NodeJS installed in your system.</p><p>Clone my PoC for Elasticsearch NodeJs client lib</p><pre>git clone <a href="https://github.com/humbss/nodejs-elasticsearch-example.git">https://github.com/humbss/nodejs-elasticsearch-example.git</a></pre><p>Make sure you have configured the connection.js file, it contains the elastic search credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*MadmP8bEKJr1eZlbCXCW6w.png" /></figure><p>Creating a new index:</p><pre>nodejs create-index.js products</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*w4SwhniTK3CNULvCRLjIrg.png" /></figure><p>To add a new document to the index execute</p><pre>nodejs main.js products 1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*qmv_8gH9fIOtPYYqmjJ1_w.png" /></figure><p>Now let’s browse the index using the Elasticsearch API Console, login into cloud.elastic.co go to your deployment and open the menu item Elasticsearch / API Console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*_g4t6QGzek6QqpLIBcnPYg.png" /></figure><p>It worked, as you can see out client is ready to put elements in Elasticsearch, now we’re able to use this code snippet to implement our Google Cloud Function that will integrate the Pub/Sub to Elasticsearch.</p><h3>Configuring the messaging system (Pub/Sub)</h3><p>Let’s create a Pub/Sub topic, I suppose that you have a Google Cloud account for tests, since Google provides some initial budget for it. Go to the side menu and scroll down to Big Data / PubSub as the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*rZkPSOX45xpSLjgDZGDfGg.png" /></figure><p>It will ask for a project and to enable the service go ahead and then create a new topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*vt9xzCyYSlvDUq40GUdxzQ.png" /></figure><p>Caution: Publish–subscribe is a software design pattern, is very important to understand what it does and why to use it instead of a simple network socket client-server, this is very required before configure the broker or decide to use this kinda software. <a href="https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">Click here</a> for more concept information.</p><h3>Setup a Pub/Sub Service Account and Publish!</h3><p>We are about to publish our first message thru a NodeJs simple program, this step is optional remember that you could add messages directly through the Pub/Sub console in the Topic menu. To use Pub/Sub outside the Cloud Console we need to setup a Service Account, this procedure is very simple, go to the APIs &amp; Services menu and select credentials page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zh4ym0xlGcSwLAc96QtLmg.png" /></figure><p>Click on “Create credentials” and select “Service account key”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cILpN0AsgCSqIJ7_iCJDew.png" /></figure><p>In the service account configuration page select the Pub/Sub Subscriber role, this is because we’re going to use this account key to publish messages to our Pub/Sub topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v58TW6qMCv8doEXyi8BKlQ.png" /></figure><p>Click on create and download the key txt file. Is very important to create an env variable that points to the key file, example:</p><pre>export GOOGLE_APPLICATION_CREDENTIALS=~/Downloads/file.txt</pre><p>Another option is create an .env file in your NodeJs project and add this env variable to this.</p><p><strong>The client example is here:</strong> <a href="https://github.com/humbss/nodejs-pubsub-example">https://github.com/humbss/nodejs-pubsub-example</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*5bJoQDG0IBd0xotNTHTd_w.png" /></figure><p>Let’s try it, here we go</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tmx68aWGiMkI3yIB7LMZhg.png" /></figure><p>As you can see, we are able to publish to topic, some messages has been added to our “products” topic.</p><h3>Creating a Google Cloud Function to consume messages</h3><p>Since Google Cloud Functions are fully integrated to Pub/Sub, let’s create one to simple print our arrived message to console. Go to Google Cloud Function and click “Create Function”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*LvRLSDDkHuOIqwyJ_HDT1g.png" /></figure><p>In the function setup session you should configure it’s name, memory allocated, and the most important part is the trigger, in our case we NEED to select Cloud Pub/Sub, and the topic that we made previously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*g5O_wvts58PnXAXfmNauXA.png" /></figure><p>The default function body will print messages arrived in our Product topic.</p><pre>/**<br> * Triggered from a message on a Cloud Pub/Sub topic.<br> *<br> * <a href="http://twitter.com/param">@param</a> {!Object} event Event payload and metadata.<br> * <a href="http://twitter.com/param">@param</a> {!Function} callback Callback function to signal completion.<br> */<br>exports.helloPubSub = (event, callback) =&gt; {<br>  const pubsubMessage = event.data;<br>  console.log(Buffer.from(pubsubMessage.data, &#39;base64&#39;).toString());<br>  callback();<br>};</pre><p>If you public more messages using the NodeJs client and go to the function log, go to the function log and you’ll see the function been triggered</p><p>Great! We have the Pub/Sub topic, the NodeJs publisher and the Google Function consumer</p><p>First, we need to configure the Cloud Function package.json</p><pre>{<br>  &quot;name&quot;: &quot;sample-pubsub&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;request&quot;: &quot;^2.81.0&quot;,<br>    &quot;elasticsearch&quot;:&quot;15.2.0&quot;,<br>    &quot;microtime&quot;:&quot;3.0.0&quot;<br>  }<br>}</pre><p>below is the function body, remember that it is a proof of concept, a minimal function.</p><pre>var elasticsearch = require(&#39;elasticsearch&#39;);<br>var microtime = require(&#39;microtime&#39;)</pre><pre>var client = new elasticsearch.Client({</pre><pre>hosts: [</pre><pre>&#39;https://elastic:PASSWORD@your_host.us-central1.gcp.cloud.es.io:9243&#39;</pre><pre>]</pre><pre>});</pre><pre>exports.helloPubSub = (event, callback) =&gt; {</pre><pre>const pubsubMessage = event.data;</pre><pre>var persistOrder = (orderObj) =&gt; {</pre><pre> client.index({</pre><pre> index: &#39;products&#39;,</pre><pre> id: microtime.now(),</pre><pre> type: &#39;product_detail&#39;,</pre><pre> body: messageObj</pre><pre>}, function (err, resp, status) {</pre><pre>if(status &lt; 200 || status &gt; 299) {</pre><pre>   console.error(status);</pre><pre>   callback(new Error(&#39;error processing obj id:&#39;+messageObj.id));</pre><pre>} else {</pre><pre>   callback();</pre><pre>}</pre><pre>});</pre><pre>}</pre><pre>var messageObj = JSON.parse(Buffer.from(pubsubMessage.data, &#39;base64&#39;).toString());</pre><pre>persistOrder(messageObj);</pre><pre>};</pre><p>After insert in Pub/Sub the function will be triggered and it inserts into Elastic Search. You can check the results in Elastic Search API console as showed below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*FSrIk3a62l1u9rTGlsvD_w.png" /></figure><h3>Stress Loading</h3><p>Before start the stress loading let’s see the Elastic Cloud cluster config, currently using the trial I have the following cluster:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0mLsc8ZQQqE4Y-z5xLcGQ.png" /></figure><p>The cloud function is configured with the minimal size 128mb.</p><p>Important note:</p><p>“Cloud Functions can start multiple function instances to scale your function up to meet the current load. <strong>These instances run in parallel, which results in having more than one parallel function execution</strong>.</p><p>However, each function instance handles only one concurrent request at a time. This means while your code is processing one request, there is no possibility of a second request being routed to the same function instance, and the original request can use the full amount of resources (CPU and memory) that you requested.</p><p>Because concurrent requests are processed by different function instances, they do not share variables or local memory. This is discussed in detail later in this document.” source: <a href="https://cloud.google.com/functions/docs/concepts/exec">https://cloud.google.com/functions/docs/concepts/exec</a></p><p>I didn’t find any property to enable, disable or even configure the concurrency, so we assume the function will run in parallel with the available power.</p><p>Index: Products<br>No. of entries: 1k</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EqPn3Fz7Sdr9L7LnKnfexQ.png" /></figure><p>Results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*LkZcSxdSMVjhtiyjeYEgZA.png" /></figure><p>Index: Products<br>No. of entries: 2k</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*s1UBcAvCetSPeQaze64dSQ.png" /></figure><p>Index: Products<br>No. of entries: 10k</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*Osx8UylAEnJL7L-FJXP7Nw.png" /></figure><p>3 items are gone, not sure if Elastic Search problem, once our function is configured to reattempt failures, according to the logs every failure messages were reprocessed, the function considers failure every status messages &lt; 200 and &gt; 299.</p><p>that’s it, I hope this Article/PoC helps you with a new serverless paradigm, with this approach for fast integration and indexing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook Group</strong></a><strong> </strong>💬<strong>.</strong></p><p><strong>To join our community Slack </strong>🗣️ <strong>and read our weekly Faun topics </strong>🗞️,<strong> click here⬇</strong></p><figure><a href="https://www.faun.dev/join/?utm_source=medium.com%2Ffaun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSdFkACJxs5iy1oR" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afa80d18298d" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/enterprise-integration-using-pub-sub-cloud-functions-and-elasticsearch-part-1-the-proof-of-afa80d18298d">Enterprise integration using Pub/Sub, Cloud Functions and Elasticsearch — Part 1 The proof of…</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>