<?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 Anil Selim Surmeli on Medium]]></title>
        <description><![CDATA[Stories by Anil Selim Surmeli on Medium]]></description>
        <link>https://medium.com/@surmelianil?source=rss-524a5df16716------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Vsc77pyj0hz3pvsn.jpg</url>
            <title>Stories by Anil Selim Surmeli on Medium</title>
            <link>https://medium.com/@surmelianil?source=rss-524a5df16716------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 12:54:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@surmelianil/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[Trace Your Requests Like A Boss with OpenTracing & Jaeger]]></title>
            <link>https://medium.com/hackernoon/trace-your-requests-like-a-boss-with-opentracing-jaeger-cc8a07a0edc0?source=rss-524a5df16716------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc8a07a0edc0</guid>
            <category><![CDATA[jaeger]]></category>
            <category><![CDATA[zipkin]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[tracing]]></category>
            <category><![CDATA[opentracing]]></category>
            <dc:creator><![CDATA[Anil Selim Surmeli]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 03:25:30 GMT</pubDate>
            <atom:updated>2019-01-27T03:25:30.471Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o59-2_98TPsQQllPT2uzEw.png" /><figcaption>credits: jaegertracing.io</figcaption></figure><p>Let’s say your services get thousands of requests per second, you log enormously and you don’t miss any exception in your logging system. Suddenly, the operation team sent you a message pointing to an error for a customer with id X on production and you couldn’t understand why all the people around you are over-stressed… and then the penny dropped. The customer X is actually a friend of the boss! (<em>true story)</em></p><p>Ok… Let’s see what you can do:</p><p>You searched X on your logging system and waited forever as there are TBs of logs. Then you tried it again with a more detailed query such asuserId=X not in this and that but in this at time t , and got the resu… oh, another problem! Error: wrong query syntax.Your teammate said that you need to replace not in thiswith in not this. After you also fixed that and waited about 10 secs, 24 results appeared on the screen! Now you are ready to analyze them.</p><p>… 10 minutes later…</p><p>You figured out that ServiceA called service ServiceB and as method LongRunningProcess in ServiceB took 3 seconds, service A returned 500.</p><p>After all, you are glad to find the bug in about 20 minutes.</p><p>Let’s replay the process assuming that you use <em>Open Tracing</em> and <em>Jaeger</em>.</p><ul><li>You visited Jaeger UI on your browser</li><li>You wrote userId=X to tags and set the date</li><li>You clicked search and the result is below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GpxVGNIrjC4SGEGTYXRqwg.png" /><figcaption>Example request that Jaeger traced</figcaption></figure><p>In couple of seconds, you can understand that LongRunningProcess took actually 3 seconds, and as a result, ServiceA returned 500.</p><p>Open tracing is an open standard for distributed tracing, and Jaeger is the tool that implements the standard. Please check the Jaeger architecture from <a href="https://www.jaegertracing.io/docs/1.8/architecture/">it’s official documentation</a> beforehand.</p><p>Today, we are gonna create 2 APIs and 1 console client for our demo environment using .net core. I will also use a simple wrapper that I wrote as it brings simplicity in my opinion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*naE7TPLNJVNEpzWOw5Y0WA.png" /></figure><p>Let’s start!</p><h4>Clone the Repo &amp; Prepare your environment</h4><p>If you have .net core and docker installed on your workspace, you are ready to go.</p><p>Get the docker image for Jaeger and run it:</p><pre>docker run -d --name jaeger \<br>  -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \<br>  -p 5775:5775/udp \<br>  -p 6831:6831/udp \<br>  -p 6832:6832/udp \<br>  -p 5778:5778 \<br>  -p 16686:16686 \<br>  -p 14268:14268 \<br>  -p 9411:9411 \<br>  jaegertracing/all-in-one:1.6</pre><p>Clone the repo I prepared for this article: <a href="https://github.com/skynyrd/opentracing-with-jaeger">https://github.com/skynyrd/opentracing-with-jaeger</a></p><p>We have one .net core solution containing 4 projects: ConsoleClient , ServiceA , ServiceB and JaegerWrapper. We are going to walk thru all of them. Let’s start with JaegerWrapper to understand the dynamics of the Jaeger client.</p><h4>JaegerWrapper: For syntactic sugar — Because why not?</h4><p>In order to use Jaeger client, we first need to understand how traces work in our code.</p><blockquote>A <strong>trace</strong> is a data/execution path through the system, and can be thought of as a directed acyclic graph of <a href="https://www.jaegertracing.io/docs/1.8/architecture#span">spans</a>.</blockquote><blockquote>A <strong>span</strong> represents a logical unit of work in Jaeger that has an operation name, the start time of the operation, and the duration. Spans may be nested and ordered to model causal relationships.</blockquote><blockquote>— Official Jaeger docs.</blockquote><p>In an application, we need to have a Tracer that manages our spans. I strongly recommend having one tracer in a microservice for simplicity. After creating the Tracer and registering it, the jaeger client library starts to analyze the controllers in the system by default, even we don’t need to create a singleTraceand Span for that, all created by the OpenTracing.Contrib.NetCore library. However, if we want to analyze a specific method, or add some additional tag/log to our spans, we need to create a Trace and bind a Span to it.</p><p><em>Important Note: If you create and activate a span when there is another active span in the system, it becomes a child. You can see it in the diagram above; parent spans are expandable.</em></p><p>I wrote a simple builder for this purpose and JaegerWrapper is a class library that contains it, you can use/copy if you like.</p><pre>_traceBuilder<br>  .WithSpanName(&quot;LongRunningProcess&quot;)<br>  .WithTag(new StringTag(&quot;exampleTag&quot;), &quot;exampleValue&quot;)<br>  .TraceIt(() =&gt;<br>  {<br>    Thread.Sleep(3000);<br>  });</pre><p>To give an example, this code block is for LongRunningProcess span represented by a yellow horizontal bar in the diagram above. We added exampleTag: exampleValue to it and we can even add more complex structures using WithLog method. Time consumed by TraceIt is published as a span duration in the GUI. In the example, I used a simple Thread.Sleep(3000) , but you can also return something (Func instead of Action) e.g.:</p><pre>var result = _traceBuilder<br>              ...<br>              .TraceIt(() =&gt; <br>              {<br>                 return &quot;something&quot;<br>              }</pre><h4>Passing across the APIs</h4><p>If you are going to HTTP call a service and you want to preserve your span lifetimes, you need to notify the other service somehow.</p><p>For the most cases you would like to use the OpenTracing.Contrib.NetCore package to automate the configurations, but if you are curious, here is the logic behind that:</p><p>Jaeger solves it with HTTP headers that are going to append to the request. You can also use JaegerWrapper for more abstraction:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2015e7615d1c6a93524b457a1971ca3/href">https://medium.com/media/c2015e7615d1c6a93524b457a1971ca3/href</a></iframe><h4>Configuration for WebAPIs</h4><p>For ServiceA and ServiceB we need to register the services for Jaeger:</p><pre>// In ConfigureServices method of Startup class:</pre><pre>GlobalTracer.Register(Tracer);<br>services.AddOpenTracing();</pre><p>If you also want to use the wrapper, you can simply add these:</p><pre><strong>var </strong>serviceProvider = services.BuildServiceProvider();</pre><pre>services.AddScoped&lt;ITraceBuilder&gt;(t =&gt; <br>    <strong>new </strong>TraceBuilder(serviceProvider.GetService&lt;ITracer&gt;()));</pre><h4>Example Calls</h4><p>Have a look at AWorldController of ServiceA, we call ServiceB there but didn’t use any JaegerClient or JaegerWrapper method. This is because we added OpenTracing.Contrib.NetCore library and it traces our requests in the black box, magically.</p><pre><strong>private static async </strong>Task&lt;<strong>dynamic</strong>&gt; GetBObject(<strong>string </strong>id)<br><strong>{<br>    var </strong>httpClient = <strong>new </strong>HttpClient<br>    {<br>        BaseAddress = <strong>new </strong>Uri(&quot;http://localhost:7334&quot;)<br>    };<br><br>    <strong>var </strong>result = <strong>await </strong>httpClient.GetAsync($&quot;/bworld/id/{id}&quot;);<br><br>    <strong>if </strong>(result.IsSuccessStatusCode)<br>    {<br>        <strong>return await </strong>result.Content.ReadAsAsync&lt;<strong>dynamic</strong>&gt;();<br>    }<br>    <br>    <strong>throw new </strong>Exception(&quot;uncovered area.&quot;);<br><strong>}</strong></pre><p>And check the Main method of the ConsoleClient. This time, as this is not a WebAPI, we manually traced our call using JaegerWrapper.</p><pre>traceBuilder.WithSpanName(&quot;MainWork&quot;)<br>    .WithHttpCall(client, url, HttpMethod.Get)<br>    .TraceIt(() =&gt;<br>    {<br>        <strong>var </strong>response = client.GetAsync(url).Result;<br><br>        <strong>if </strong>(!response.IsSuccessStatusCode)<br>            <strong>throw new </strong>Exception(&quot;uncovered area for the demo.&quot;);<br><br>        <strong>var </strong>responseBody = response.Content.ReadAsStringAsync().Result;<br>        Console.WriteLine(responseBody);<br>    });</pre><p>I used Zipkin instead of Jaeger on production couple of years ago, thus I don’t want to write anything about the performance. But I can say that Zipkin was quite performant. If you have production experience with Jaeger, please comment below, I’m curious about it!</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc8a07a0edc0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/trace-your-requests-like-a-boss-with-opentracing-jaeger-cc8a07a0edc0">Trace Your Requests Like A Boss with OpenTracing &amp; Jaeger</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Easiest Way To Secure Your .NET Core APIs using IdentityServer4]]></title>
            <link>https://medium.com/hackernoon/the-easiest-way-to-secure-your-net-core-apis-using-identityserver4-e4fccdaddf6f?source=rss-524a5df16716------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4fccdaddf6f</guid>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[identityserver4]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Anil Selim Surmeli]]></dc:creator>
            <pubDate>Thu, 10 Jan 2019 13:19:25 GMT</pubDate>
            <atom:updated>2019-01-10T22:37:27.498Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Easiest Way To Secure Your .NET Core APIs using IdentityServer4</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwztV361OG-FXNGkwxeieA.jpeg" /><figcaption>Credits: Telerik Developer Network</figcaption></figure><p>Nowadays, my daily work is all about OpenID Connect, OAUTH2, JSON web tokens and modernizing the authentication process. Yes, it is complicated especially in high-sensitive systems, but today, I’m not gonna prattle about them, I mean, mostly. Instead, I’ll try to explain the *easiest* way to secure your WebAPIs using IdentityServer4.</p><blockquote>-Easiest?</blockquote><p>Yes, easiest. Not fancy, but simple and useful solution. Like a budget smartphone… or 2000’s rock music… or… anyways.</p><p>We’re going to create 3 projects for the demo environment. One will be a client, one will be an API that will be consumed by the client, and one will be the identity service powered by IdentityServer4.</p><p>Let’s start!</p><p>The flow we are going to use is called “<em>Client Credentials”. </em>It only uses the IdentityServer4 and there is no open id connect configuration. Pretty simple as I said.</p><h4>Create three empty folders for each service</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*fsMROheEpdjRLqlo5Vg1lQ.png" /><figcaption>cd ~/ &amp;&amp; mkdir ClientCredentials &amp;&amp; mkdir ClientCredentials/TheClient &amp;&amp; mkdir ClientCredentials/TheIdentityServer &amp;&amp; mkdir ClientCredentials/TheServer</figcaption></figure><h4>Setting Up The Identity Server</h4><p>In TheIdentityServer folder, we need to create new .net core webapi application: dotnet new webapi , add dependencies dotnet add package IdentityServer and restore the project: dotnet restore (or let VS/Rider do the job for you)</p><p>We need to somehow register our clients and APIs in the application. Let’s create some static lists for that purpose. Create Config.cs and paste below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/874055d7508442cc831a5cc723917b3a/href">https://medium.com/media/874055d7508442cc831a5cc723917b3a/href</a></iframe><p>We’ve just registered our client and API in the application. I chose to register first although we don’t have solutions, not a big deal.</p><p>Our API name is TheApi and we’ve used it in AllowedScopes property of our client. That means, whenever a client with the client id TheClientId trying to access an API whose name is TheApi , do not block it. Notice that we’ve also set AllowedGrantTypes to GrantTypes.ClientCredentials which shows that we don’t follow hybrid or implicit flow. (we will discuss it later), also we set client secret, which is going to be used to authorize the client by the token endpoint.</p><p>Then we need to use this lists in the ConfigureServices method in Startup.cs</p><pre>services.AddIdentityServer()<br>  .AddDeveloperSigningCredential()<br>  .AddInMemoryApiResources(Config.GetApiResources())<br>  .AddInMemoryClients(Config.GetClients());</pre><p>We used in memory clients and API resources as we use lists. In production, we should of course use some kind of client store. IdentityServer4 verifies the token by a key, for development purposes we’ve added that by AddDeveloperSiginingCredential , also it should be changed for the production use.</p><p>We also need to add the middleware by adding app.UseIdentityServer() to the Configure method.</p><p>Lastly, just add the host url (port 5000) in Program.cs :</p><pre>...<br>WebHost.CreateDefaultBuilder(args)<br>   .UseUrls(&quot;http://localhost:5000&quot;)<br>   .UseStartup&lt;Startup&gt;();<br>...</pre><h4>Setting Up The API</h4><p>Assuming we have a webapi in TheServer folder, we have 2 tasks to do after adding the dependencies IdentityServer4.AccessTokenValidation and restoring the project:</p><ul><li>Registering the identity service that we’ve just created:</li></ul><p>Add to ConfigureServices :</p><pre>services.AddAuthentication(&quot;Bearer&quot;)<br>    .AddIdentityServerAuthentication(options =&gt;<br>    {<br>        options.Authority = &quot;http://localhost:5000&quot;; // Id.Ser.Addr.<br>        options.RequireHttpsMetadata = <strong>false</strong>;<br><br>        options.ApiName = &quot;api1&quot;;<br>    });</pre><p>Add to Configure :</p><pre>app.UseAuthentication();</pre><p>Add host url (port 5001) in Program.cs :</p><pre>...<br>WebHost.CreateDefaultBuilder(args)<br>   .UseUrls(&quot;http://localhost:5001&quot;)<br>   .UseStartup&lt;Startup&gt;();<br>...</pre><ul><li>And we need to add [Authorize] attribute to a controller we want to secure, of course.</li></ul><p>By the way, we can delete app.UseHttpsRedirection(); as we don’t need to use https as we are preparing a demo app.</p><h4>Setting Up The Client</h4><p>Client can be any application that is going to call The Server (API), so we are going to create a console app for brevity.</p><ul><li>In TheClient folder: dotnet new console</li><li>Add the IdentityModel dependency.</li><li>Change the Program.cs with below:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae815ff6808ae37c689a6c2245eaacea/href">https://medium.com/media/ae815ff6808ae37c689a6c2245eaacea/href</a></iframe><p>DiscoveryClient is located in the dependency we’ve added, IdentityModel. It is a useful wrapper around the HTTP client. We can directly use TokenEndpoint property from the HTTP response as you can see. To get the “Access Token”, we use our credentials, which are TheClientId and secret. Also, we request access from TheApi as we registered in the identity service.</p><p>If everything goes well, we are ready to call the actual API with the access token we get from the identity service.</p><h4>Time to run</h4><ul><li>Run the applications:</li></ul><pre>// first terminal</pre><pre>cd TheIdentityServer<br>dotnet run</pre><pre>// second terminal</pre><pre>cd TheServer<br>dotnet run</pre><p>Lastly, we need to run the console client by dotnet run again.</p><p>The result should be in this structure:</p><pre>Token Response:</pre><pre>{<br>  &quot;access_token&quot;: &quot;eyJhbGciOiJSUzI1NiIsImtpZCI6ImVhYTA3MjAzM2ZlMWM2ODQ5NmZlM2Y5MjA1MmJkZDMyIiwidHlwIjoiSldUIn0.eyJuYmYiOjE1NDcxMjUwODksImV4cCI6MTU0NzEyODY4OSwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAwIiwiYXVkIjpbImh0dHA6Ly9sb2NhbGhvc3Q6NTAwMC9yZXNvdXJjZXMiLCJUaGVBcGkiXSwiY2xpZW50X2lkIjoiVGhlQ2xpZW50SWQiLCJzY29wZSI6WyJUaGVBcGkiXX0.VyGQzOgK7YGlP_Z8Gca-aYUAahm8SIXQroozwDJqS03TPWYTZKy-aHRR2dRRxtrH1r47kxmJ7AN0ZhrwWCeY6FW06wHyUFBs_q9Bt7noXnFKuPgKNNNWZWofsj6vLQQKTI28_gETyH5uAenLPXhXotbLB9e1iWtyZEX64qL79BujXMBsMIK-MHdalMbEPV_3ktSGb4MICL1Ce5TxFr8eL-9iHuf1Z1pglMD6ceESXGT22eTzDp8stpJrKG4q9uNCi00_XFt7AHVKJDo2R3LrYYZF-pIFwy1P4ISKlmTco9hsxRCFYj7WOdF6_O-X4kgAiD5_sOrFwSuXl1Z08GYWxg&quot;,<br>  &quot;expires_in&quot;: 3600,<br>  &quot;token_type&quot;: &quot;Bearer&quot;<br>}</pre><pre>**************************<br>Status code from the API:</pre><pre>OK</pre><pre>**************************<br>Response body:<br>Response body:<br>[&quot;value1&quot;,&quot;value2&quot;]</pre><p>Token response from the identity service that we’ve created, status code of the result from the API and the response body.</p><p>Try changing the secret and TheClientId in the Client application and run it again, you’ll see that it won’t get the access_token this time, identity service is going to block it.</p><p>That’s it for today, here is the GitHub repo of the demo apps: <a href="https://github.com/skynyrd/ClientCredentialsExample">https://github.com/skynyrd/ClientCredentialsExample</a></p><p><a href="https://twitter.com/_skynyrd">Follow me on twitter</a></p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4fccdaddf6f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/the-easiest-way-to-secure-your-net-core-apis-using-identityserver4-e4fccdaddf6f">The Easiest Way To Secure Your .NET Core APIs using IdentityServer4</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why We Replaced Our Kafka Connector with a Kafka Consumer]]></title>
            <link>https://medium.com/hackernoon/why-we-replaced-our-kafka-connector-with-a-kafka-consumer-972e56bebb23?source=rss-524a5df16716------2</link>
            <guid isPermaLink="false">https://medium.com/p/972e56bebb23</guid>
            <category><![CDATA[apache-kafka]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[kafka-connect]]></category>
            <category><![CDATA[kafka-streams]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Anil Selim Surmeli]]></dc:creator>
            <pubDate>Sat, 16 Dec 2017 12:58:22 GMT</pubDate>
            <atom:updated>2018-11-16T04:00:13.160Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*rCSZxf-gglx1u0-vni07rQ.jpeg" /><figcaption>Confused?</figcaption></figure><p>A few months ago, I wrote about <a href="https://hackernoon.com/writing-your-own-sink-connector-for-your-kafka-stack-fa7a7bc201ea">creating your own sink connector</a> after we started using ours. Surprisingly, we replaced it with <a href="https://kafka.apache.org/documentation/#consumerapi">Kafka Consumers</a> last week. I am going to review our experience and try to write the advantages and disadvantages of both technologies in this short article.</p><h4>But Why?</h4><p>To say the truth, we were quite satisfied with our custom Elastic Sink Connector; it already handled our traffic (up to 7000 product data per second (<em>each one is about 1000 lines)</em>, on 4 docker containers) and no single performance failure has happened. However,<strong> debugging and testing is A LOT difficult for custom Kafka Connectors!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*M-niOn2-KTD9EBTH_KmEOA.jpeg" /><figcaption>Yes, unfortunately.</figcaption></figure><p>You cannot write your integration tests easily as it is some kind of plugin in your Kafka stack. You need to mock internal Kafka classes, create <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/anti-corruption-layer">anti corruption layers,</a> spend much time on unit tests and… Still, you don’t feel satisfied as there are no end-to-end or integration tests.</p><p>Assume that you have a bug in production and you can’t figure it out as your tests are not complete for the reasons above. Ok, you want to debug the connector in your local. Unfortunately, it is quite a luxury word for Kafka Connectors. If you need to put a breakpoint somewhere, you need to do A LOT of “<em>wtf… really?”</em> staff <a href="https://stackoverflow.com/a/45719652">mentioned here</a>. Creating your environment? You can attach your connector to Landoop’s <a href="https://github.com/Landoop/fast-data-dev">fast-data-dev</a> stack, but again, it is not debugging, you just cloned the problem and trying to solve it in a more controllable infrastructure.</p><p>For this reasons, we replaced our custom Sink Connector with a regular Kafka Consumer and now it is like a piece of cake to maintain it. (At least for now…)</p><p>We were wondering about the performance, but the test results impressed us. For our performance concerns, they are almost identical. Maybe it can show a change in a quite big traffic, but this time you can scale right, it is the best advantage of Kafka.</p><h4>Migrating to Kafka Consumers</h4><p>Debugging and testing Kafka Consumers are quite easy, just like a regular API. If you decide to move to consumers, you can write in many programming languages. We first thought about writing it with Python or C#, but our final choice was Java. Because we could copy our classes in Kafka Connect project in a short time. (You must use Java for your custom Kafka Connectors)</p><p>I want to emphasize the main point here: Committing the offsets.</p><p>In a custom Kafka Connector, the framework auto commits the messages if there is no exception in put method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0bbd88ed3b2472434cda7abd1e487cc/href">https://medium.com/media/b0bbd88ed3b2472434cda7abd1e487cc/href</a></iframe><p>In Kafka Consumers, you can use auto-commit again but this time you should consider that the framework commits just after you received the topic messages. What I’m trying to say is, if your code threw an exception before transferring the data, you lost the message.</p><p>Instead, you can commit manually and that is really easy to imitate Connect’s behaviour, just commit after you complete your job :)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b54dce021dc920af7edcfda560364fd5/href">https://medium.com/media/b54dce021dc920af7edcfda560364fd5/href</a></iframe><h4>So, do you mean that you don’t recommend Kafka Connectors?</h4><p>No! If you need to simply transfer your topic data to another system, or vice versa, and there is a community/Confluent supported Kafka Connector, use it! - A little configuration and boom, it’s ready. However, if you must write your own Kafka Connector for some reasons, please consider that testing and debugging is hard.</p><p>Thanks for reading,</p><p>Sometimes I tweet a useful piece of information: <a href="https://twitter.com/_skynyrd">@_skynyrd</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=972e56bebb23" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/why-we-replaced-our-kafka-connector-with-a-kafka-consumer-972e56bebb23">Why We Replaced Our Kafka Connector with a Kafka Consumer</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing Your Own Sink Connector for Your Kafka Stack]]></title>
            <link>https://medium.com/hackernoon/writing-your-own-sink-connector-for-your-kafka-stack-fa7a7bc201ea?source=rss-524a5df16716------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa7a7bc201ea</guid>
            <category><![CDATA[elastic]]></category>
            <category><![CDATA[kafka-connect]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Anil Selim Surmeli]]></dc:creator>
            <pubDate>Sun, 17 Sep 2017 11:06:41 GMT</pubDate>
            <atom:updated>2017-10-20T13:48:05.294Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eC3fKob7FdMJqITZX5ZX6w.png" /><figcaption>The image from <a href="https://www.confluent.io/blog/announcing-kafka-connect-building-large-scale-low-latency-data-pipelines/">here.</a></figcaption></figure><p>There can be no Kafka Connector for your system, or available ones may not meet your requirements. On both cases, you have to write your own Kafka Connector and there are not many online resources about it. I’ll try to write my adventure to help others suffering with the same pain.</p><p>Here is my case: I want to read data from a Kafka topic and write them to Elastic index if data has “insert” flag in it’s status field, or delete them if status is “delete”. I know I couldn’t use official or any other open source Elastic sink connectors as they have one generic behavior option, not depending on data, but connector configuration.</p><p>For local development and testing, I’ve used <a href="https://github.com/Landoop/fast-data-dev">Landoop’s fast-data-dev project</a> as it includes Zookeeper, Kafka, Connect and sufficient UI tools in just one docker container.</p><h4>Getting Ready</h4><p>If you want to write your own source or sink connector, you have to use Java, because our main idea is to create some jars from our project that is going to be a plug-in for our local Kafka Connect cluster, or standalone server. So, make sure that you have JDK on your local. I’ve used IntelliJ IDEA as I am a JetBrains fan.</p><h4>Create Your Project Using Custom Connect Maven Archetype</h4><p>There is a <a href="https://maven.apache.org/guides/introduction/introduction-to-archetypes.html">maven archetype</a> for your project, a bunch of skeleton classes included. In order to use it via IntelliJ, you can add it when creating a new project. Here is its <a href="https://github.com/jcustenborder/kafka-connect-archtype">Github repository.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*mTLegDS-lTwK2btwDTkYnQ.png" /><figcaption>Not forget to use the latest version. <a href="https://github.com/jcustenborder/kafka-connect-archtype">Check it out from its repo.</a></figcaption></figure><h4>What we are going to build?</h4><p>As I said, we are going to create a custom Elastic Sink Connector that is going to behave according to the topic data. I am going to explain the most important parts of the project, please <a href="https://github.com/skynyrd/kafka-connect-elastic-sink">clone my repository</a> to catch the following snippets.</p><h4>ElasticSinkConnectorConfig.java</h4><p>You will use this class in order to get configuration properties, its pretty straight forward class. First you should define your config element, such as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*eU0RvdA98BaR4TnMTnuDoA.png" /><figcaption><a href="https://github.com/skynyrd/kafka-connect-elastic-sink/blob/master/src/main/java/com/skynyrd/kafka/ElasticSinkConnectorConfig.java">Link to source</a></figcaption></figure><p>ELASTIC_PORT is the config property that will be used for our Elastic transport client, or you can say Elastic driver. ELASTIC_PORT_DOC is the explanation property that are used by ConfigDef static method.</p><p>ConfigDef is a method in kafka common package and we are binding all of our properties here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*N4rq7nmX2wGZB1QkszKRIA.png" /><figcaption><a href="https://github.com/skynyrd/kafka-connect-elastic-sink/blob/master/src/main/java/com/skynyrd/kafka/ElasticSinkConnectorConfig.java">Link to source</a></figcaption></figure><p>And the rest of the file includes getters and setters of properties, not a complex stuff here.</p><h4>ElasticSinkConnector.java</h4><p>If you have something to do when starting to consume from a topic, or stopping the connector, this is the class you should implement.</p><p>Just going over the methods:</p><ul><li>version() returns the version of the connector,</li><li>start() takes configuration fromconnector.properties and pass them to ElasticSinkConnectorConfig class where we discussed above,</li><li>taskClass() returns the class that does the actual work — gets data from the topic and processes. (We are going to talk about this in a minute),</li><li>stop() is kind of teardown function for your connector,</li><li>config() returns the config class — ElasticSinkConnectorConfig for us,</li></ul><p>and taskConfigs() is for your tasks. We have distributed the configs to all the tasks here: (by the way you should give <em>tasks.max</em> property from the worker configuration, and <a href="https://stackoverflow.com/a/42030617">here</a> is what value it should be)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/522/1*3Nz5wvSgK6DTDFXaqHeN1A.png" /><figcaption>By the way, I still could not realized how many task should be set for an optimal configuration.. <a href="https://github.com/skynyrd/kafka-connect-elastic-sink/blob/master/src/main/java/com/skynyrd/kafka/ElasticSinkConnector.java">Link to source</a></figcaption></figure><h4>ElasticSinkTask.java</h4><p>Here is the class you got the data from configured topic, in start() method, I create an instance ofElasticServiceImpl, I didn’t use any dependency injection strategy as testing the plug in overriding methods are really difficult and some kind of <a href="https://softwareengineering.stackexchange.com/questions/184464/what-is-an-anti-corruption-layer-and-how-is-it-used">anti corruption layer</a> is needed. For that reason, when I get the data in put() method, I directly send it to ElasticServiceImpl after a little modification and test my service instead of ElasticSinkTask class. In the constructor of elastic service, I passed null as the ElasticClient, because I am going to pass it in the test class. So, my main processing class became ElasticServiceImpl then.</p><p>The irony here is that I did not write any test class yet, I’ll implement them.</p><p>The most important thing for this class is you should be careful of using put() method as Kafka Connect commits the data offsets in this method. So, proper error handling should be done here.</p><h4>ElasticServiceImpl.java</h4><p>In constructor, we setup JsonConverter and Gson serializer just before creating an instance of ElasticClient.</p><p>In process() method, I convert record strings to Record data type since it is more readable and more processable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*nhNlg34ArG5K6s6yV9kZGg.png" /><figcaption>Topic message representation. <a href="https://github.com/skynyrd/kafka-connect-elastic-sink/blob/master/src/main/java/com/skynyrd/kafka/Record.java">Link to source</a></figcaption></figure><p>After playing with some Gson methods to convert strings to Records, it is ready to be sent to Elastic.</p><h4>ElasticClientImpl.java</h4><p>As an Elastic client, I have tried using <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.4/transport-client.html">Transport Client</a> at first as it connects like another node to your Elastic cluster and <a href="https://www.elastic.co/blog/benchmarking-rest-client-transport-client">bulk indexing is little bit faster</a> than http protocol. However, I faced with an error and could not find any solution, <a href="https://stackoverflow.com/questions/46179241/nosuchmethoderror-when-constructing-prebuilttransportclient-for-elastic">even I asked it to StackOverflow</a>. I think it can be related to fast-data-dev container, or docker networking configuration etc. Then I switched to <a href="https://github.com/searchbox-io/Jest">Jest Client</a> as http protocol performance is also great related to the same article I have mentioned above.</p><p>In bulkSend() method, simply we add each data in dataList to the Bulk, if behavior of Record is insert, then Index request is added, else Delete request is attached to the Bulk.</p><p>We send it to Elastic and log if any error occurs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*Jdi2cIvF8j-ccxIuxJtPOg.png" /><figcaption><a href="https://github.com/skynyrd/kafka-connect-elastic-sink/blob/master/src/main/java/com/skynyrd/kafka/client/ElasticClientImpl.java">Link to source</a></figcaption></figure><h4>Conclusion</h4><p>To conclude, we have to write our own sink or source connector if there is no community implementation for our system. Also there can be ready to use connectors, but you may need to change its behaviour.</p><p>The most challenging part of this process is testing your connector. What you implement is somekind of plugin to your connect cluster and it is not a standalone application. Writing unit tests are tricky as you override methods of Kafka Connect package and kind of anti corruption layer is needed. Also debugging is quite difficult.</p><p>You can test the connector using the docker-compose file I have written and following the steps in <a href="https://github.com/skynyrd/kafka-connect-elastic-sink">my repository</a>.</p><p>Thanks,</p><p>Sometimes I tweet useful piece of information: <a href="https://twitter.com/_skynyrd">@_skynyrd</a></p><p>Helpful resources I have used:</p><ul><li><a href="https://docs.confluent.io/current/connect/devguide.html">https://docs.confluent.io/current/connect/devguide.html</a></li><li><a href="https://www.udemy.com/kafka-streams/">Stephane Maarek’s Udemy courses</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa7a7bc201ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/writing-your-own-sink-connector-for-your-kafka-stack-fa7a7bc201ea">Writing Your Own Sink Connector for Your Kafka Stack</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy your React & .NET Core Apps on Linux using Nginx and Supervisor]]></title>
            <link>https://medium.com/hackernoon/deploy-your-react-net-core-apps-on-linux-using-nginx-and-supervisor-5a29d0b6ef94?source=rss-524a5df16716------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a29d0b6ef94</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[supervisor]]></category>
            <dc:creator><![CDATA[Anil Selim Surmeli]]></dc:creator>
            <pubDate>Mon, 23 Jan 2017 20:30:09 GMT</pubDate>
            <atom:updated>2017-09-18T12:36:01.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6pAq_q29-6O2zoxXFCGkQ.png" /></figure><p>After a long day trying to deploy my .NET Core microservice to IIS7(?), I finally persuaded my client to port our app to a linux server.</p><p>In this post, I am going to create a simple React app that uses a .NET Core backend service, indeed, my goal is writing about tricky process of deployment. Here are the steps:</p><ul><li>Creating a sample React app &amp; Getting the prod ready files</li><li>Creating a sample .NET Core app</li><li>Connect and send them to a Linux machine</li><li>Installing Nginx &amp; configuration — Deployment for client</li><li>Supervisor installing &amp; configuration — Deployment for server</li></ul><h3>Creating a sample React application</h3><p>For creating a boilerplate code, I am going to use create-react-app, which is an official cli for react applications. I had zero problem with it.</p><p><a href="https://github.com/facebookincubator/create-react-app">Here</a> you can find further information</p><ol><li>Install it:</li></ol><pre>$ npm install -g create-react-app</pre><p>2. Create your project:</p><pre>$ create-react-app sample-react-app</pre><p>3. Check that everything is ok. Application will be running at port 3000.</p><pre>$ cd sample-react-app<br>$ npm start</pre><p>4. Let’s prepare the build files for the deployment</p><pre>$ npm run build</pre><p>Now you have a build folder in your project folder that contains asset-manifest.json favicon.ico index.html and static. Cool, we have a sample front end base now. We will send this file to the remote server.</p><h3>Creating a sample .NET Core application</h3><p>I can use Visual Studio 2015 to create our backend base, but I prefer using Yeoman for those who have Mac or Linux.</p><ol><li>Install Yeoman:</li></ol><pre>$ npm install -g yo</pre><p>2. Install ASP.NET Generator:</p><pre>$ npm install -g generator-aspnet</pre><p>3. Create your .NET Core Microservice:</p><p><em>Choose:<br> * Web Application Basic [without Membership and Authorization]<br> * Bootstrap<br>Name it:<br> * SampleMicroservice</em></p><pre>$ yo aspnet</pre><p>Go inside the created folder and change the Index method of HomeController:</p><pre>public IActionResult Index()<br>{<br>    return Json(new {<br>        Hello = &quot;From the api&quot;<br>    });<br>}</pre><p>4. Go inside Program.cs and add .UseUrls(&quot;http://0.0.0.0:5000&quot;) after .UseKestrel()</p><p>Run the service and try hitting <a href="http://localhost:5000/">http://localhost:5000</a> and be sure that the json appears on screen:</p><h3>Connect and send them to a Linux machine</h3><p>For a cheap Linux VPS, I prefer <a href="http://digitalocean.com/">DigitalOcean</a>. For your personal projects, you can use Raspberry PI + a static IP as your own server.</p><p>To send what we created so far, you can use a version controlling system like Github and SVN or use SFTP protocol.</p><p>Reminder for SFTP:</p><pre>sftp username@remote_hostname_or_IP</pre><pre># Basic Commands:<br>pwd -&gt; remote working dir<br>ls -&gt; remote ls<br>lpwd -&gt; your working dir<br>lls -&gt; ls for your machine<br>get remoteFile localFile -&gt; Get the file to the local machine<br>put localFile -&gt; Send the file to the remote server</pre><pre># simply put l as a prefix to the commands for running them in local machine</pre><h3>Installing Nginx &amp; configuration — Deployment for client</h3><p>So, we are in our Linux server, connected via ssh and our build folder extracted by npm run build is in our workspace.</p><p>SSH Reminder:</p><pre>$ ssh user_name@IP<br>Then enter your pass</pre><p>Install Nginx:</p><pre>$ sudo apt-get install nginx</pre><p>Edit the configuration file by vim or nano:</p><pre>vim -or nano- /etc/nginx/sites-available/default</pre><p>In this file default configuration appears:</p><pre>server {<br>        listen 80 default_server;<br>        listen [::]:80 default_server;</pre><pre>        # Some comments...</pre><pre>        root /var/www/html;  <strong># STATIC FILE LOCATION</strong></pre><pre>        # Some comments...<br>        index index.html index.htm index.nginx-debian.html;</pre><pre>        server_name _;</pre><pre>        location / {<br>                # Some comments...<br>                try_files $uri /index.html;   <strong># ADD THIS</strong><br>        }</pre><pre>        # Some comments...<br>}</pre><p>At first, you should move all the files in your build folder to the static file location, which is /var/www/html as default.</p><pre>$ cp -a /your/build/folder/location/build/* /var/www/html/</pre><p>Before you copy the files, you should add try_files $uri /index.html; inside location / in the nginx configuration as you don’t want to give 404 not found error to the user trying to directly go to the different url in your single page app. You simply say here that “Any routes should match with the index.html , Let’s give the responsibility to the React Router.”</p><p>After restarting nginx, your homepage should run on the <a href="http://your_ip/">http://your_ip</a>:</p><pre>$ sudo service nginx restart</pre><h3>Supervisor installing &amp; configuration — Deployment for server</h3><p>We are again in our Linux server and <strong>our dotnet core project folder</strong> is in our workspace.</p><p>I prefer explaining this step by step:</p><h4>1. Create a user to run your future daemon -service-. And login with that user:</h4><pre>$ adduser sampleMicroService<br>...<br>$ usermod -aG sudo sampleMicroService<br>$ su sampleMicroService</pre><h4>2. Install dotnet by <a href="https://www.microsoft.com/net/core#linuxubuntu">these steps.</a></h4><h4>3. Prepare your dll files:</h4><p>Go into your project folder and extract the deployment files:</p><pre>$ dotnet restore</pre><pre>$ dotnet run (optional to check that your app runs successfully)</pre><pre>$ dotnet publish</pre><p>publish folder should be in /bin/Debug/netcoreapp1.x/</p><p>4. Move the all the files inpublish folder to somewhere in /var</p><pre>$ mv /your/publish/folder/location/publish/* /var/SampleMicroservice/</pre><p>Note: The reason we are compiling and publishing our dll’s in our deployment server instead of our local machine is that we want /home/sampleMicroService/.nuget/packages folder to set it as an environment variable in supervisor configuration. Actually this is a bug in dotnet cli, if we don’t set an environment variable ArgumentNullException is thrown with path1 can&#39;t be null message. <a href="https://github.com/dotnet/cli/issues/2385">Here</a> is the bug details.</p><p>5. Install supervisor to create your daemon:</p><pre>$ sudo apt-get install supervisor</pre><p>6. Create supervisor configuration file by:</p><pre>$ sudo vim -or nano-  /etc/supervisor/conf.d/sampleMicroService.conf</pre><p>And put this inside:</p><pre>[program:sampleMicroService]<br>command=/usr/bin/dotnet /var/sampleMicroService/SampleMicroService.dll<br>directory=/var/sampleMicroService/<br>autostart=true<br>autorestart=true<br>stderr_logfile=/var/log/sampleMicroService.err.log<br>stdout_logfile=/var/log/sampleMicroService.out.log<br>environment=ASPNETCORE_ENVIRONMENT=Production,NUGET_PACKAGES=&quot;/home/anil/.nuget/packages&quot;<br>user=sampleMicroService<br>stopsignal=INT</pre><p>Be sure that you set NUGET_PACKAGES environment variable here.</p><p>Stop supervisor, enable systemctl and start supervisor:</p><pre>$ sudo service supervisor stop<br>$ sudo systemctl enable supervisor<br>$ sudo service supervisor start</pre><p>From now on you can start/stop your service by:</p><pre>$ sudo supervisorctl start/stop/status sampleMicroService</pre><p>Check the error or out logs:</p><pre>$ tail -f /var/log/sampleMicroService/sampleMicroService.err.log<br>$ tail -f /var/log/sampleMicroService/sampleMicroService.out.log</pre><p>That’s it, your micro service is running on http://YOUR_IP:5000</p><p>Ps. You can easily add your domain name by clicking “Add domain” to droplet menu if you use digitalocean like me.</p><p>Thanks,</p><p>Sometimes I tweet useful piece of information: <a href="https://twitter.com/_skynyrd">@_skynyrd</a></p><p>Btw, my references:</p><ul><li><a href="https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction">Official documentation</a></li><li><a href="http://www.hanselman.com/blog/PublishingAnASPNETCoreWebsiteToACheapLinuxVMHost.aspx">Hanselman’s post</a></li><li><a href="https://medium.com/@cameronbwhite90/deploy-react-webpack-to-digital-ocean-with-nginx-and-github-b83d1cf4be0b#.854bmxdvz">Cameronbwhite90’s post</a></li><li><a href="http://stackoverflow.com/">Stackoverflow</a></li></ul><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a29d0b6ef94" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/deploy-your-react-net-core-apps-on-linux-using-nginx-and-supervisor-5a29d0b6ef94">Deploy your React &amp; .NET Core Apps on Linux using Nginx and Supervisor</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>