<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrei</title>
    <description>The latest articles on DEV Community by Andrei (@gimlet2).</description>
    <link>https://dev.to/gimlet2</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F36959%2F73f6ae0c-e747-403b-a952-a4aece65549e.jpeg</url>
      <title>DEV Community: Andrei</title>
      <link>https://dev.to/gimlet2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gimlet2"/>
    <language>en</language>
    <item>
      <title>Dockerizing Java 10 Spring Boot app</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Wed, 25 Apr 2018 20:42:54 +0000</pubDate>
      <link>https://dev.to/gimlet2/dockerizing-java-10-spring-boot-app-3b4c</link>
      <guid>https://dev.to/gimlet2/dockerizing-java-10-spring-boot-app-3b4c</guid>
      <description>

&lt;p&gt;In my previous &lt;a href="https://dev.to/gimlet2/java-10--migration-story-41k7"&gt;article&lt;/a&gt; I’ve been talking about using &lt;strong&gt;Java 10&lt;/strong&gt; to build and run your &lt;a href="https://projects.spring.io/spring-boot/"&gt;&lt;strong&gt;Spring Boot&lt;/strong&gt;&lt;/a&gt; app. Now it is time to talk how to put it in Docker container. Better support of containerization was one of the main features of Java 10 release. So, let’s go!&lt;/p&gt;

&lt;p&gt;That is fairly simple process, so just take a look on following code snippet:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;Here, as you can see, I use multi-stage Docker build file. Quick note: multi-stage builds are supported with &lt;strong&gt;Docker 17.05&lt;/strong&gt; or higher but result image is backward compatible(at least from my experience). On the first stage it downloads &lt;strong&gt;JDK&lt;/strong&gt; from Oracle’s, but it can make sense to store your own copy somewhere closer to your build server since it isn’t that small — a little bit less then 200mb. So, it is downloaded, unziped and ready to be used. But not so quick.&lt;/p&gt;

&lt;p&gt;As you probably remember, &lt;strong&gt;Java 9&lt;/strong&gt; gave us module system and &lt;strong&gt;JDK&lt;/strong&gt; itself is also modularized. That means we don’t have to bring whole &lt;strong&gt;JDK&lt;/strong&gt; to production but we could build our own striped version specifically for our app’s needs. There is jlink tool provided for that. Just take a look how it is used in the build process. The modules listed there should be enough to run a typical &lt;strong&gt;Spring Boot&lt;/strong&gt; application. In my production case I had to put java.scripting, jdk.scripting.nashorn to the list as well.&lt;/p&gt;

&lt;p&gt;On the second stage it copies results from previous one, defines some environment variables, exposes port, copy launch.sh and app’s artifact. Not a rocket science at all.&lt;/p&gt;

&lt;p&gt;And here is launch.sh script I’ve just mentioned:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;That is just a small helper to ensure that there are all important things provided, etc. But, sure, it is optional.&lt;/p&gt;

&lt;p&gt;And that should be enough to put your app to the production. Please, put some comments down if you have some thoughts how to make it better!&lt;/p&gt;


</description>
      <category>springboot</category>
      <category>java</category>
      <category>docker</category>
      <category>devops</category>
    </item>
    <item>
      <title>Java 10 — migration story</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Mon, 26 Mar 2018 21:56:57 +0000</pubDate>
      <link>https://dev.to/gimlet2/java-10--migration-story-41k7</link>
      <guid>https://dev.to/gimlet2/java-10--migration-story-41k7</guid>
      <description>&lt;p&gt;As you probably know &lt;a href="http://jdk.java.net/10/" rel="noopener noreferrer"&gt;&lt;strong&gt;Java 10&lt;/strong&gt;&lt;/a&gt; was recently released. Not so many new features. At least for &lt;a href="http://kotlinlang.org" rel="noopener noreferrer"&gt;&lt;strong&gt;Kotlin&lt;/strong&gt;&lt;/a&gt; developers… But there are &lt;a href="http://www.oracle.com/technetwork/java/javase/10-relnote-issues-4108729.html" rel="noopener noreferrer"&gt;several improvements&lt;/a&gt; to &lt;strong&gt;JVM&lt;/strong&gt; itself. And, I guess, there will be more in upcoming versions. Which we will get twice a year from now! So, I think it is better to take some time and sync your projects to make it easier in future to migrate with the same speed.&lt;/p&gt;

&lt;p&gt;The main project I’m involved into is &lt;strong&gt;SpringBoot&lt;/strong&gt; 1.5.X based service made with &lt;strong&gt;Kotlin&lt;/strong&gt; and it uses &lt;strong&gt;Postgres&lt;/strong&gt; as a data base. At this moment it uses &lt;strong&gt;Java 8&lt;/strong&gt;. Such a great chance to skip &lt;strong&gt;Java 9&lt;/strong&gt; and jump directly to 10! Being inspired by this thought I have opened my laptop.&lt;/p&gt;

&lt;p&gt;I use &lt;a href="http://sdkman.io" rel="noopener noreferrer"&gt;&lt;strong&gt;SDKman&lt;/strong&gt;&lt;/a&gt; to install Java but for &lt;strong&gt;Java 10&lt;/strong&gt; it delivers broken version for some unknown reason. So this time I had to download bundle from the official &lt;a href="http://jdk.java.net/10/" rel="noopener noreferrer"&gt;website&lt;/a&gt; manually.&lt;/p&gt;

&lt;p&gt;The biggest issue is that some libraries are no longer part of &lt;strong&gt;JDK&lt;/strong&gt;. That is good news — it is getting cleaner. But as a result, you need to define additional dependencies for your project. You can also include them with command line parameters since they are actually still in &lt;strong&gt;JDK&lt;/strong&gt; but I think it is better to move them into dependencies because as far as I’ve understood they gonna be removed in future releases completely. In my case it was:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ASQ14w9r73jrD6tHWTt7d-w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ASQ14w9r73jrD6tHWTt7d-w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second issue was &lt;a href="https://docs.gradle.org/current/userguide/jacoco_plugin.html" rel="noopener noreferrer"&gt;&lt;strong&gt;Jacoco Gradle plugin&lt;/strong&gt;&lt;/a&gt;. If you use it to measure the code coverage there is good news— &lt;strong&gt;Jacoco&lt;/strong&gt; itself supports &lt;strong&gt;Java 10&lt;/strong&gt;. But to make &lt;strong&gt;Jacoco Gradle plugin&lt;/strong&gt; work I had to specify the tool version like this in my gradle build file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AnjwwVXG6jfxW7NDI3YtQnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AnjwwVXG6jfxW7NDI3YtQnw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the last part that was broken — &lt;a href="http://site.mockito.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Mockito&lt;/strong&gt;&lt;/a&gt;. That issue could be solved by adding a fresh version of &lt;a href="http://bytebuddy.net/" rel="noopener noreferrer"&gt;&lt;strong&gt;Bytebuddy&lt;/strong&gt;&lt;/a&gt; library like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AVCu3z7x3Lm9b0WKn_czzLw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AVCu3z7x3Lm9b0WKn_czzLw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After these modifications, I was able to build and run my project and all tests were green. Don’t be afraid to migrate! Next step would be to prepare &lt;strong&gt;Dockerbuild&lt;/strong&gt; file. But that is a topic for the next article.&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>springboot</category>
      <category>java</category>
      <category>java10</category>
    </item>
    <item>
      <title>Karma.js, Headless Chrome and Docker</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Sat, 03 Mar 2018 08:50:57 +0000</pubDate>
      <link>https://dev.to/gimlet2/karmajs-headless-chrome-and-docker-1m2l</link>
      <guid>https://dev.to/gimlet2/karmajs-headless-chrome-and-docker-1m2l</guid>
      <description>&lt;p&gt;Today I’ve come back to frontend project I’m involved. I have no idea what have happened while I was away for different things but our &lt;strong&gt;Karma.js&lt;/strong&gt; tests stop working.&lt;/p&gt;

&lt;p&gt;The project is done with &lt;strong&gt;Vue.js&lt;/strong&gt; and it becomes for some reason impossible to pass slots to the components as strings. Well. And there was error message suggesting to use &lt;strong&gt;Puppeteer&lt;/strong&gt; instead.&lt;/p&gt;

&lt;p&gt;And here is a short snippet to how actually do that. Quick notice, I run my tests inside Docker container…&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;remove &lt;strong&gt;Phantomjs&lt;/strong&gt; from your &lt;strong&gt;package.json&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;add dependencies to &lt;strong&gt;puppeteer&lt;/strong&gt; and &lt;strong&gt;karma-chrome-launcher&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;update &lt;strong&gt;karma.conf.js&lt;/strong&gt; according to the snippet below&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;also &lt;strong&gt;Chrome&lt;/strong&gt; requires some system libraries and doesn’t work on default &lt;strong&gt;nodejs&lt;/strong&gt;  &lt;strong&gt;Docker&lt;/strong&gt; image. So, I’ve found &lt;code&gt;geekykaran/headless-chrome-node-docker&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And after all that changes my tests are green again!&lt;/p&gt;

</description>
      <category>phantomjs</category>
      <category>javascript</category>
      <category>vue</category>
      <category>testing</category>
    </item>
    <item>
      <title>Kotlin for Pebble</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Fri, 16 Feb 2018 09:59:15 +0000</pubDate>
      <link>https://dev.to/gimlet2/kotlin-for-pebble-1idl</link>
      <guid>https://dev.to/gimlet2/kotlin-for-pebble-1idl</guid>
      <description>&lt;p&gt;The best Smartwatchs are &lt;a href="https://www.pebble.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Pebble&lt;/strong&gt;&lt;/a&gt;. Even taking into account that the company producing them was sold, and there will be no more new devices it is still best smartwatchs you can buy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AKB-De6zghaKa6iaQcgmVkA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AKB-De6zghaKa6iaQcgmVkA.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is specially true if you are a software developer or just love to play with code. &lt;strong&gt;Pebbles&lt;/strong&gt; provides you with powerful but simple &lt;strong&gt;SDK&lt;/strong&gt; for &lt;strong&gt;C&lt;/strong&gt; and &lt;strong&gt;Javascript&lt;/strong&gt;. And cool web IDE —&lt;a href="https://cloudpebble.net/" rel="noopener noreferrer"&gt;&lt;strong&gt; CloudPebble&lt;/strong&gt;&lt;/a&gt;. As a result, it is super easy to develop apps and watchfaces.&lt;/p&gt;

&lt;p&gt;But you probably know I am a big fan of &lt;a href="http://kotlinlang.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Kotlin&lt;/strong&gt;&lt;/a&gt;, so &lt;strong&gt;C&lt;/strong&gt; and &lt;strong&gt;Javascript&lt;/strong&gt; were not definitely enough for me! Since &lt;strong&gt;Kotlin-native&lt;/strong&gt; at this moment doesn’t support the platforms are used in &lt;strong&gt;Pebble&lt;/strong&gt; I’ve decided to go with &lt;strong&gt;KotlinJS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KotlinJS&lt;/strong&gt; is a way to transpile &lt;strong&gt;Kotlin&lt;/strong&gt; code to &lt;strong&gt;Javascript&lt;/strong&gt;. As a starting point, I took this repo — &lt;a href="https://github.com/pebble/pebblejs" rel="noopener noreferrer"&gt;https://github.com/pebble/pebblejs&lt;/a&gt;. This repo provides you the way to develop apps for &lt;strong&gt;Pebble&lt;/strong&gt; in &lt;strong&gt;Javascript&lt;/strong&gt; locally.&lt;/p&gt;

&lt;p&gt;First, you need to follow this &lt;a href="https://developer.pebble.com/sdk/install/" rel="noopener noreferrer"&gt;https://developer.pebble.com/sdk/install/&lt;/a&gt; instructions to setup &lt;strong&gt;PebbleSDK&lt;/strong&gt;. Also, you need to setup Kotlin command line tools. I am using &lt;a href="http://sdkman.io/" rel="noopener noreferrer"&gt;&lt;strong&gt;SDKMan&lt;/strong&gt;&lt;/a&gt; for that. As soon as you have all that you are good to go.&lt;/p&gt;

&lt;p&gt;So, I’ve made a fork of &lt;strong&gt;pebblejs&lt;/strong&gt; repo — &lt;a href="https://github.com/gimlet2/pebblekt" rel="noopener noreferrer"&gt;https://github.com/gimlet2/pebblekt&lt;/a&gt;. The first thing to check here is &lt;strong&gt;build.sh&lt;/strong&gt; script. It has three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build Kotlin code to Javascript with &lt;strong&gt;kotlinc-js&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Remove unused code with help of &lt;strong&gt;kotlin-dce-js&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;And &lt;strong&gt;pebble build&lt;/strong&gt; to actually produce artifact for Pebble&lt;/li&gt;
&lt;li&gt;The last step which is not the part of the script — installation — you can use different options of &lt;strong&gt;pebble install&lt;/strong&gt;  command.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The last thing to focus on — &lt;strong&gt; src&lt;/strong&gt;  folder:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;in &lt;strong&gt;js&lt;/strong&gt; folder you will find original &lt;strong&gt;PebbleJS&lt;/strong&gt; SDK. Also a result of &lt;strong&gt;Kotlin&lt;/strong&gt; transpiling is also could be found here in &lt;strong&gt;app.js&lt;/strong&gt;  file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;KotlinJs&lt;/strong&gt; standard library could be found in &lt;strong&gt;kotlinjs&lt;/strong&gt; folder. It is huge but &lt;strong&gt;kotlin-dce-js&lt;/strong&gt; is there to fix this.&lt;/li&gt;
&lt;li&gt;And finally, &lt;strong&gt;kotlin&lt;/strong&gt; folder contains bindings to js code(for example &lt;strong&gt;ui.kt&lt;/strong&gt; ), some helper functions in &lt;strong&gt;pebble.kt&lt;/strong&gt; and &lt;strong&gt;app.kt&lt;/strong&gt;  — the application code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you build and run this code you’ll get typical &lt;em&gt;Hello world&lt;/em&gt; app.&lt;/p&gt;

&lt;p&gt;With this project I want to try to expand &lt;strong&gt;Kotlin&lt;/strong&gt; to a new platform. Worth to mention the latest release of &lt;strong&gt;Kotlin-native&lt;/strong&gt; (&lt;a href="https://github.com/JetBrains/kotlin-native/releases/tag/v0.6" rel="noopener noreferrer"&gt;0.6.0&lt;/a&gt;) with a support of &lt;strong&gt;STM32&lt;/strong&gt; chips. But that is a story for another post.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>pebble</category>
      <category>smartwatch</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>Prometheus, Python, Flask</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Fri, 02 Feb 2018 16:43:38 +0000</pubDate>
      <link>https://dev.to/gimlet2/prometheus-python-flask-4ik0</link>
      <guid>https://dev.to/gimlet2/prometheus-python-flask-4ik0</guid>
      <description>&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt; based apps are significant part of the ecosystem in our company. In the era of microservices there is really no difference which technology is in use under the hood. But each service should provide its own API and the way to monitor its state.&lt;/p&gt;

&lt;p&gt;In our setup we use &lt;a href="https://prometheus.io/"&gt;&lt;strong&gt;Prometheus&lt;/strong&gt;&lt;/a&gt; to aggregate metrics from all our services. And it works fine. Especially with our &lt;strong&gt;JVM&lt;/strong&gt; apps. But that was not a case for all out Pythons till today.&lt;/p&gt;

&lt;p&gt;As a historical tradition our Pythons apps are mostly done with &lt;a href="http://flask.pocoo.org/"&gt;&lt;strong&gt;Flask&lt;/strong&gt;&lt;/a&gt;. And it is a nice framework. In some cases it is also wrapped with &lt;a href="http://gunicorn.org/"&gt;&lt;strong&gt;Gunicorn&lt;/strong&gt;&lt;/a&gt;. And here is a tutorial how to make it work with Prometheus:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the dependency to your project &lt;strong&gt;setup.py&lt;/strong&gt; to prometheus_client==0.1.1&lt;/li&gt;
&lt;li&gt;Inside your application define some metrics you want to collect, for example: FLASK_REQUEST_LATENCY = Histogram(__name__.replace(‘.’, ‘_’) + ‘_request_latency_seconds’, ‘Flask Request Latency’) .&lt;/li&gt;
&lt;li&gt;Annotate a method you want to measure with @FLASK_REQUEST_LATENCY.time()&lt;/li&gt;
&lt;li&gt;Add endpoint to expose the statistics:&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And that’s it! If your app is just plain Flask without Gunicorn. To make it work in multiprocessor scenario you need to make several additional steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create config for Gunicorn:&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;&lt;p&gt;This config can be provided to &lt;strong&gt;gunicorn&lt;/strong&gt; cli with &lt;strong&gt;-c&lt;/strong&gt;  flag.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add Environment variable prometheus_multiproc_dir that should point to a directory where Prometheus can temporarily store the metrics. If you use &lt;strong&gt;Kubernetes&lt;/strong&gt; update the deployment descriptor to mount &lt;strong&gt;Volume&lt;/strong&gt; with &lt;strong&gt;emptyDir&lt;/strong&gt;  type.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And the last thing to do — update code for your /stats endpoint like this:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;I hope this short guide can be useful and will help you to make your apps measurable and system more reliable.&lt;/p&gt;

</description>
      <category>python</category>
      <category>kubernetes</category>
      <category>gunicorn</category>
      <category>flask</category>
    </item>
    <item>
      <title>Setup Go project - for JVM developers</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Sat, 06 Jan 2018 00:36:59 +0000</pubDate>
      <link>https://dev.to/gimlet2/setup-go-project---for-jvm-developers-1915</link>
      <guid>https://dev.to/gimlet2/setup-go-project---for-jvm-developers-1915</guid>
      <description>

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o2JUdUZz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A74h9ZBGFc-INjZrF8ZBhFg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o2JUdUZz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A74h9ZBGFc-INjZrF8ZBhFg.png" alt=""&gt;&lt;/a&gt;image from &lt;a href="https://github.com/zxh0/jvm.go"&gt;&lt;/a&gt;&lt;a href="https://github.com/zxh0/jvm.go"&gt;https://github.com/zxh0/jvm.go&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have been doing development for &lt;strong&gt;JVM&lt;/strong&gt; platform for quite some time already. It was &lt;strong&gt;Java&lt;/strong&gt; back in time, now it is &lt;strong&gt;Kotlin&lt;/strong&gt;. And everything seems logical here — here is your &lt;strong&gt;Maven&lt;/strong&gt; , &lt;strong&gt;Gradle&lt;/strong&gt; or whatever project description with versioned dependencies, when you do build — the artifact is right here. It gives you a sense of workspace. It is easy to develop multiple projects in parallel — they all are isolated from each other.&lt;/p&gt;

&lt;p&gt;But then the new player comes in that perfect world —  &lt;strong&gt;Go&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;$GOROOT&lt;/strong&gt;? &lt;strong&gt;$GOPATH&lt;/strong&gt;? WTF? Where are project’s dependencies? Is there something like versions? And where are my binaries?!&lt;/p&gt;

&lt;p&gt;I believe that such design of the ecosystem has some rational core and reasoning. But from my(probably not just my) experience it looks like completely parallel universe.&lt;/p&gt;

&lt;p&gt;To deal with it my first approach was to replicate expected &lt;strong&gt;$GOPATH&lt;/strong&gt; folders structure in the project directory —  &lt;strong&gt;bin&lt;/strong&gt; , &lt;strong&gt;src&lt;/strong&gt; and &lt;strong&gt;pkg&lt;/strong&gt;. Then create correct import path inside &lt;strong&gt;src&lt;/strong&gt; folder — like &lt;strong&gt;github.com/gimlet2/&amp;lt;someproject&amp;gt;&lt;/strong&gt; and checkout project itself there. After this manipulations updating of &lt;strong&gt;$GOPATH&lt;/strong&gt; environment variable to point to the project directory. Well, too complicated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oGdZ0T9H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/250/1%2AiEQB41x__t5yNiNAQVAieA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oGdZ0T9H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/250/1%2AiEQB41x__t5yNiNAQVAieA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To improve it a little bit I’ve decided to use dep package manager. And it became better. Now for each project, I was able to provide a list of dependencies with exact versions. Maybe that isn’t really the &lt;strong&gt;Go&lt;/strong&gt; way, but I like it.&lt;/p&gt;

&lt;p&gt;But still, it was far from ideal. Maybe virtual environment can be helpful here? It is widely used in Python to fix the similar issue. And the first thing I’ve found on &lt;strong&gt;Github&lt;/strong&gt; was &lt;a href="https://github.com/crsmithdev/goenv"&gt;goenv&lt;/a&gt;. This project isn’t under active development but it does the job.&lt;/p&gt;

&lt;p&gt;It is pretty easy to use:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install it go get github.com/crsmithdev/goenv&lt;/li&gt;
&lt;li&gt;checkout your project&lt;/li&gt;
&lt;li&gt;then, in your project folder do goenv init github.com/me/myproject&lt;/li&gt;
&lt;li&gt;active virtual environment . goenv/activate&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cool, it works! But &lt;strong&gt;dep&lt;/strong&gt; is an issue now. It verifies that your project is located inside appropriate &lt;strong&gt;$GOPATH&lt;/strong&gt;. And &lt;strong&gt;goenv&lt;/strong&gt; creates virtual &lt;strong&gt;$GOPATH&lt;/strong&gt; in &lt;strong&gt;~/.goenv/&amp;lt;project name&amp;gt;&lt;/strong&gt;. Inside this folder, it also creates &lt;strong&gt;bin&lt;/strong&gt; , &lt;strong&gt;pkg&lt;/strong&gt; and src folders and folders structure that you’ve specified with goenv init command. Almost the same steps I was doing manually before. And it makes a symlink to your actual project folder. So, I’ve improved &lt;strong&gt;goenv&lt;/strong&gt; a little bit to cd into this virtual project folder on activating of the environment.&lt;/p&gt;

&lt;p&gt;Now you can run dep ensure right away or start your code editor(personally I use &lt;a href="https://code.visualstudio.com/"&gt;Visual Studio Code&lt;/a&gt; for Go development), work with git, etc. I’ve provided this change as a pull request to the original project. But you can also install it from my fork — go get &lt;a href="https://github.com/gimlet2/goenv"&gt;github.com/gimlet2/goenv&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Maybe that setup isn’t the best but it works for me. At least now I know what is where and can setup new project in one command.&lt;/p&gt;


</description>
      <category>softwaredevelopment</category>
      <category>tools</category>
      <category>go</category>
      <category>programming</category>
    </item>
    <item>
      <title>8 minutes of fame — fzf talk</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Wed, 15 Nov 2017 18:36:19 +0000</pubDate>
      <link>https://dev.to/gimlet2/8-minutes-of-fame--fzf-talk-2bce</link>
      <guid>https://dev.to/gimlet2/8-minutes-of-fame--fzf-talk-2bce</guid>
      <description>

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7uLy-38Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2ABY3Uq4WgzyvruHuCl4o_Hw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7uLy-38Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2ABY3Uq4WgzyvruHuCl4o_Hw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today we’ve started a new thing in our company(just in case you wondering it’s Outfittery Gmbh) — “8 minutes of fame”. This thing has one idea behind — small lightning talks 8 minutes each. It expected to be periodical. For now, we’ve agreed to do it once a month but will see how it’ll go. Each session contains 4 slots. No slides allowed * — show code or live demo, or you could just talk for 8 minutes(* — on some exceptional topics it’s ok to have).&lt;/p&gt;

&lt;p&gt;But here I want to summarize the talk I gave —  &lt;strong&gt;How to fzf.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First of all, what is &lt;a href="https://github.com/junegunn/fzf"&gt;&lt;strong&gt;fzf&lt;/strong&gt;&lt;/a&gt;? That is command line tool that should simplify your daily life with power of fuzzy finding. That actually the way how it’s pronounced — FuzzyFinder. It is written in &lt;strong&gt;Go&lt;/strong&gt; lang and could be easily found on &lt;strong&gt;Github&lt;/strong&gt;. The recommended way to &lt;strong&gt;install&lt;/strong&gt; it — checkout the repo to ~/.fzf folder and run install script. It will ask you several questions and you are ready to go!(don’t forget to apply shell config modifications with source command)&lt;/p&gt;

&lt;p&gt;What is so cool about it? Well, it’s doing one thing but doing it well. As each Unix tools should. It takes a list of lines to STD/IN and produces a filtered list of lines to STD/OUT. But magic happens in the middle =). Under the hood it supports several filter options: default one — fuzzy finding — you type and it tries to understand what you actually mean, strict match, the strict match from the beginning of the line and strict match on the end of the line. Forgot to mention, it is also possible to filter something out — just prepend your query with !(bang).&lt;/p&gt;

&lt;p&gt;After you’ve found what you need(with a query or by manual navigation with cursor buttons) just hit enter or even just pick what you need my mouse click.With &lt;strong&gt;-m&lt;/strong&gt; flag passed it’s allowed to pick several items from the list(just use Tab or Shift+Tab).&lt;/p&gt;

&lt;p&gt;Just with this functionality, this tool becomes useful for integration to you interactive scripts. But it provides more — bunch of cool keybindings(and you can extend it). Here is my favorite:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ctrl+R — fuzzy search on your terminal history;&lt;/li&gt;
&lt;li&gt;Ctrl+T — find files in current directory and deep inside and return the result to the command line. Super useful when you type some command(let’s say less) and then you hit Ctrl+T and pick file you want;&lt;/li&gt;
&lt;li&gt;Alt+C — cd to selected directory;&lt;/li&gt;
&lt;li&gt;ssh ** and then Tab — selecting a host from your hosts file or ssh config;&lt;/li&gt;
&lt;li&gt;kill -9 and then Tab — selecting process to kill;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And there is more, those are just my top list I use daily.&lt;br&gt;&lt;br&gt;
There are several more things worse to mention: Vim integration and new feature — preview. But, I hope, if you haven’t tried(or maybe you are using fzf already for many years…), just check it. More details you always can find in README file. And I’m going to prepare my next talk for “8 minutes of fame”.&lt;/p&gt;


</description>
      <category>terminal</category>
      <category>commandline</category>
      <category>fzf</category>
    </item>
    <item>
      <title>Summarize on “Spring Microservices” book by Rajesh RV</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Sat, 30 Sep 2017 12:33:11 +0000</pubDate>
      <link>https://dev.to/gimlet2/summarize-on-spring-microservices-book-by-rajesh-rv-14o6</link>
      <guid>https://dev.to/gimlet2/summarize-on-spring-microservices-book-by-rajesh-rv-14o6</guid>
      <description>

&lt;p&gt;Recently I’ve read &lt;strong&gt;“Spring Microservices”&lt;/strong&gt; book by &lt;strong&gt;Rajesh RV&lt;/strong&gt; and here I want to try to summarize it. The book was published in June 2016. But, it seems, it is still relevant.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rJtHz7Da--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/500/1%2AsxES4bQ1vbo2PoXbTjJdVA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rJtHz7Da--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/500/1%2AsxES4bQ1vbo2PoXbTjJdVA.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Microservices isn’t just for developers pleasure but also business demand.
&lt;/h4&gt;

&lt;p&gt;Yes, sure, it’s extremely interesting and fun to plan and implement scalable and distributed systems but developers should always keep in mind why we are doing that — to evaluate faster on business processes, reduce the cost of the experiment.&lt;/p&gt;

&lt;h4&gt;
  
  
  Meaningful health check is important
&lt;/h4&gt;

&lt;p&gt;Self-healing is significant for microservice architecture. And to provide it your service has to report its health state accurate. For example, your service is deployed in &lt;strong&gt;Kubernetes&lt;/strong&gt; cluster and exposes &lt;strong&gt;/health&lt;/strong&gt; endpoint. Then it will be possible to restart it in case of failure and reroute traffic to a health node instead. Also, it helps you to understand your app better, know all significant dependencies and requirements.&lt;/p&gt;

&lt;h4&gt;
  
  
  Spring Cloud is a good choice for microservices
&lt;/h4&gt;

&lt;p&gt;…if you do not afraid of such vendor-lock. In case if your platform is 100% based on Spring stack it seems pretty logical to try to solve microservices challenges with help of &lt;strong&gt;Spring Cloud&lt;/strong&gt;. Bunch of cool project from &lt;strong&gt;Spring Cloud Config&lt;/strong&gt; till &lt;strong&gt;Spring Cloud Streams&lt;/strong&gt; helps you to build reliable and manageable system. But if you run your services for example on top of &lt;strong&gt;Kubernetes&lt;/strong&gt; you will get alternative solutions for those issues for free(like service discovery, load balancing, etc.).&lt;/p&gt;

&lt;h4&gt;
  
  
  Distributed tracing brings transparency into the system
&lt;/h4&gt;

&lt;p&gt;On that field Spring provides us &lt;strong&gt;Spring Cloud Sleuth&lt;/strong&gt; solution. It works on top of &lt;strong&gt;Zipkin&lt;/strong&gt; , Cloudera or Dapper. As result of integration, you will be able to add to your log messages what’s called &lt;strong&gt;Trace-Id&lt;/strong&gt; and Span-Id, so you can track request chain across entire system for example in &lt;strong&gt;Kibana&lt;/strong&gt;. Super useful for debugging, dependency analysis, etc.&lt;/p&gt;

&lt;h4&gt;
  
  
  Autoscaling
&lt;/h4&gt;

&lt;p&gt;…isn’t trivial process. Beside of technical support of autoscaling from your platform(for example, Kubernetes has it but limited, but there are some third-party extensions to improve it), you really need to think about scaling policies, pay attention what limits your app performance.&lt;/p&gt;

&lt;p&gt;Of course, there are much more useful tips in this book. Here is only some point I focus my attention on. In total — it worth to spend some time and read.&lt;/p&gt;


</description>
      <category>kubernetes</category>
      <category>microservices</category>
      <category>springcloud</category>
      <category>books</category>
    </item>
    <item>
      <title>Sentri.io — errors handling</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Sat, 23 Sep 2017 01:49:47 +0000</pubDate>
      <link>https://dev.to/gimlet2/sentriio--errors-handling-536p</link>
      <guid>https://dev.to/gimlet2/sentriio--errors-handling-536p</guid>
      <description>

&lt;p&gt;Today I want to talk about one service I’ve discovered for myself last week. As you probably already got from article title it is &lt;a href="https://sentry.io/"&gt;Sentry.io&lt;/a&gt;. This open source project helps you to aggregate and monitor information regarding errors happening in your application. Beside opensource version, there is also hosted &lt;a href="https://sentry.io/pricing/"&gt;paid&lt;/a&gt;(with free Hobbyist plan) version which supposes to be the same.&lt;/p&gt;

&lt;p&gt;This service provides wide support for different programming languages like Java, C#, Elixir, Go, Javascript, Node, Perl, PHP, Python, etc. The integration process is super easy — you just need to add proper dependency into your project and provide a little bit of &lt;a href="https://docs.sentry.io/clients/java/config/"&gt;configuration&lt;/a&gt;(at least access token), and you are ready to go.&lt;/p&gt;

&lt;p&gt;In my case, it was a &lt;strong&gt;Spring-Boot&lt;/strong&gt; application with &lt;strong&gt;logback&lt;/strong&gt; logging framework. Both those technologies are supported by Sentry.io. So, I’ve placed &lt;strong&gt;io.sentry:sentry-spring&lt;/strong&gt; and &lt;strong&gt;io.sentry:sentry-logback&lt;/strong&gt; libraries into projects &lt;strong&gt;Gradle&lt;/strong&gt; script. Then I’ve created a new project inside Sentry’s dashboard and generated a token for it. Next step — configuration inside the project. And that is something I don’t like about all that story. Maybe there is some way around but I can’t find it — so, I had to duplicate configuration twice — for logback and for spring-boot respectively. I’ve added &lt;strong&gt;sentry.properties&lt;/strong&gt; file in project’s resource folder with &lt;strong&gt;dsn&lt;/strong&gt; key inside and &lt;strong&gt;sentry.dsn&lt;/strong&gt; key to my &lt;strong&gt;application.yaml&lt;/strong&gt;. Also, the configuration of logback appenders was updated with the following block:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;And as a final step additional beans for Spring to handle unhandled exceptions and provide additional request context(yes, a little bit of  &lt;strong&gt;Kotlin&lt;/strong&gt; ):&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;That’s it.&lt;/p&gt;

&lt;p&gt;But there is much more than just aggregation of errors. Sentry provides useful report channels integrations. For example, it can send notifications by &lt;strong&gt;email&lt;/strong&gt; or to S &lt;strong&gt;lack&lt;/strong&gt; when there is a new type of error. Or notify you if same error happened more then 100 times per hour. All those rules are extremely flexible and can be configured with Sentry’s dashboard.&lt;/p&gt;

&lt;p&gt;And there is integration with popular issue trackers like &lt;strong&gt;Jira&lt;/strong&gt;. So, it will create a new bug ticket for each new error with stacktrace and all context it has. That should make it easier to fix them.&lt;/p&gt;

&lt;p&gt;So far looks good.&lt;/p&gt;


</description>
      <category>errors</category>
      <category>springboot</category>
      <category>sentry</category>
    </item>
    <item>
      <title>Kafka usage — tips&amp;hints</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Sun, 13 Aug 2017 21:30:42 +0000</pubDate>
      <link>https://dev.to/gimlet2/kafka-usage--tipshints-49g0</link>
      <guid>https://dev.to/gimlet2/kafka-usage--tipshints-49g0</guid>
      <description>

&lt;p&gt;Today we will talk about &lt;a href="https://kafka.apache.org"&gt;Apache Kafka&lt;/a&gt;. As you probably already know, Kafka is “a distributed streaming platform”, so it could be used as Queue, Message Bus, etc.&lt;/p&gt;

&lt;p&gt;But this story isn’t about Kafka it self. It is about issues I faced recently developing one Kafka based service. Small application consuming messages from defined topic and validating them according to the schema. Nothing like rocket science. But.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Upfront check version of your Kafka server — even minor version difference could break API. Like server version 0.10.0.1 isn’t compatible with client 0.10.1.1. Just pay attention.&lt;/li&gt;
&lt;li&gt;Check which compression mechanism is used on your Kafka server. &lt;a href="https://www.gnu.org/software/gzip/"&gt;GZip&lt;/a&gt; and &lt;a href="https://google.github.io/snappy/"&gt;Snappy&lt;/a&gt; are supported. In my case it was Snappy, and you know what? It requires &lt;a href="https://www.gnu.org/software/libc/"&gt;glibc&lt;/a&gt;. And my base docker image was Alpine. And Alpine does not have support of glibc. So, choose the right base image.&lt;/li&gt;
&lt;li&gt;If you use Kafka Streams API and want to split one stream into two based on some predicate your could pass this predicate to &lt;code&gt;_branch_&lt;/code&gt; method along with predicate that always returns true — some sort of _everithingElsePredicate(_Predicate { _, _ -&amp;gt; true }).&lt;/li&gt;
&lt;li&gt;kafka-console-consumer and kafka-console-producer — your best friends to debug your Kafka app.&lt;/li&gt;
&lt;li&gt;If you are going to scale you app to process some topic in parallel way don’t forget to increase number of partitions on that topic. But keep in mind that it is only possible to increase number of partitions but there is no way back.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That’s all I have in mind to mention.&lt;/p&gt;


</description>
      <category>bigdata</category>
      <category>apachekafka</category>
      <category>tipsandtricks</category>
      <category>kafka</category>
    </item>
    <item>
      <title>Code sharing between Kotlin and Kotlin-Native</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Thu, 20 Jul 2017 22:40:39 +0000</pubDate>
      <link>https://dev.to/gimlet2/code-sharing-between-kotlin-and-kotlin-native-4cij</link>
      <guid>https://dev.to/gimlet2/code-sharing-between-kotlin-and-kotlin-native-4cij</guid>
      <description>

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZMl9u8lA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AISVo7EQ7xi5KNd5QrF0xOg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZMl9u8lA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AISVo7EQ7xi5KNd5QrF0xOg.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nowadays when popularity of Kotlin grows faster then ever JetBrains puts a lot of energy to bring us new Kotlin universe — &lt;a href="https://github.com/JetBrains/kotlin-native"&gt;Kotlin-Native&lt;/a&gt;. Kotlin-Native allows us to build native apps. It based on &lt;a href="http://llvm.org/"&gt;LLVM&lt;/a&gt; compiler and supports various of platforms. It still somewhere far from being production ready but we already have the third release — &lt;a href="https://github.com/JetBrains/kotlin-native/releases/tag/v0.3"&gt;version 0.3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have one let’s say pet-project I’ve already &lt;a href="https://dev.to/gimlet2/kottpd--http-server-in-pure-kotlin-3bi7-temp-slug-3595491"&gt;wrote&lt;/a&gt; about — &lt;a href="https://github.com/gimlet2/kottpd"&gt;kottpd&lt;/a&gt;. It is simple HTTP-server written entirely in Kotlin. From this two facts I’ve made obvious decision — I need to try to port my library to Kotlin-Native! But that is not only for fun. There is one dream behind it — to make it possible to build web apps in Kotlin but with possibility to run them with native performance.&lt;/p&gt;

&lt;p&gt;Well, to be honest, it is only an experiment for now. But let’s see where this experiment will lead later.&lt;/p&gt;

&lt;p&gt;As a first step I’ve cut all unimportant parts out — SSL support, files serving, exception handling and even multi-thread support. And it still was able to serve HTTP requests. Great! Let’s move on.&lt;/p&gt;

&lt;p&gt;The second step was a little bit harder. I had to go through all codebase and remove all direct references to JVM classes. In my case it was java.net. &lt;strong&gt;ServerSocket&lt;/strong&gt; , java.net. &lt;strong&gt;Socket&lt;/strong&gt; , java.io. &lt;strong&gt;OutputStream&lt;/strong&gt; , java.io. &lt;strong&gt;OutputStreamWriter&lt;/strong&gt; , java.io. &lt;strong&gt;PrintWriter&lt;/strong&gt; , java.io. &lt;strong&gt;BufferedReader&lt;/strong&gt; , java.io. &lt;strong&gt;InputStream&lt;/strong&gt; , java.io. &lt;strong&gt;InputStreamReader&lt;/strong&gt; , java.io. &lt;strong&gt;IOException&lt;/strong&gt; , java.lang. &lt;strong&gt;System&lt;/strong&gt;. Not that big list.&lt;/p&gt;

&lt;p&gt;Instead of all those classes I’ve introduced corresponding interfaces and exceptions. And that help me to isolate all platform dependent logic from, let’s say, business logic of the library. On that moment I did check how it works once again. And it was fine. Time to move to Kotlin-Native!&lt;/p&gt;

&lt;p&gt;The code was copied to separate folder. And I had no idea what to do next. But, thanks to JetBrains team, we have some examples that come along with Kotlin-Native. For inspiration I choose &lt;a href="https://github.com/JetBrains/kotlin-native/tree/master/samples/socket"&gt;&lt;strong&gt;socket&lt;/strong&gt;&lt;/a&gt; sample. There I took &lt;strong&gt;build.gradle&lt;/strong&gt; file and &lt;strong&gt;sockets.def&lt;/strong&gt; for configuring C interop. On that moment I realized how far Kotlin-Native is from production use right now — there is no IDE support. That remind me old good times at school with Pascal — change code, compile, read error messages, fix code =)! And that what we have now with Kotlin-Native. Most of the time error messages give you enough information to actually get what is wrong.&lt;/p&gt;

&lt;p&gt;Beside pure tooling I’ve faced not so many issues — &lt;strong&gt;fun main(args: Array&amp;lt;String&amp;gt;) &lt;/strong&gt;— must be in a file without package, type conversions from native world and back are two biggest of them.&lt;/p&gt;

&lt;p&gt;But anyway I made it work! In one thread, crashing time to time with segmentation fault but still serving HTTP requests!&lt;/p&gt;

&lt;p&gt;There is more thoughts to improve it — bring all pieces removed due to simplification back, introduce multi-threading and improve build process to make it actually one application with common code base!&lt;/p&gt;

&lt;p&gt;If you interested in this experiment please follow on &lt;a href="https://github.com/gimlet2/kottpd/tree/nativizy"&gt;github&lt;/a&gt;.&lt;/p&gt;


</description>
      <category>kotlinnative</category>
      <category>https</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>Kottpd — HTTP Server in pure Kotlin</title>
      <dc:creator>Andrei</dc:creator>
      <pubDate>Wed, 16 Nov 2016 22:31:51 +0000</pubDate>
      <link>https://dev.to/gimlet2/kottpd--http-server-in-pure-kotlin-k7g</link>
      <guid>https://dev.to/gimlet2/kottpd--http-server-in-pure-kotlin-k7g</guid>
      <description>

&lt;p&gt;In today’s post I would like to talk about one of the projects I’m working on. I define it as light &lt;strong&gt;HTTP framework&lt;/strong&gt; and it is made in pure &lt;a href="http://kotlinlang.org/"&gt;&lt;strong&gt;Kotlin&lt;/strong&gt;&lt;/a&gt;. Based on these two facts I’ve named it &lt;a href="https://github.com/gimlet2/kottpd"&gt;&lt;strong&gt;kottpd&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This project was born during long bus ride. There was no Internet and I decided to write something without external dependencies. What could be better then implementing well-known text-based protocol?!&lt;/p&gt;

&lt;p&gt;Not all pieces were easy to find in the palaces of the mind but in couple of hours first version was ready to serve standard HTTP queries. The design of API was made with inspiration from &lt;strong&gt;Spark-Java&lt;/strong&gt;. So, it looks quite similar.&lt;/p&gt;

&lt;p&gt;What we could find under the hood? First of all it is Cached ThreadsPool. It helps to allocate and reuse threads for each HTTP request. Then in infinite loop the server waits for incoming connections, reads it, tries to match against configured routes and passes to corresponding handler if found. Beside request handlers you could also specify &lt;strong&gt;Before&lt;/strong&gt; and &lt;strong&gt;After&lt;/strong&gt; filters to implement some sort of middleware(for example — login, transactions, etc.).&lt;/p&gt;

&lt;h4&gt;
  
  
  What for is it useful?
&lt;/h4&gt;

&lt;p&gt;Well, it could be used if you want to make a web application, or an &lt;strong&gt;REST API&lt;/strong&gt; , or just to serve a static content(it supports that too!). But you want to do it in a lightweight way. And you like &lt;strong&gt;Kotlin&lt;/strong&gt;! That it is a perfect choice for you. Have I mentioned it supports  &lt;strong&gt;SSL&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;To explain it better let me show you an example that could be easily found in the README file. But first of all you need to add it as a dependency to your project. The library is published into maven central repository, so you should not face any issues with it.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;  &lt;/div&gt;

&lt;p&gt;Here we create an instance of &lt;em&gt;Server&lt;/em&gt; class, define path to the folder with static content we want our server to serve. Then we define several request handlers(yes, you could use regular expressions for that). And then there is a block with filters. They could be global — when there is no specific path defined — and path specific. And of course you could define some exception handlers too. The only thing is left to be done — call &lt;em&gt;start()&lt;/em&gt; method. By default your application will listen on the &lt;strong&gt;port 9000&lt;/strong&gt;. But you could just pass any port value you want as argument to &lt;em&gt;start()&lt;/em&gt; method or define it with server.port system property(&lt;em&gt;-Dserver.port=8080&lt;/em&gt;).&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;I hope you got interested with my project. Please, try to use it in your applications and I will be really happy to see any feedback from you. If you have never used Kotlin before, it is a good moment to start!&lt;/p&gt;

&lt;p&gt;Do Kotlin — do the Web!&lt;/p&gt;


</description>
      <category>kotlin</category>
      <category>https</category>
      <category>java</category>
      <category>restapi</category>
    </item>
  </channel>
</rss>
