<?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 Omer Kalim Ansari on Medium]]></title>
        <description><![CDATA[Stories by Omer Kalim Ansari on Medium]]></description>
        <link>https://medium.com/@ok_ansari?source=rss-bb020ae5c9a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*S0Ox4oROcQZ6uZR8dkDeMg.jpeg</url>
            <title>Stories by Omer Kalim Ansari on Medium</title>
            <link>https://medium.com/@ok_ansari?source=rss-bb020ae5c9a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 01:07:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ok_ansari/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[How to develop, consume, and publish an Angular library to NPM]]></title>
            <link>https://medium.com/free-code-camp/how-to-develop-consume-and-publish-an-angular-library-to-npm-2ed608a03c6c?source=rss-bb020ae5c9a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ed608a03c6c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Omer Kalim Ansari]]></dc:creator>
            <pubDate>Wed, 20 Mar 2019 17:24:00 GMT</pubDate>
            <atom:updated>2021-04-08T08:37:58.490Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to develop, consume, and publish an Angular library to NPM… but sometimes its not Worth it!</h3><p>Angular is a really popular and powerful JavaScript Framework on which one can built Web Apps to serve millions of daily users. It’s an open source framework by Google and anyone can collaborate. Likewise, there are thousands of packages for Angular available as plug-and-play on <a href="https://www.npmjs.com/">NPM</a>. Here in this article we’re gonna make one too 😇.</p><p>We will start this article as a tutorial to develop an <strong>Angular Component Library</strong>, consume it within an Angular CLI project, and then we’ll <strong>publish it to the NPM.</strong> This will be a step-by-step guide.</p><p>Then, we will convert that same Angular Library to <strong>Angular Pipe </strong>and we will go in more detail as to <strong>when to “use Pipes over Modules”</strong> and how pipes can reduce the load over the application. Wanna target only this part? Navigate three quarters of the way down in the article.</p><p>Pipes are much lighter, when compared to a third-party libraries as the cost of JavaScript is way too high on the client side when handled inefficiently. <a href="https://medium.com/u/2508e4c7a8ec">Addy Osmani</a> explains this in his <a href="https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4">latest article</a>.</p><p>This article will target two major domains: <strong>Angular Component </strong>and <strong>Angular Pipes (</strong>and when they are worth using<strong>)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xTxWlyL5uxdvCEisURZelw.png" /></figure><h3>Angular Component Library</h3><p>We will create a small component library that will format large numbers into human readable format. For example: current metrics shows that Twitter has <strong>“55138719 Followers”</strong> and our library will format it as <strong>“55.1M Followers”. </strong>Isn’t this more intuitive and user-friendly? 😉 Some more examples:</p><ul><li><strong>37574 -&gt; 37.5K</strong></li><li><strong>1222130 -&gt; 1.2M</strong></li><li><strong>12414770 -&gt; 12.4M</strong></li><li><strong>19121364128 -&gt; 19.1B</strong></li></ul><h4>Setting up the Project</h4><p>We will be using Angular CLI as a base to our development as it’s more convenient than cloning the Angular Repo from Github. Plus we will be benefiting from the scaffolding and auto generation of modules, components and pipes. *Later, we will use this same project for the development of our component and pipes and will also use it as a Sandbox to test our Library.</p><p>Let’s start by installing the CLI globally and then initiating the Project.</p><pre>npm install @angular/cli -g</pre><pre>ng new ng-number-formatter</pre><p>Now that we have a basic structure of the project, we can navigate to the project folder “ng-number-formatter” and serve the Project.</p><pre>ng serve // Navigating to `localhost:4200`</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*qZCNkP8n72L1zi-7NAdPBw.png" /></figure><h4>Initiating the Modules/Components for the Library</h4><p>Now that our most simple Angular App is up and running, let’s add our custom modules and components to format numbers in a human readable format.</p><pre>ng generate module modules/ng-number-formatter</pre><pre>ng generate component modules/ng-number-formatter</pre><p>This auto-generation will create the mandatory files for the development of Angular Modules. In our case, these independent modules are meant to be isolated from each other so that we can export them as stand-alone Angular Libraries. It’s also good practice to make each module decoupled from every other just like the concept of MicroServices.</p><p>Modules in Angular can be considered as configuration files that will help reference our components to be a part of an Angular Project. These Modules are based on Components which actually makes our application productive and gets it up and running.</p><h4>Number Formatter Module</h4><p>This Module file is self expressive and in it we can see the declarations and exports of our library.</p><pre>@NgModule({<br>    imports: [<br>        CommonModule<br>    ],<br>    declarations: [<br>        NgNumberFormatterComponent<br>    ],<br>    exports: [<br>        NgNumberFormatterComponent<br>    ]<br>})</pre><h4>Number Formatter Template</h4><p>Now open the ng-number-formatter.component.html file within the app/modules/ng-number-formatter folder and add the required Html span Tag. For the sake of styling, we can manipulate the content of the ng-number-formatter.component.css file, but for now we will ignore that and let things stay as simple as possible.</p><pre>&lt;span&gt;{{ngNumber}}&lt;/span&gt;</pre><p>Here, the variable ngNumber is defined within the associated ng-number-formatter.component.ts component. As we will be getting the number in a string format from some parent component (in our case that would be app.component.ts — we will show how these components are linked), we will format that number in into human readable format with our ng-number-formatter.component.ts. Then we will display it via the Html template to which we just added a Span Tag.</p><h4>Number Formatter Component</h4><p>Open the ng-number-formatter.component.ts file within the same app/modules/ng-number-formatter folder. You can see that there’s already basic code present for the Component. The template which we just modified is already linked in our component.</p><pre>@Component({<br>    selector: &#39;ng-number-formatter&#39;,<br>    inputs: [&#39;ngNumber&#39;],<br>    templateUrl: &#39;./ng-number-formatter.component.html&#39;,<br>    styleUrls: [&#39;./ng-number-formatter.component.css&#39;]<br>})</pre><p>Here, selector: &#39;ng-number-formatter&#39; is a custom tag which we, as the consumer of our library, will be needing to reference our Component. Then inputs: [&#39;ngNumber&#39;] is with the two contexts.</p><p>In our “ng-number-formatter component” <strong>(the callee)</strong> it’s treated as a variable that will accept the incoming number string. On the other hand in the “app.component.ts” <strong>(the caller), </strong>it will be treated as a property to our selector which will send the value.</p><p>Then templateUrl: &#39;.ng-number-formatter.component.html&#39; and styleUrls: &#39;.ng-number-formatter.component.css&#39; are the ones linking the template.</p><p>Update the file with the required logic for the number conversion. Next our template doesn’t need to be in a separate file. So we can remove that and directly embed it to our component as template: &#39;&lt;span&gt;{{ngNumber}}&lt;/span&gt;&#39;. The following Gist shows the complete contents of our component. Compare the changes which you made and then we will proceed to the next steps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff219707b1454ae13fc1d4f7c4d745dc/href">https://medium.com/media/ff219707b1454ae13fc1d4f7c4d745dc/href</a></iframe><h3>Consuming the Angular Component Library</h3><p>To consume any Angular Library, first you need to get referenced within the Module and then the usage of its selector ng-number-formatter (as mentioned in our component’s selector tab) in the template.</p><p>There’s only one difference when consuming a third party library in a project and when used as a sandbox.</p><p>1. Since our library is not yet published and listed in the NPM Directory, we need its full path to reference within the Module.</p><pre>import { NgNumberFormatterModule } from &#39;./modules/ng-number-formatter/ng-number-formatter.module&#39;;</pre><p>2. And when our library gets published and listed in the NPM Directory, it will be with a much simpler reference link. Like this:</p><pre>import { NgNumberFormatterModule } from &#39;ng-number-formatter&#39;;</pre><p>And here’s our custom Tag to consume our brand new library:</p><pre>&lt;ng-number-formatter [ngNumber]=&quot;12414770&quot;&gt;&lt;/ng-number-formatter&gt;</pre><pre>// Resulting number into the Format much more convenient &quot;1.2M&quot;</pre><h3>Packaging and Publishing it to the NPM</h3><p>Now that we have our independent Module developed and tested within the Sandbox project, we are good to go. First of all, the good part is that this Module is so simple and minimal in nature that it doesn’t have any other dependencies. Second, it’s good that our module is totally isolated and is easily plugged to the our component in the sandbox which makes it ready to be separately packaged and published.</p><p>The next step is to make it open to the world so others can download and use it to format numbers in their Angular Applications.</p><p>To get started with the packaging and publishing of our Number Formatting Module, we need a Packager that will transform this Module into a Library identifiable as an NPM Package. For that we choose “<a href="https://www.npmjs.com/package/ng-packagr"><strong>ng-packagr</strong></a><strong>” </strong>which Transpiles your libraries to Angular Package Format.<strong> </strong>It is an NPM Package built as a wrapper over “<a href="https://www.npmjs.com/package/rollup"><strong>Roll-Up</strong></a><strong>” </strong>which is a module bundler that compiles code into Libraries and Applications.</p><p>Now let’s continue with our development process by installing our packager within the context of our Sandbox Project. We will be saving it as a dev-dependency as we only need to compile our module as a Library identifiable to <a href="https://www.npmjs.com/">NPMjs.com</a>.</p><pre>npm install ng-packagr --save-dev</pre><p>The next step is to add two files manually in our project directory, namely ng-package.json and public_api.ts.</p><p>ng-package.json is to configure ng-packgr and point out the public_api.ts file to get ready for the packaging. Here’s the content:</p><pre>{<br>  &quot;$schema&quot;: &quot;./node_modules/ng-packagr/ng-package.schema.json&quot;,<br>  &quot;lib&quot;: {<br>    &quot;entryFile&quot;: &quot;public_api.ts&quot;<br>  }<br>}</pre><p>public_api.ts is the file that will be composed of one single line exporting the recently developed Angular Module.</p><pre>export * from &#39;./src/app/modules/ng-number-formatter/ng-number-formatter.module&#39;</pre><p>Once the two files are created, we will register the ng-packagr command in the package.json file of our Application Project and will also toggle the property &quot;private&quot;: false for the NPM Directory. Go ahead and update your files so that we can continue for the publication.</p><pre>&quot;scripts&quot;: {<br>  &quot;ng&quot;: &quot;ng&quot;,<br>  &quot;start&quot;: &quot;ng serve&quot;,<br>  &quot;build&quot;: &quot;ng build&quot;,<br>  &quot;test&quot;: &quot;ng test&quot;,<br>  &quot;lint&quot;: &quot;ng lint&quot;,<br>  &quot;e2e&quot;: &quot;ng e2e&quot;,<br>  &quot;packagr&quot;: &quot;ng-packagr -p ng-package.json&quot;<br>},<br>&quot;private&quot;: false</pre><p>Now that ng-packagr is registered as a command, we can continue packing our module as a package recognizable for NPM Directory. This compiles our TypeScript-based Module into executable JavaScript in the dist folder. Next we navigate to the dist folder and run the final packaging as a standalone component library.</p><pre>npm run packagr</pre><pre>cd dist</pre><pre>npm pack</pre><p>That’s all on your local machine — now is the time to make it public. For that we need an account on <a href="https://www.npmjs.com/">https://www.npmjs.com/</a>. Go ahead and signup and then we will run the last two commands for our Library to be publicly available 🏆.</p><p>Login to NPM via Terminal / Command Line Tool:</p><pre>npm login</pre><p>Publish to NPM:</p><pre>npm publish</pre><p>Voillllàaaaaaaaaaaaaaaaaaaaaaaaa!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBJcjunNHVVV_SDi-xSspQ.png" /></figure><p><a href="https://www.npmjs.com/package/ng-number-formatter">ng-number-formatter</a></p><p>Your package is up and available just like this one of mine. :)</p><h3>How others will consume your Library within their Project</h3><p>This will happen the same way as in our app.component.ts file of our Sandbox Project, but in fact it’s a bit simpler. We only need the simplest module referencing directly with the name. The following three steps need to be executed one after another: <strong>Installation</strong>, <strong>Importing the Module</strong>, using the <strong>Selector</strong>.</p><pre><strong>// Installation<br></strong>npm install ng<strong>-</strong>number<strong>-</strong>formatter <strong>--</strong>save</pre><pre><strong>// Importing the Module<br></strong>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { NgModule } from &#39;@angular/core&#39;;</pre><pre>import { AppComponent } from &#39;./app.component&#39;;<br>import { NgNumberFormatterModule } from &#39;ng-number-formatter&#39;;</pre><pre>@NgModule({<br>    declarations: [<br>        AppComponent<br>    ],<br>    imports: [<br>        BrowserModule,<br>        NgNumberFormatterModule<br>    ],<br>    providers: [],<br>    bootstrap: [AppComponent]<br>})</pre><pre>export class AppModule { }</pre><pre><strong>// Selector<br></strong>&lt;ng-number-formatter [ngNumber]=&quot;1222130&quot;&gt;&lt;/ng-number-formatter&gt;</pre><p>For more, find the <a href="https://www.npmjs.com/package/ng-number-formatter"><strong>“ng-number-formatter”</strong></a><strong> </strong>Package in the NPM Directory!</p><p><a href="https://www.npmjs.com/package/ng-number-formatter">ng-number-formatter</a></p><p>And the code with in the <a href="https://github.com/DynamicRemo/ng-number-formatter"><strong>“Sandbox Project”</strong></a> on Github!</p><p><a href="https://github.com/DynamicRemo/ng-number-formatter">DynamicRemo/ng-number-formatter</a></p><h3>Angular Pipes, and when to use them as an alternative</h3><p>Now that we’ve got all that done, let’s move on to the second part of the article. First we’ll consider the need for Pipes in Angular Applications, and then we will convert the <strong>NG Number Formatter Library </strong>into a <strong>Number Formatter Pipe</strong>.</p><h3>The | symbol near the Enter Key on the Keyboard</h3><p>What is a pipe? Pipe is a simple representation <strong>“ | ”</strong> within the template of any Module in the Angular Application. Pipes are usually dedicated to perform simple tasks: the most common of them all is the formatting of timestamps or Unix version <strong>Date</strong> into human readable <strong>Date </strong>as <strong>Day/Month/Year</strong> format. Such as the following:</p><blockquote>1533679976 into 08/07/2018<br>1533679976 into Tue, 07 Aug 2018</blockquote><p>The way this is done is inside the HTML Tag. For example:</p><pre>&lt;span&gt; {{ 1533679976 | date }} &lt;/span&gt;</pre><p>The separator <strong>“ | ” </strong>will force Angular to interpret the inner html of the Span Tag before rendering it to the screen.</p><p>Pipes are preferred over Modules in certain scenarios because of the cost of JavaScript. This cost is in regards to <strong>memory size, download time, latency, time to render elements </strong>and <strong>time taken before the interactivity of the page starts. </strong>These are just a few things to be considered when you have a JavaScript intensive Web Application / Website.</p><p>Third-Party Libraries can be heavy, loaded with dozens of other dependencies (like libraries based on other libraries) which can pull your application down. This can affect your Google search rankings as well, as time taken to page-load is still one of the major metrics for calculating your Search Index on Google Search.</p><p>In the context of the <a href="https://www.npmjs.com/package/ng-number-formatter"><strong>Ng-Number-Formatter Library</strong></a><strong>, </strong>the library is already compressed and is in its minimal form available without any external dependencies. Therefore, if you have an alternative <strong>Pipe </strong>for this, it would also be almost of the same size on the disk. You can go to your Project folder in which you have consumed npm install ng-number-formatter --save and check that the total size of the library with in the node_modules folder is around 70 KB including the sandbox testing environment.</p><p>Before starting the actual tutorial for the <strong>Angular Number Formatter Pipe, </strong>I would like to note that you should know your dependencies well, before choosing any third party add-on or plug-in. Then, when integrating them into your project, you can plan accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G5gvSkpJQP11kgx8DeGvnw.png" /><figcaption>NPM Package with lots of dependent Packages is kind of a burden. <a href="https://www.monkeyuser.com/2017/npm-delivery/">Image</a></figcaption></figure><h4>Angular Number Formatter Pipe</h4><p>As of now, we all know the flow of an Angular Application. Thus, this last part is just a skim over the topic as a <strong>Cheat Sheet</strong> with the Terminal Commands and minimum required Code for the <strong>Angular-Number-Formatter-Pipe</strong>!</p><p>We’ll get started with the scaffolding command for the generation of <strong>Pipes, </strong>then we will register and import our newly generated Pipe to the Parent Component. Finally, we’ll use it in our Template. <br><strong>*as of here… implementation is expressive enough. Cheers!</strong></p><pre>// Generating Pipe<br>ng generate pipe pipes/angular-number-formatter</pre><pre>// Importing into Module<br>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { NgModule } from &#39;@angular/core&#39;;<br>import { AppComponent } from &#39;./app.component&#39;;<br>import { AngularNumberFormatterPipe } from &#39;./pipes/angular-number-formatter.pipe&#39;;<br>@NgModule({<br>    declarations: [<br>        AppComponent,<br>        AngularNumberFormatterPipe<br>    ],<br>    imports: [<br>        BrowserModule<br>    ],<br>    providers: [],<br>    bootstrap: [AppComponent]<br>})<br>export class AppModule { }</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6220d62a6ed50b8849662004004cd276/href">https://medium.com/media/6220d62a6ed50b8849662004004cd276/href</a></iframe><p>and finally using the Number Formatter Pipe in the Template:</p><pre>&lt;span&gt; {{ 1533679976 | angularNumberFormatter }} &lt;/span&gt;</pre><p>That’s all for this article! I hope this helps and lets you publish dozens of Libraries and tons of pipes for the community.</p><blockquote>Wanna know about the combination of <strong>Internet of Things </strong>and <strong>Industry 4.0</strong>? Here’s an excerpt of my Master Thesis <a href="https://medium.com/coinmonks/micro-services-pipeline-for-an-industrial-internet-of-things-a8cdd67f1eb9">https://medium.com/coinmonks/micro-services-pipeline-for-an-industrial-internet-of-things-a8cdd67f1eb9</a>. <br><em>It’s an implementation of Micro-Services Pipeline based on </em><strong><em>Apache Kafka’s Message Queuing</em></strong><em>, </em><strong><em>Apache Spark’s Streaming Engine</em></strong><em> and </em><strong><em>MongoDB’s Data Lake</em></strong><em>. Give it a read!</em></blockquote><blockquote>You can find/follow me <a href="https://twitter.com/intent/follow?screen_name=ok_ansari">@ok_ansari</a>. Cheers, <a href="https://medium.com/u/bb020ae5c9a8">Omer Kalim Ansari</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ed608a03c6c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-develop-consume-and-publish-an-angular-library-to-npm-2ed608a03c6c">How to develop, consume, and publish an Angular library to NPM</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Micro Services pipeline for an Industrial Internet of Things (IIOT) Framework… towards Data…]]></title>
            <link>https://medium.com/coinmonks/micro-services-pipeline-for-an-industrial-internet-of-things-a8cdd67f1eb9?source=rss-bb020ae5c9a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8cdd67f1eb9</guid>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Omer Kalim Ansari]]></dc:creator>
            <pubDate>Sun, 15 Jul 2018 13:29:46 GMT</pubDate>
            <atom:updated>2020-10-28T17:13:58.614Z</atom:updated>
            <content:encoded><![CDATA[<h3>Micro Services pipeline for an Industrial Internet of Things (IIOT) Framework… towards Data Engineering</h3><p>This is my first ever post on Medium to share an excerpt from my Master Thesis; how Micro-Services Architecture helped me in developing a Framework for <strong>Industrial Internet of Things</strong> in a time frame of 6 months.</p><p>Its also with an intent to write for the students who aspire for their Thesis (or final year project), for the new developers eager to learn the flow of how multiple small applications can play a bigger part in the enterprise level application and for all my experienced/skilled audience who would give feedback on how I could have achieve brilliance in my Thesis Implementation. This Thesis is a part of my Masters Degree at <strong>RWTH Aachen University, Germany</strong> 🇩🇪.</p><blockquote>“The idea was to leverage the technology followed in the Internet of Things and overlap them with the 4th generation industrial revolution that is Industry 4.0.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*UeptKy7XPFtY5ASjU72FzA.jpeg" /><figcaption><a href="https://www.amec.com.vn/du-hoc-duc-voi-10-truong-dai-hoc-hang-dau-dao-tao-nganh-y.html">SuperC Building, RWTH Aachen University</a></figcaption></figure><p>By now almost everyone have heard the word Micro-Services; small application/service dedicated to perform some particular task independent of any others software or service. Its not something too complicated for a newbie but just a concept of loosely coupled (almost no dependency) software services combined together resulting in a one complete Application.</p><blockquote>Micro-Services Architecture (sometimes also referred as Service Oriented Architecture) is a set of services summing up to a complex application. It’s with a concept that if any part of the Application goes down, it should not effect other features and functionality around it. Sounds reliable and robust, right?</blockquote><p>Although there’s no formal definition of Micro Services Architecture (MSA) but there are certain characteristics which identifies this claim. <strong>Martin Fowler</strong> describes <strong>Micro-Services as; Software Applications with scalability, business capability, automated deployment, intelligence in the endpoints and decentralized control of languages and data</strong>.</p><blockquote><strong>*alternative</strong> of Micro Services Architecture were <strong>Monolithic Application</strong>, built on single programming stack and each component highly dependent on one another.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*S1kWdAuHYbxc7sUW7k-0hA.png" /><figcaption><a href="https://martinfowler.com/articles/microservices.html">Monoliths and Microservices</a></figcaption></figure><p>Combining all: Software applications which are independently deploy-able, modular in nature, running a unique process with a well-defined scope, possess lightweight mechanism to serve a business goal and are loosely coupled with high cohesion ends up being a part of Micro Services Architecture. Such architectures are best to handle different programming stack and to make them work together as per the implementation pipeline.</p><p>That’s what I did… making a pipeline of several small applications as a building block to my Master Thesis implementation. These implementation of applications were based on <strong>Apache Kafka </strong>(used for messaging system)<strong>, Apache Spark </strong>(for real-time data streaming and processing)<strong>, MEAN Stack </strong>(Node.js, Angular for data ingestion and visualization)<strong>, Python for RaspberryPi </strong>(along with sensors programming), <strong>MySQL</strong> (sample data), <strong>JAVA Spring </strong>(for map-matching)<strong> </strong>and <strong>MongoDB as a Data Lake</strong>. Thus, with the total time frame of 6 months in mind it was suitable for me to choose Micro-Services Architecture. In this way I was able to get my hands-on to these technologies for the implementation and saved the time for writing the detailed report as per the requirement of Master Thesis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*hSu4Wsitt8afciNdnzvzNg.png" /><figcaption>Technology (Implementation) Pipeline</figcaption></figure><blockquote>“Master Thesis are usually with a duration of 6 months. In those 6 months every student have to develop a POC / MVP (prove of concept / minimum viable product) along with the research paper/work to defend in front of the University Professors (Supervisors). In that way it can be a part of some research project or it may become the base of some industrial project.”</blockquote><blockquote><strong>Now limiting the scope </strong>to the break down of master thesis implementation that includes different technology stacks and how did I end up leveraging them with Micro Services Architecture in the time span of 6 months?</blockquote><p>At the time of my Thesis Proposal, there were two main concerns raised by University Supervisors. First was concerned with the variety of involved technologies and second concern was the feasibility of implementation with in a time frame of 6 months. The answer to the second concern is already cleared in the prior para and regarding the first concern, yes the variety was meant to be for the sake of implementation. As the goal was to develop “<strong>An Extensible Framework for Sensor Data with the context of Industrial Internet of Things</strong>”. Thus, I needed a variety of Sensor to make them work as per my pipeline with Node and Python, similarly to handle such variety of incoming data from sensors I needed the messaging system which should be fast and robust enough to handle multiple streams at any point of time so I chose Kafka. Likewise the incoming data was to be processed on the go with Spark’s Streaming Engine and then the data is dumped in a document based database which was MongoDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3nFTn4krTR-nHLuvIbnM4w.png" /><figcaption>Master Thesis Phase (Flow) Diagram</figcaption></figure><p>So when you have this variety of technology you can’t rely on a Monolithic Architecture (monolithic applications are built as a single autonomous unit, where change in one component effects the application as a whole). Hence, micro services architecture (MSA) to the rescue! MSA is with a concept that if any part of the Application goes down, it should not effect other features and functionality around it. I molded it a bit and made a pipeline of such micro applications (services) for my Master Thesis implementation.</p><h3>Context of Industrial Internet of Things</h3><p>The idea was to leverage the technology followed in the <strong>Internet of Things</strong> and overlap that with the 4th generation industrial revolution that is <strong>Industry 4.0</strong>. We all are aware of the idea behind Internet of Things (IOT), that each and every electronic devices are connected to each other in a meaningful way to make our lives easier; providing convenience in our day to day life. Similarly, Industry 4.0 is with an idea of automation. To make the factories totally based on robot; that is less human involvement will lead to less human-error and less things to worry for. Simple example would be the manufacturing industry, you supply the raw material and you get the finished product with limited or no human involvement. Hence, the future factories.</p><h4>Future Cities and now Future Factories</h4><p>The concept was to develop such a framework that is flexible enough to adapt as per the nature of incoming data. In the context of industrial internet of things, these incoming stream of data are mostly from the Machine Sensor and Industrial Robot. These data then processed and utilize with my framework on the go. Resulting in meaningful data which could become input of later forwarding machinery in the pipeline of that particular industry.</p><blockquote>In the actual implementation, this data which got ingested to the data lake is actually an input to the next component of the Industry Pipeline.</blockquote><p><strong>Framework handles the incoming stream of data from several different sources, analyze it on the go and ingest the meaningful information to the data lake. </strong>Where, the incoming data are from the multiple giant sized industrial robots working on different communication protocols generating data in different data types and formats at a very high velocity. The communication protocols variate from OPC-UA to the traditional web-sockets, whereas data formats were in variation from low level binaries to JSON and XML. Here’s another flow diagram expressing the architecture with the context of how data flows from the Industrial Robots to the Data Lake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*TAVKcOQt9w2p_GLtMzzIrg.png" /><figcaption>Master Thesis Architecture Diagram</figcaption></figure><p>This explains the part “Franework for Sensor Data” but what about “<strong>Extensible</strong>”? The resulting framework could perform the above mentioned task in the context of Industrial Internet of Things but was also robust enough that it could handle the incoming data from other domains; with an idea of plug-and-play with the slight configuration without altering or updating any component of the Application.</p><blockquote>To defend the extensibility of the Framework I also developed a POC based on Car-to-X application that could help in monitoring traffic congestions at real time involving <strong>Map-Matching</strong>.</blockquote><h4>Phase # 1 — Wrappers for the incoming Data from Machines</h4><p>As industrial systems are based on heterogeneous data sources, we need such software components that are dynamic enough to adapt the change which might occur. Functionality that starts from message queuing system and involvement of streaming engine will remain more-or less the same but the source of data will change as per the change in incoming data or associated protocols of the sensor. Initially, the robots I got to work on were targeting the Web Sockets, TCP Clients and OPC-UA Clients. They can be configured as per the input expected from the sensors via their associated XML resource file which help them to efficiently communicate with the ecosystem built for this thesis. The Wrapper application which I wrote for these input handles data via configuration files, with which one can control the flow of data that initiates from sensors, robots and industrial machines.</p><h4>Phase # 2 — Message Queuing System with Apache Kafka</h4><p>An API based on Apache Kafka, a distributed messaging framework was developed and deployed on one of the University Cloud (got a dedicated <strong>Cloud Server </strong>for the implementation of Messaging System, thanks to my Professor 😃). The target functionality of Apache Kafka was to handle the generated data from multiple sensors. I chose Apache Kafka because of its functionality of replaying data and its implementation of topic subscriptions. Kafka’s topic subscription itself acted as a framework for subscription and separate producers and consumers were handling the incoming data on the basis of different sources. In this manner using Apache Kafka as a fault tolerance and low memory consumption system was a great deal in reducing the load prior to the Streaming Engine. Here’s a flow diagram representing the role Kafka was playing in my Master Thesis. Other options would have been Apache Flume but yeah Kafka wins!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rjz78THhTZRynvFwwt0mCw.png" /><figcaption>Kafka Messaging System Implementation</figcaption></figure><h4>Phase # 3 — Real Time Streaming Engine</h4><p>Apache Spark is used as a streaming engine to process the incoming stream of data in real-time. This real-time processing exploits the data and makes an ease for further analysis purposes. Apache Spark comes with lots of support such as windowing techniques, sliding steps and data stream mining. Apache Kafka can also act as an Streaming Engine but we choose Apache Spark as it can be extended when the involvement of Machine Learning is required, Spark MLib can play a major role in real time prediction. Apache Spark provides such an awesome eco-system which neither Apache Kafka nor any other streaming engine provides. This includes the native support for dynamic query language, libraries for graph and machine learning libraries.</p><blockquote>Just like the variety of data collecting sources, Apache Kafka and this real time streaming engine implementation were also a stand alone project with out any dependency on other components in the pipeline of my Thesis. Spark’s implementation was Scala based, can be configured and executed to any system with Java Virtual Machine.</blockquote><h4>Phase # 4 — Ingestion to the Data Lake</h4><p>The process that initiated from the machines generating sensor data, ends up in the Data Lake. For my thesis, a document based Database MongoDB acted as a data lake for the later consumption of the collected meaningful data. There were several reason why I choose MongoDB but I believe those are not meant to be explained in this excerpt. However, apart from MongoDB I had a choice to go for either Apache Cassandra or Apache Hbase.</p><p>In addition to this ingestion of data to its final location, I wrote a small <strong>MEAN Stack Application (MongoDB, Express, Angular, Node)</strong> to visually represent the data going towards the data lake.</p><p>Visualized MongoDB was a simple application and was an alternative to use MongoDB Console which represents textual format of the Documents in the Collections of particular MongoDB Database. With this application we can avoid the textual command on console to check the data in our database. This alternative helped me monitor the inserting of each and every set of data which if not implemented would have to executed manually on a very frequent basis to monitor the ingestion of data.</p><blockquote>This MEAN stack application wasn’t a part of my initial proposal to Master Thesis but an extra effort to show my dedication… got acknowledged by my Professor on this small effort.</blockquote><h3>Connected Car, a Map Matching Implementation</h3><p>Last but not the least, to justify the extensibility of my Master Thesis I came up with the <strong>use-case</strong> based on Connected Cars. Without any change to my actual implementation, I just switched the source of data. I swapped the incoming data from machines with those generated by the sensors in the Car and I start getting the location of each car at real time. This additional implementation of Map Matching Algorithm with in my Spark Streaming Engine let me to prove the extensibility of my framework by detecting the traffic congestion on the road. Here’s a visual representation in the form of GIF Image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LHx-2pWfQhrF0DONc1PHwg.gif" /><figcaption>Connected Car — Map Matching Algorithm</figcaption></figure><blockquote>“Map matching is the problem of how to match recorded geographic coordinates to a logical model of the real world, typically using some form of Geographic Information System.” via <a href="https://en.wikipedia.org/wiki/Map_matching">Wikipedia</a></blockquote><p>That would be it, hope this helps to anyone who reads.<br>Clap to appreciate. One, Two or lots of Claps. Thank you 😃</p><blockquote>You can find/follow me <a href="https://twitter.com/intent/follow?screen_name=ok_ansari">@ok_ansari</a>. Cheers, <a href="https://medium.com/u/bb020ae5c9a8">Omer Kalim Ansari</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8cdd67f1eb9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/micro-services-pipeline-for-an-industrial-internet-of-things-a8cdd67f1eb9">Micro Services pipeline for an Industrial Internet of Things (IIOT) Framework… towards Data…</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>