<?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 Kobe on Medium]]></title>
        <description><![CDATA[Stories by Kobe on Medium]]></description>
        <link>https://medium.com/@haithai91?source=rss-4294b03fe298------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zm6JcnMd95L2EEPvv7NsLw.jpeg</url>
            <title>Stories by Kobe on Medium</title>
            <link>https://medium.com/@haithai91?source=rss-4294b03fe298------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:31:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@haithai91/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[[Interview Question] What is the difference between Lambdas outside and inside a VPC?]]></title>
            <link>https://haithai91.medium.com/interview-question-what-is-the-difference-between-lambdas-outside-and-inside-a-vpc-da6c92d807c9?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/da6c92d807c9</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[lambda-function]]></category>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Mon, 11 Mar 2024 01:41:03 GMT</pubDate>
            <atom:updated>2024-03-11T01:41:03.399Z</atom:updated>
            <content:encoded><![CDATA[<p>AWS Lambda functions can be executed both within a Virtual Private Cloud (VPC) and outside it. Here are the differences between the two:</p><p><strong>Lambda functions within a VPC:</strong></p><ol><li>Have access to resources within the same VPC, including databases, file systems, and instances which are not publicly accessible.</li><li>Use the security features of your VPC like security groups and network access control lists (NACLs).</li><li>Can access the internet only if your VPC has internet gateway. If not, these functions only have access to resources within the VPC.</li></ol><p><strong>Lambda functions outside a VPC</strong></p><ol><li>Can access the public internet, but they cannot access resources inside your VPC. If your function needs to access both VPC resources and the public internet, you should configure a NAT gateway in your VPC or use VPC endpoints.</li><li>Might offer faster cold start times than those inside the VPC.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da6c92d807c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tell me about your self]]></title>
            <link>https://haithai91.medium.com/tell-me-about-your-self-d834c255321b?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/d834c255321b</guid>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 15:13:02 GMT</pubDate>
            <atom:updated>2023-12-18T03:50:12.938Z</atom:updated>
            <content:encoded><![CDATA[<p>Sample 1</p><p>Good morning/Afternoon.</p><p>Thank you for giving me the opportunity to introduce myself in front of you.</p><p>I am Te, 32 years old.</p><p>Let me tell you guys a little bit about my experience.</p><p>I have around 10 years of experience in the software development area. Currently, I am working on a domain related to the eComerce Platform. I have a team of six engineers who’re working on the current project with multiple roles (Devop, BA, QA, and a technical guy from the client team).</p><p>My skills are good leadership and problem-solving. I have worked on a lot of languages in the past, but with the backend code, I am good with Java and Node.js, and the frontend is ReactJS and Angular. About cloud computing is AWS (devop skills I use Terraform in 2 last projects).</p><p>That’s all about myself.</p><p>Thank you!</p><p>Link refer: <a href="https://www.indiabix.com/hr-interview/tell-me-about-yourself/">https://www.indiabix.com/hr-interview/tell-me-about-yourself/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d834c255321b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to speed up DynamoDB query with low Read Capacity Unit]]></title>
            <link>https://haithai91.medium.com/how-to-speed-up-dynamodb-query-with-low-read-capacity-unit-2b3b6dd75add?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b3b6dd75add</guid>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 15:55:22 GMT</pubDate>
            <atom:updated>2023-06-07T15:55:22.676Z</atom:updated>
            <content:encoded><![CDATA[<p>Example you have a DynamoDB table provisioned with RCU = 1.</p><p>If you have provisioned low read capacity in DynamoDB and want to speed up your queries, there are a few strategies you can consider</p><ol><li>Query Projection: Use query projection to retrieve only the necessary attributes instead of fetching the entire item. By specifying only the required attributes in the ProjectionExpression parameter, you can reduce the amount of data read from the table, thereby decreasing the consumed read capacity.</li><li>Filter Expressions: Optimize your queries by utilizing filter expressions to reduce the number of items returned. Filtering at the database level can help minimize the amount of data transferred to your application, improving query performance.</li><li>Indexes: Create appropriate secondary indexes to support your query patterns. Indexes allow you to query the table using alternate attributes and can significantly enhance query performance. Choose the right type of index (e.g., global secondary index, local secondary index) based on your query requirements.</li><li>Query Design: Design your queries efficiently to minimize the amount of data accessed. Use partition keys and sort keys effectively to distribute the workload evenly across partitions. Avoid “Scan” operations whenever possible, as they read the entire table and consume significant read capacity.</li><li>Caching: Implement a caching layer in front of DynamoDB using services like Amazon ElastiCache or Amazon DAX. Caching frequently accessed data can reduce the number of requests made to DynamoDB, improving query response times.</li><li>Increase Provisioned Capacity: If your workload requires consistently faster query performance, consider increasing the provisioned read capacity for your DynamoDB table. This allows you to handle higher levels of traffic without being throttled and ensures optimal performance for your queries.</li></ol><p>Remember to monitor the performance of your DynamoDB queries using Amazon CloudWatch metrics and DynamoDB’s built-in monitoring capabilities. This will help you identify any bottlenecks or areas for optimization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b3b6dd75add" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DynamoDB — Provisioned RCU = 1 Can Execute with RCU = 10]]></title>
            <link>https://haithai91.medium.com/dynamodb-provisioned-rcu-1-can-execute-with-rcu-10-ebe5c218252b?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebe5c218252b</guid>
            <category><![CDATA[dynamodb]]></category>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 15:52:34 GMT</pubDate>
            <atom:updated>2023-06-07T15:52:34.569Z</atom:updated>
            <content:encoded><![CDATA[<h3>DynamoDB — Provisioned RCU = 1 Can Execute with RCU = 10</h3><p>The reason why when you create a DynamoDB Table and setup the Provisioned mode with RCU = 1 and WRC = 1. However you still can query more than 1 RCU configured</p><p>In Amazon DynamoDB, when you provision a table with a capacity mode of “Provisioned,” you specify the desired read and write capacity units for the table. Each read capacity unit represents one strongly consistent read per second or two eventually consistent reads per second for items up to 4 KB in size. Each write capacity unit represents one write per second for items up to 1 KB in size.</p><p>If you provision your DynamoDB table with 1 read capacity unit and 1 write capacity unit, it means that you have allocated enough capacity to handle 1 read request and 1 write request per second. However, DynamoDB provides burst capacity that allows you to exceed the provisioned capacity temporarily.</p><p>The burst capacity allows you to accommodate traffic spikes or occasional high-demand periods. DynamoDB reserves a certain number of read capacity units and write capacity units for burst capacity, which accumulates over time. This burst capacity can be used to handle traffic that exceeds the provisioned capacity for short durations.</p><p>So, even if you provisioned your table with 1 read capacity unit and 1 write capacity unit, you may still be able to perform more than 1 query per second because of the burst capacity. However, if your workload consistently exceeds the provisioned capacity, DynamoDB might throttle your requests or return an error indicating that you have exceeded your provisioned throughput.</p><p>To handle a sustained higher workload, you would need to increase the provisioned capacity of your DynamoDB table to ensure that it can handle the desired request rate without being throttled.</p><p><strong>The Question do AWS charge for the burst capacity?</strong></p><p>No, AWS does not charge separately for burst capacity in Amazon DynamoDB. The burst capacity is provided as part of the provisioned capacity that you pay for.</p><p>When you provision a DynamoDB table with a capacity mode of “Provisioned,” you pay for the provisioned read capacity units and write capacity units on an hourly basis. The burst capacity is included at no additional cost.</p><p>The burst capacity allows you to handle occasional spikes in traffic without being throttled, but it is not meant to sustain a high workload continuously. If your workload consistently exceeds the provisioned capacity, you may need to consider increasing the provisioned capacity to ensure optimal performance.</p><p>It’s important to note that different AWS services have different pricing models, so it’s always a good practice to review the AWS Pricing documentation specific to the service you are using to understand the associated costs and any potential limitations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebe5c218252b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to switch go dependencies path to local for development]]></title>
            <link>https://haithai91.medium.com/how-to-switch-go-dependencies-path-to-local-for-development-58f4b12afa8a?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/58f4b12afa8a</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[local-development]]></category>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Thu, 29 Dec 2022 17:16:43 GMT</pubDate>
            <atom:updated>2022-12-29T17:16:43.762Z</atom:updated>
            <content:encoded><![CDATA[<p>Step 1: Open the go.mod file</p><pre>module github.com/pub-technology/ProductAPI<br><br>go 1.19<br><br>require (<br> github.com/aws/aws-lambda-go v1.28.0<br> github.com/aws/aws-sdk-go v1.44.126<br> github.com/pub-technology/helper v1.0.0<br>)<br><br>require (<br> github.com/pub-technology/uuid v1.0.0<br>)<br><br>require (<br> ... // indirect<br> ... // indirect<br>)</pre><p>Step 2: Example we want to run helper v1.0.0 locally instead of checkout it from git</p><p>Simple update go.mod with option replace replace checkout from git to the ${path} (Ex: Path of the helper is the same folder )</p><pre>go 1.19<br><br>require (<br> github.com/aws/aws-lambda-go v1.28.0<br> github.com/aws/aws-sdk-go v1.44.126<br>)<br><br>replace github.com/pub-technology/helper =&gt; ./helper</pre><p>Step 3: Re-build your app</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58f4b12afa8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run AWS lambda go with localstack]]></title>
            <link>https://haithai91.medium.com/how-to-run-aws-lambda-go-with-localstack-cd8fb353f193?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd8fb353f193</guid>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 08:26:08 GMT</pubDate>
            <atom:updated>2022-12-14T08:26:08.624Z</atom:updated>
            <content:encoded><![CDATA[<p>As you know when we start the application with localstack the endpoint will be run with <a href="http://localhost:4566/">http://localhost:4566</a> the easy way to we can attach this endpoint to the AWS config is to determine when we can use S3, DynamoDB Client, and SQS services from localstack</p><p>You should define a client and inject the session into services used in the system</p><p>We will have a client that includes all AWS Services (S3, DynamoDB, SQS) Client</p><p>Create AWS Session connect to localstack (endpoint localhost:4566)</p><pre> sess, err := session.NewSessionWithOptions(session.Options{<br>  Profile:           profileName,<br>  SharedConfigState: session.SharedConfigEnable,<br>  Config: aws.Config{<br>   Region:           aws.String(region),<br>   Credentials:      credentials.NewStaticCredentials(&quot;test&quot;, &quot;test&quot;, &quot;&quot;),<br>   S3ForcePathStyle: aws.Bool(true),<br>   Endpoint:         aws.String(&quot;http://localhost:4566&quot;),<br>  },<br> })</pre><p>We will create a client wrapper and include the session for our service</p><pre>package main<br><br>import (<br>    &quot;github.com/aws/aws-sdk-go/aws&quot;<br>    &quot;github.com/aws/aws-sdk-go/aws/session&quot;<br>    &quot;github.com/aws/aws-sdk-go/service/s3&quot;<br>    &quot;github.com/aws/aws-sdk-go/aws/credentials&quot;<br>    ...<br>)<br><br>// ClientWrapper hold all our services <br>type ClientWrapper struct {<br>   DynamoDBClient          dynamodbiface.DynamoDBAPI<br>   SQSClient               sqsiface.SQSAPI<br>   S3Client                s3iface.S3API<br>}<br><br>var (<br> newDynamoDBClient      = dynamodb.New<br> newSQSClient           = sqs.New<br> newS3Client            = s3.New<br>)<br><br>func generateClientWrapper(sess *session.Session) {<br>    var clientWrapper ClientWrapper<br>    clientWrapper.DynamoDBClient = newDynamoDBClient(sess)<br>    clientWrapper.SQSClient = newSQSClient(sess)<br>    clientWrapper.S3Client = newS3Client(sess)<br>    return clientWrapper<br>}<br><br>func iniClient() ClientWrapper {<br>   sess := session.Must(session.NewSession())<br>   return generateClientWrapper(sess)<br>}<br><br>func iniClientWithSession(sess *session.Session) ClientWrapper {<br>   return generateClientWrapper(sess)<br>}</pre><p>Now, we can use our client with the local env now</p><pre>req, _ := clientWrapper.S3Client.GetObjectRequest(&amp;s3.GetObjectInput{<br>        Bucket: aws.String(&quot;mybucket&quot;),<br>        Key:    aws.String(&quot;key&quot;),<br>})</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd8fb353f193" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to optimize disk space Node.js Modules Across Multiple Projects]]></title>
            <link>https://haithai91.medium.com/how-to-optimize-disk-space-node-js-modules-across-multiple-projects-914cd448ded5?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/914cd448ded5</guid>
            <category><![CDATA[disk-space]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[optimize]]></category>
            <category><![CDATA[node-modules]]></category>
            <category><![CDATA[multiple-projects]]></category>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Fri, 25 Nov 2022 04:32:42 GMT</pubDate>
            <atom:updated>2022-11-29T11:59:54.985Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I’ll guide you through a method to optimize disk space with node projects. I got a problem with disk space when working on a lot of NodeJS, and ReactJS repositories ( more than 30 lambdas repos node js, 3 repo ReactJS with ) for each project the node_modules size up to 500MB ) ~ 33 * 500MB ~ 16.5 GB (ಥ﹏ಥ). I tried to review again the repositories and I realized that all repos are using a common library (lodash, webpack, jest, mocha….). I found a lot of different ways on the network and StackOverflow however I got a big deal with pnpn the size of the package optimized up to 70%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vSDtBF-agHng7iA7Rvcpeg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@fennings?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Marc PEZIN</a> on <a href="https://unsplash.com/s/photos/SSD?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>About the <a href="https://pnpm.io/installation">pnpm</a> Fast, disk space efficient package manager:</p><ul><li>Fast. Up to 2x faster than the alternatives (see <a href="https://github.com/pnpm/pnpm#benchmark">benchmark</a>).</li><li>Efficient. Files inside node_modules are linked from a single content-addressable storage.</li><li><a href="https://pnpm.io/workspaces">Great for monorepos</a>.</li><li>Strict. A package can access only dependencies that are specified in its package.json.</li><li>Deterministic. Has a lockfile called pnpm-lock.yaml.</li><li>Works as a Node.js version manager. See <a href="https://pnpm.io/cli/env">pnpm env use</a>.</li><li>Works everywhere. Supports Windows, Linux, and macOS.</li><li>Battle-tested. Used in production by teams of <a href="https://pnpm.io/users">all sizes</a> since 2016.</li><li><a href="https://pnpm.io/feature-comparison">See the full feature comparison with npm and Yarn</a>.</li></ul><h4>Step 1: Install pnpm package (using npm)</h4><p>Refer to the installation: <a href="https://pnpm.io/installation">https://pnpm.io/installation</a></p><pre>(base) haithai@FVFY201CHV2H SafetyCheckManagementUI % npm install -g pnpm<br>/Users/haithai/.nvm/versions/node/v14.9.0/bin/pnpm -&gt; /Users/haithai/.nvm/versions/node/v14.9.0/lib/node_modules/pnpm/bin/pnpm.cjs<br>/Users/haithai/.nvm/versions/node/v14.9.0/bin/pnpx -&gt; /Users/haithai/.nvm/versions/node/v14.9.0/lib/node_modules/pnpm/bin/pnpx.cjs<br>+ pnpm@7.17.0<br>added 1 package in 1.752s</pre><h4>Step 2: Install the dependencies &amp; devDependecies</h4><p>The scenario is Project A vs Project B we have a lot of the same packages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cCUyGdsD3T9vJTphtMqMVQ.png" /></figure><p>Project A</p><pre>Packages are hard linked from the content-addressable store to the virtual store.<br>  Content-addressable store is at: /Users/haithai/Library/pnpm/store/v3<br>  Virtual store is at:             node_modules/.pnpm<br>Progress: resolved 1766, reused 0, downloaded 1766, added 1868, done</pre><p>For project A — this is the first repo we run the install with pnpm so it doesn’t reuse any existing package from the node_modules root</p><p>So we have 1766 packages added with 0 resued package</p><p>Project B</p><pre>Packages are hard linked from the content-addressable store to the virtual store.<br>  Content-addressable store is at: /Users/haithai/Library/pnpm/store/v3<br>  Virtual store is at:             node_modules/.pnpm<br>Progress: resolved 2120, reused 1746, downloaded 374, added 2225, done</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*FB8rSFIDUygBoeuF2FvMzg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=914cd448ded5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[404 not found — Spring boot]]></title>
            <link>https://haithai91.medium.com/404-not-found-spring-boot-201657e15abe?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/201657e15abe</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[404]]></category>
            <category><![CDATA[not-found]]></category>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 13:16:50 GMT</pubDate>
            <atom:updated>2022-11-14T13:16:50.011Z</atom:updated>
            <content:encoded><![CDATA[<h3>404 not found — Spring boot</h3><p>The questions</p><p>Q1: @SpringBootApplication What package is it in?</p><p>Q2: What package is your controller in?</p><p>By default, Spring boot component scanning occurs in the package of your main application class, or sub-packages. com.example.Controller is not a sub-package of com.example.demo</p><p>You could specify the name of the package to scan for components like this:</p><pre>@SpringBootApplication(scanBasePackages = {&quot;com.example.demo&quot;, &quot;com.example.controller&quot;})</pre><p>So now you can define a @RestController in your class below 2 packages com.example.demo &amp; com.example.controller</p><pre>package com.example.controller;<br><br>import lombok.extern.slf4j.Slf4j;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.RequestMapping;<br>import org.springframework.web.bind.annotation.RequestParam;<br>import org.springframework.web.bind.annotation.RestController;<br><br>@Slf4j<br>@RestController<br>@RequestMapping(&quot;api&quot;)<br>public class DemoController {<br><br>    @GetMapping(&quot;/hello&quot;)<br>    public String sayHello(@RequestParam(value = &quot;myName&quot;, defaultValue = &quot;World&quot;) String name) {<br>        return String.format(&quot;Hello %s!&quot;, name);<br>    }<br>}</pre><p>Access your API : <a href="http://localhost:8080/api/hello">http://localhost:8080/api/hello</a></p><pre>Hello World!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=201657e15abe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Find and kill a port was already in use]]></title>
            <link>https://haithai91.medium.com/find-and-kill-a-port-was-already-in-use-11566f9095fa?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/11566f9095fa</guid>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[in-use]]></category>
            <category><![CDATA[kill-processes]]></category>
            <category><![CDATA[stopprocess]]></category>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Mon, 14 Nov 2022 11:43:34 GMT</pubDate>
            <atom:updated>2022-11-14T11:43:34.380Z</atom:updated>
            <content:encoded><![CDATA[<p>Some time when you try to start an application ( server ) and application failed to start with error</p><pre>Server failed to start. Port 8080 was already in use.<br><br>Action:<br><br>Identify and stop the process that&#39;s listening on port 8080<br>configure this application to listen on another port.</pre><p>The problem when your app started with a background processing and when you close the Code Editor , Command line the process still running</p><p>Just simple kill it and restart application</p><pre>sudo lsof -i :&lt;PortNumber&gt;<br><br>kill -9 &lt;PID&gt;</pre><p>Example: sudo lsof -i :8080</p><pre>sudo lsof -i :8080<br><br>COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME<br>java    63207 haithai   56u  IPv6 0xb7a4136880cbaf4f      0t0  TCP *:http-alt (LISTEN)</pre><p>From the command we can see our PORT(8080) running below PID : 63207</p><p>Kill the process with command kill -9 63207</p><pre>kill -9 63207</pre><p>Another way to find the PID with netstat command.</p><pre><br>#8080 - port number needs to be unclocked<br># macOs <br>sudo lsof -i tcp:8080<br># common way <br>netstat -vanp tcp | grep 8080<br>#centOs<br>netstat -vanp --tcp | grep 8080<br><br>#after finding PID number of process<br>#run the following command: <br>kill -9 &lt;PID&gt;<br>#where &lt;PIP&gt; replace with proper PID number</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11566f9095fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Zookeeper & Kafka with Docker and Springboot]]></title>
            <link>https://haithai91.medium.com/zookeeper-kafka-with-docker-b1d4b33c0d5e?source=rss-4294b03fe298------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1d4b33c0d5e</guid>
            <category><![CDATA[manager]]></category>
            <category><![CDATA[zookeeper]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[cluster]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Kobe]]></dc:creator>
            <pubDate>Sun, 13 Nov 2022 04:00:07 GMT</pubDate>
            <atom:updated>2022-11-22T03:16:14.031Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, We will show you how to setup and run the Apache Kafka at local to speed up your development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*ktCPRpqZe1lv7RiLZfdaHA.png" /><figcaption>Zookeeper &amp; Kafka Communication</figcaption></figure><h3>Step 1: Setup Docker</h3><p>docker-compose.yml configuration</p><pre>version: &#39;3&#39;<br><br>services:<br>  zookeeper:<br>    image: confluentinc/cp-zookeeper:latest<br>    environment:<br>      ZOOKEEPER_CLIENT_PORT: 2181<br>      ZOOKEEPER_TICK_TIME: 2000<br>    ports:<br>      - 22181:2181<br>    volumes:<br>      - ./pub-technology/zookeeper/data:/data<br>      - ./pub-technology/zookeeper/datalog:/datalog<br>  <br>  kafka-server-1:<br>    image: confluentinc/cp-kafka:latest<br>    depends_on:<br>      - zookeeper<br>    ports:<br>      - 29092:29092<br>    environment:<br>      KAFKA_BROKER_ID: 1<br>      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181<br>      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-server-1:9092,PLAINTEXT_HOST://localhost:29092<br>      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT<br>      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT<br>      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1<br>    volumes:<br>      - ./pub-technology/kafka1/data:/var/lib/kafka/data<br>  kafka-server-2:<br>    image: confluentinc/cp-kafka:latest<br>    depends_on:<br>      - zookeeper<br>    ports:<br>      - 39092:39092<br>    environment:<br>      KAFKA_BROKER_ID: 2<br>      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181<br>      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-server-2:9092,PLAINTEXT_HOST://localhost:39092<br>      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT<br>      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT<br>      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1<br>    volumes:<br>      - ./pub-technology/kafka2/data:/var/lib/kafka/data<br>  manager:<br>    image: sheepkiller/kafka-manager<br>    ports:<br>      - 9000:9000<br>    environment:<br>      ZK_HOSTS: zookeeper:2181<br>    depends_on:<br>      - zookeeper</pre><p>From the configuration file, we can see that we have a Zookeeper server used to monitor our Kafka. In this setup we will start a Zookeeper server and 2 Kafka nodes and start a Kafka manager support for our demonstrate</p><ul><li>so in <em>docker-compose.yml</em> file we have 4 services, namely <em>zookeeper</em> and kafka-server-1, kafka-server-2, manager.</li><li>Make the zookepper server always starts before 2 Kafka servers, Kafka manager triggered start or stop. So in the config of the we have a setup depends_on to this dependency.</li><li>Zookeeper server is listening on the port 2181 to manage our Kafka servers. We defined within the same container setup and for any client running on the host will be run on the port 22181 so in the config of the zookeeper, we will expose on the port <em>22181:2181</em></li><li>With 2 nodes of Kafka servers we will expose the host application with port 29092 &amp; 39092. However our Kafka is actually advertised on the port 9092 configured in the environment <strong><em>KAFKA_ADVERTISED_LISTENERS</em></strong></li><li>service names and KAFKA_BROKER_ID are unique across the services.</li><li>The Kafka manager run on port 9000</li></ul><h3>Step 2: Start application</h3><p>Start our containers using the <a href="https://docs.docker.com/compose/reference/"><em>docker-compose</em></a> command<em>docker-compose up -d</em></p><pre>docker-compose up -d<br><br>Creating network &quot;hello-kafka-server_default&quot; with the default driver<br>Creating hello-kafka-server_zookeeper_1 ... done<br>Creating hello-kafka-server_kafka-server-1_1 ... done<br>Creating hello-kafka-server_kafka-server-2_1 ... done<br>Creating hello-kafka-server_manager_1... done</pre><p>Make sure all services were run successfully and verify all services are listening on the exactly port in the configuration.</p><h4>Use <a href="https://linux.die.net/man/1/nc">netcat</a> command to make a connection to a port</h4><ul><li>Zookeeper ( port 22181 )</li><li>Kafka Node #1 ( port 29092 )</li><li>Kafka Node #2 ( port 39092 )</li><li>Kafka Manager ( port 9000 )</li></ul><pre>(base) haithai@FVFV2H hello-kafka-server % nc -z localhost 22181<br>Connection to localhost port 22181 [tcp/*] succeeded!<br>(base) haithai@FVFV2H hello-kafka-server % nc -z localhost 29092     <br>Connection to localhost port 29092 [tcp/*] succeeded!<br>(base) haithai@FVFV2H hello-kafka-server % nc -z localhost 39092<br>Connection to localhost port 39092 [tcp/*] succeeded!<br>(base) haithai@FVFV2H hello-kafka-server % nc -z localhost 9000 <br>Connection to localhost port 9000 [tcp/cslistener] succeeded!</pre><p>Use docker compose command to grep the logs of our services make sure the service is active and don’t have any exception when it started.</p><pre>docker-compose logs zookeeper | grep -i started<br><br>zookeeper_1       | [2022-11-12 10:24:47,459] INFO Started o.e.j.s.ServletContextHandler@7eecb5b8{/,null,AVAILABLE} (org.eclipse.jetty.server.handler.ContextHandler)<br>zookeeper_1       | [2022-11-12 10:24:47,582] INFO Started ServerConnector@5b247367{HTTP/1.1, (http/1.1)}{0.0.0.0:8080} (org.eclipse.jetty.server.AbstractConnector)<br>zookeeper_1       | [2022-11-12 10:24:47,583] INFO Started @5327ms (org.eclipse.jetty.server.Server)<br>zookeeper_1       | [2022-11-12 10:24:47,586] INFO Started AdminServer on address 0.0.0.0, port 8080 and command URL /commands (org.apache.zookeeper.server.admin.JettyAdminServer)<br>zookeeper_1       | [2022-11-12 10:24:47,785] INFO PrepRequestProcessor (sid:0) started, reconfigEnabled=false (org.apache.zookeeper.server.PrepRequestProcessor)</pre><pre>docker-compose logs kafka-server-1 | grep -i started<br><br>kafka-server-1_1  | [2022-11-12 10:24:56,806] INFO [KafkaServer id=1] started (kafka.server.KafkaServer)</pre><h3>Step 3: CMAK is a tool for managing Apache Kafka clusters</h3><p>Access the host <a href="http://localhost:9000/">http://localhost:9000/</a> to open the Kafka Cluster Manager and you can easy to create a new cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*kDQGJRzZdSu_iNABRxQF3A.gif" /></figure><p>From the last image you can see your cluster have 2 Kafka servers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KJE5q3m9DLBuiDei4vG8uA.png" /></figure><p>Sample create a topic with 2 partitions and 2 replicates</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*okAchbf5kYNZ-lr9rpb_uQ.gif" /></figure><h3>Step 4 : Create a Springboot app with spring-kafka</h3><p>Please checkout this repo <a href="https://github.com/pub-technology/zookeeper-kafka-docker-springboot/tree/main/demo">https://github.com/pub-technology/zookeeper-kafka-docker-springboot/tree/main/demo</a> for more detail</p><h4>4.1 Add <em>spring-kafka </em>dependency</h4><ul><li>add the <em>spring-kafka</em> dependency to our <em>pom.xml</em></li></ul><pre>&lt;dependency&gt;<br>   &lt;groupId&gt;org.springframework.kafka&lt;/groupId&gt;<br>   &lt;artifactId&gt;spring-kafka&lt;/artifactId&gt;<br>   &lt;version&gt;2.9.2&lt;/version&gt;<br>&lt;/dependency&gt;</pre><h4>4.2 Create Kafka topic programmatically</h4><p>Now we can easy to create topics programmatically with AdminClient in Spring-Kafka. In this demo I’ll create a new topic product with KafkaAdmin</p><pre>package com.example.kafka;<br><br>import org.apache.kafka.clients.admin.AdminClientConfig;<br>import org.apache.kafka.clients.admin.NewTopic;<br>import org.springframework.beans.factory.annotation.Value;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.kafka.core.KafkaAdmin;<br><br>import java.util.HashMap;<br>import java.util.Map;<br><br>@Configuration<br>public class KafkaTopicConfig {<br><br>    @Value(value = &quot;${kafka.bootstrapAddress}&quot;)<br>    private String bootstrapAddress;<br><br>    @Bean<br>    public KafkaAdmin kafkaAdmin() {<br>        Map&lt;String, Object&gt; configs = new HashMap&lt;&gt;();<br>        configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);<br>        return new KafkaAdmin(configs);<br>    }<br><br>    @Bean<br>    public NewTopic productTopic() {<br>        return new NewTopic(&quot;product&quot;, 1, (short) 1);<br>    }<br><br>}</pre><p>After start application the configuration will be run automatically and if the top don’t exist the Kafka Amin will create a new one</p><p>In the Kafka manager we can see the our topic created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*jYMEf5Row7OcMYzxUxm_9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*JQHiFqwTFFDticXqs7ZHBw.png" /></figure><h4>4.3 Create producer &amp; send message to topic</h4><p>So now we need to config the workflow Kafka send &amp; listener message</p><p>We need a ProducerFactory support generate producer instance and we will have a KafkaTemplate use the producer instant for sending message to the topic.</p><pre>package com.example.kafka;<br><br>import lombok.extern.slf4j.Slf4j;<br>import org.apache.kafka.clients.producer.ProducerConfig;<br>import org.apache.kafka.common.serialization.StringSerializer;<br>import org.springframework.beans.factory.annotation.Value;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.kafka.core.DefaultKafkaProducerFactory;<br>import org.springframework.kafka.core.KafkaTemplate;<br>import org.springframework.kafka.core.ProducerFactory;<br>import org.springframework.kafka.support.serializer.JsonSerializer;<br><br>import lombok.RequiredArgsConstructor;<br><br>import java.io.Serializable;<br>import java.util.HashMap;<br>import java.util.Map;<br><br>@Slf4j<br>@Configuration<br>@RequiredArgsConstructor<br>public class KafkaProducerConfig {<br>    @Value(value = &quot;${kafka.bootstrapAddress}&quot;)<br>    private String bootstrapAddress;<br><br>    @Bean<br>    public ProducerFactory&lt;String, Serializable&gt; producerFactory() {<br>        Map&lt;String, Object&gt; configProps = new HashMap&lt;&gt;();<br>        configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);<br>        configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);<br>        configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);<br>        configProps.put(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, &quot;20971520&quot;);<br>        return new DefaultKafkaProducerFactory&lt;&gt;(configProps, new StringSerializer(), new JsonSerializer&lt;&gt;());<br>    }<br><br>    @Bean<br>    KafkaTemplate&lt;String, Serializable&gt; jsonKafkaTemplate(ProducerFactory&lt;String, Serializable&gt; jsonProducerFactory) {<br>        return new KafkaTemplate&lt;&gt;(jsonProducerFactory);<br>    }<br>}</pre><p>In our ProducerConfig will help our app have ability send message type JSON instead of String message.</p><p>We will create a ProductProducer support for send message to topic</p><pre>package com.example.kafka.producers;<br><br>import com.example.requests.Product;<br>import com.example.requests.ProductMessage;<br>import lombok.NoArgsConstructor;<br>import lombok.extern.slf4j.Slf4j;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.kafka.core.KafkaTemplate;<br>import org.springframework.kafka.support.SendResult;<br>import org.springframework.stereotype.Component;<br>import org.springframework.util.concurrent.ListenableFuture;<br>import org.springframework.util.concurrent.ListenableFutureCallback;<br><br>import java.io.Serializable;<br><br>@Slf4j<br>@NoArgsConstructor<br>@Component<br>public class ProductProducer {<br>    final String productTopic = &quot;product&quot;;<br><br>    private KafkaTemplate&lt;String, Serializable&gt; kafkaTemplate;<br><br>    @Autowired<br>    public ProductProducer(KafkaTemplate&lt;String, Serializable&gt; kafkaTemplate) {<br>        this.kafkaTemplate = kafkaTemplate;<br>    }<br><br>    public void send(ProductMessage message) {<br>        ListenableFuture&lt;SendResult&lt;String, Serializable&gt;&gt; future = kafkaTemplate.send(productTopic, message);<br><br>        future.addCallback(new ListenableFutureCallback&lt;SendResult&lt;String, Serializable&gt;&gt;() {<br>            @Override<br>            public void onFailure(Throwable ex) {<br>                log.error(&quot;Unable to send message = {} dut to: {}&quot;, message.toString(), ex.getMessage());<br>            }<br><br>            @Override<br>            public void onSuccess(SendResult&lt;String, Serializable&gt; result) {<br>                log.info(&quot;Message sent successfully with offset = {}&quot;, result.getRecordMetadata().offset());<br>            }<br>        });<br>    }<br><br>}</pre><p>In our service we will use ProductProvider to send message to topic</p><pre>package com.example.services;<br><br>import com.example.kafka.producers.ProductProducer;<br>import com.example.requests.Product;<br>import com.example.requests.ProductMessage;<br>import lombok.extern.slf4j.Slf4j;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.stereotype.Component;<br><br>@Component<br>@Slf4j<br>public class ProductService {<br>    private ProductProducer productProducer;<br><br>    @Autowired<br>    public ProductService(ProductProducer productProducer) {<br>        this.productProducer = productProducer;<br>    }<br><br>    public void sendMessage(ProductMessage message) {<br>        log.info(&quot;[ProductService] send product to topic&quot;);<br>        productProducer.send(message);<br>    }<br><br>}</pre><p><em>ProductProducer</em> instance are thread safe it will give higher performance don’t worry about the problem we send message continuously.</p><h4>4.4 Create consumer &amp; consuming messages from topic</h4><p>First we need to create ConsumerConfig configure a ConsumerFactory and ListenerFactory</p><pre>package com.example.kafka;<br><br>import com.example.requests.ProductMessage;<br>import lombok.extern.slf4j.Slf4j;<br>import org.apache.kafka.clients.consumer.ConsumerConfig;<br>import org.apache.kafka.common.serialization.StringDeserializer;<br>import org.springframework.beans.factory.annotation.Value;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.kafka.annotation.EnableKafka;<br>import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;<br>import org.springframework.kafka.core.ConsumerFactory;<br>import org.springframework.kafka.core.DefaultKafkaConsumerFactory;<br>import org.springframework.kafka.support.mapping.DefaultJackson2JavaTypeMapper;<br>import org.springframework.kafka.support.serializer.JsonDeserializer;<br><br>import java.util.HashMap;<br>import java.util.Map;<br><br>@Slf4j<br>@Configuration<br>public class KafkaConsumerConfig {<br>    @Value(value = &quot;${kafka.bootstrapAddress}&quot;)<br>    private String bootstrapAddress;<br>    public ConsumerFactory&lt;String, ProductMessage&gt; consumerFactory() {<br>        Map&lt;String, Object&gt; config = new HashMap&lt;&gt;();<br>        config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);<br>        config.put(ConsumerConfig.GROUP_ID_CONFIG, &quot;consuming&quot;);<br><br>        DefaultJackson2JavaTypeMapper typeMapper = new DefaultJackson2JavaTypeMapper();<br>        Map&lt;String, Class&lt;?&gt;&gt; classMap = new HashMap&lt;&gt;();<br>        typeMapper.setIdClassMapping(classMap);<br>        typeMapper.addTrustedPackages(&quot;*&quot;);<br><br>        JsonDeserializer&lt;ProductMessage&gt; jsonDeserializer = new JsonDeserializer&lt;&gt;(ProductMessage.class);<br>        jsonDeserializer.setTypeMapper(typeMapper);<br>        jsonDeserializer.setUseTypeMapperForKey(true);<br><br>        return new DefaultKafkaConsumerFactory&lt;&gt;(config, new StringDeserializer(), jsonDeserializer);<br>    }<br><br>    public Map&lt;String, Object&gt; consumerConfigs() {<br>        Map&lt;String, Object&gt; props = new HashMap&lt;&gt;();<br>        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);<br>        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);<br>        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);<br>        props.put(ConsumerConfig.GROUP_ID_CONFIG, &quot;consuming&quot;);<br>        return props;<br>    }<br><br>    @Bean<br>    public ConcurrentKafkaListenerContainerFactory&lt;String, ProductMessage&gt; kafkaListenerContainerFactory() {<br>        ConcurrentKafkaListenerContainerFactory&lt;String, ProductMessage&gt; factory = new ConcurrentKafkaListenerContainerFactory&lt;&gt;();<br>        factory.setConsumerFactory(consumerFactory());<br>        log.info(&quot;Configure concurrent consumer Kafka&quot;);<br>        return factory;<br>    }<br>}</pre><p>Next, we will create a ProductLisnter support listening the message from topic</p><pre>package com.example.kafka.listeners;<br><br>import com.example.requests.ProductMessage;<br>import lombok.extern.slf4j.Slf4j;<br>import org.springframework.kafka.annotation.KafkaListener;<br>import org.springframework.stereotype.Service;<br><br>@Slf4j<br>@Service<br>public class ProductListener {<br>    @KafkaListener(topics = &quot;product&quot;, containerFactory = &quot;kafkaListenerContainerFactory&quot;)<br>    public void newProductListener(ProductMessage product) {<br>        log.info(&quot;Get request from product topic &quot; + product.toString());<br>    }<br>}</pre><p>Demo</p><ul><li>Checkout the project and cd to demo application</li><li>Start the Spring boot application</li><li>trigger api add product `curl/product-add.sh` from root demo folder</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1_KB-qJyA0vLY-LnlwTUw.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1d4b33c0d5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>