avatarShiitaal Budhrauj

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5243

Abstract

name">C</span>:\Users\feng\Kafka\kraft>ls docker-compose.yml <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>docker-compose up -d [+] Running <span class="hljs-number">2</span>/<span class="hljs-number">2</span>

  • Network kraft_default Created <span class="hljs-number">0.0</span>s
  • Container kraft-kafka<span class="hljs-number">-1</span> Started

<span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES <span class="hljs-number">54342e49</span>a1f2 bitnami/<span class="hljs-name">kafka</span>:latest <span class="hljs-string">"/opt/bitnami/script…"</span> <span class="hljs-number">18</span> seconds ago Up <span class="hljs-number">17</span> seconds <span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">9092</span>-><span class="hljs-number">9092</span>/tcp kraft-kafka<span class="hljs-number">-1</span> <span class="hljs-number">0.5</span>s</pre></div><h2 id="095a">1.5 Create Kafka topic</h2><p id="0672">We’ll login to the instance and create a test topic in Kafka</p><div id="aaf2"><pre><span class="hljs-comment">## Login to Kafka docker instance</span> C:\Users\feng\Kafka\kraft>docker exec -it kraft-kafka-1 <span class="hljs-string">/bin/bash</span> <span class="hljs-keyword">cd</span> <span class="hljs-string">/opt/bitnami/kafka</span> <span class="hljs-string">/opt/bitnami/kafka</span> <span class="hljs-string">./bin/kafka-topics.sh</span> <span class="hljs-params">--version</span> 3.4.0 <span class="hljs-params">(Commit:2e1947d240607d53)</span>

<span class="hljs-comment">## Create topic named "test_topic"</span> <span class="hljs-string">/opt/bitnami/kafka</span>$ <span class="hljs-string">./bin/kafka-topics.sh</span> <span class="hljs-params">--bootstrap-server</span> localhost<span class="hljs-function">:9092</span> <span class="hljs-params">--create</span> <span class="hljs-params">--replication-factor</span> 1 <span class="hljs-params">--partitions</span> 2 <span class="hljs-params">--topic</span> test_topic WARNING: Due to limitations in metric names, topics with a period <span class="hljs-params">('.')</span> or underscore <span class="hljs-params">('_')</span> could collide. To avoid issues it is best to use either, but not both. Created topic test_topic.

<span class="hljs-comment">## List current topics</span> <span class="hljs-string">/opt/bitnami/kafka</span>$ <span class="hljs-string">./bin/kafka-topics.sh</span> <span class="hljs-params">--bootstrap-server</span> localhost<span class="hljs-function">:9092</span> <span class="hljs-params">--list</span> test_topic</pre></div><p id="8304">So by now we have a Kafka docker instance running successfully.</p><h1 id="80ee">2 Run sanity checks using simple producer/consumer app codes</h1><h2 id="b504">2.1 Setup producer/consumer Dev ENV</h2><div id="8e5b"><pre>## Create conda env <span class="hljs-keyword">for</span> Kafka producer <span class="hljs-keyword">and</span> cosumer <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>conda create -n kafka_env python=<span class="hljs-number">3.10</span> ... <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>conda activate kafka_env

Install kafka-python <span class="hljs-built_in">package</span>

(kafka_env) <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>pip install kafka-python ... (kafka_env) <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>pip list | grep kafka kafka-python <span class="hljs-number">2.0</span><span class="hljs-number">.2</span>

Install Faker <span class="hljs-built_in">package</span> to generate dummy messages

(kafka_env) <span class="hljs-name">C</span>:\Users\feng\Kafka\kraft>pip install Faker ... (kafka_env) <span class="hljs-name">C</span>:\Users<span class="hljs-number">6119811</span>\Kafka\kraft>pip list | grep Faker Faker <span class="hljs-number">17.3</span><span class="hljs-number">.0</span></pre></div><h2 id="6701">2.2 Code examples</h2><p id="c7dc">Now we can use VSCode to create producer/consumer files.</p><p id="fc6a">Producer generate fake user info as JSON load sending to Kafka topic “test_topic”. producer.py is like following.</p><div id="8801"><pre><span class="hljs-keyword">import</span> time <span class="hljs-keyword">import</span> json <span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime <span class="hljs-keyword">from</span> kafka <span class="hljs-keyword">import</span> KafkaProducer <span class="hljs-keyword">from</span> faker <span class="hljs-keyword">import</span> Faker

<span class="hljs-comment"># JSON messages needs to be serialized</span> <span class="hljs-comment"># when sending to Kafka topic </span> <span class="hljs-keyword">def</span> <span class="hljs-title function_">json_serializer</span>(<span class="hljs-params">message</span>): <span class="hljs-keyword">return</span> json.dumps(message

Options

).encode(<span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Kafka Producer</span> producer = KafkaProducer( bootstrap_servers=[<span class="hljs-string">'localhost:9092'</span>], value_serializer=json_serializer ) <span class="hljs-keyword">if</span> name == <span class="hljs-string">'main'</span>: fake = Faker() <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, <span class="hljs-number">3</span>): <span class="hljs-comment"># Generate a fake JSON message</span> name = fake.name() email = fake.email() city = fake.city() fake_message = { <span class="hljs-string">"name"</span>: name, <span class="hljs-string">"email"</span>: email, <span class="hljs-string">"city"</span>: city }

    <span class="hljs-comment"># Send fake JSON message to Kafka topic</span>
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f'<span class="hljs-subst">{datetime.now()}</span>: Message = <span class="hljs-subst">{<span class="hljs-built_in">str</span>(fake_message)}</span>'</span>)
    producer.send(<span class="hljs-string">'test_topic'</span>, fake_message)
                                                          
    time.sleep(<span class="hljs-number">1</span>)</pre></div><p id="6594">And here is our consumer.py</p><div id="a19b"><pre><span class="hljs-keyword">import</span> json 

<span class="hljs-keyword">from</span> kafka <span class="hljs-keyword">import</span> KafkaConsumer

<span class="hljs-keyword">if</span> name == <span class="hljs-string">'main'</span>: <span class="hljs-comment"># Kafka Consumer</span> consumer = KafkaConsumer( <span class="hljs-string">'test_topic'</span>, bootstrap_servers=<span class="hljs-string">'localhost:9092'</span>, auto_offset_reset=<span class="hljs-string">'earliest'</span> ) <span class="hljs-keyword">for</span> message <span class="hljs-keyword">in</span> consumer: <span class="hljs-built_in">print</span>(json.loads(message.value))</pre></div><p id="8d09">OK, now let’s start consumer and run producer to send some fake message for a sanity check.</p><div id="572f"><pre><span class="hljs-comment"># Run producer</span> (kafka_env) C:\Users\feng\Kafka\kraft>python producer.py 2023-02-25 18:48:41.143953: Message = {<span class="hljs-string">'name'</span>: <span class="hljs-string">'Susan Best'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'Kellytown'</span>} 2023-02-25 18:48:42.160545: Message = {<span class="hljs-string">'name'</span>: <span class="hljs-string">'James Wilson'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'Lake Bryanfort'</span>} 2023-02-25 18:48:43.177933: Message = {<span class="hljs-string">'name'</span>: <span class="hljs-string">'Haley Brooks'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'East Janetburgh'</span>}

<span class="hljs-comment"># Monitor consumer</span> (kafka_env) C:\Users\feng\Kafka\kraft>python consumer.py {<span class="hljs-string">'name'</span>: <span class="hljs-string">'Susan Best'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'Kellytown'</span>} {<span class="hljs-string">'name'</span>: <span class="hljs-string">'James Wilson'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'Lake Bryanfort'</span>} {<span class="hljs-string">'name'</span>: <span class="hljs-string">'Haley Brooks'</span>, <span class="hljs-string">'email'</span>: <span class="hljs-string">'[email protected]'</span>, <span class="hljs-string">'city'</span>: <span class="hljs-string">'East Janetburgh'</span>}</pre></div><p id="3143">Great, our Kafka Docker instance and simple applications are working as expected!</p><p id="79d6">Happy Reading!</p><div id="2213" class="link-block"> <a href="https://medium.com/@fengliplatform/membership"> <div> <div> <h2>Join Medium with my referral link - Feng Li</h2> <div><h3>Writing helps ourselves, sharing helps many. It started from study notes for myself with no pressure of perfection…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*K9psL5RefQfuKkzr)"></div> </div> </div> </a> </div></article></body>

Why I Prefer to Revisit a Previously Read Self-Help Book

Even When Most People Are Heading to Buy the Newest Flavour of the Season

Photo by Andrea-Piacquadio on Pexels

“One of the most effective things you can do to build better habits is to join a culture where your desired behaviour is the normal behaviour. New habits seem achievable when you see others doing them every day. If you’re surrounded by fit people, you’re more likely to consider working out to be a common habit. If you’re surrounded by jazz lovers, you’re more likely to believe it’s reasonable to play jazz every day. Your culture sets your expectation for what is “normal.” Surround yourself with people who have the habits you want to have yourself. You’ll rise together.”

— Lines from ‘Atomic Habits’ by James Clear

Image from Goodreads

#1- Why It Pays off to Go Back to The Book That Triggered Change in Your Thoughts, Belief Systems, and Hence Behavioural Patterns

The world and its denizens are busy chasing insights from the newest, hot-selling self-help book that has just landed the book stores, each year.

I’m a tad too unconventional.

Instead of chasing the newest flavour of the season, I like to dig deep.

Deeper into the pages of the book that was instrumental in triggering change in me, in the first place.

The book made such a deep impact on my thinking that it led me on a transformative trajectory the very first time I devoured the delicious new concepts off its pages.

My logic being: it had the capacity to move me to such an extent, that it triggered a change in me then. A change that I have been able to sustain.

Surely, if I read it now, after another 6 months, I’ll get fresh insights glaring at me, that I missed out on, the first time around.

Let me distill this concept a little more deeply.

#2- Why the 6 Months Break is Required Before Revisiting the Book

Writers write the first draft of an article and then allow a few days to pass before they get down to the editing stage.

At least two nights of sleep should have elapsed between the writing bit and the editing stage, for the article to truly sparkle.

For it to pack a punch. For the writer to be able to cut out the fluff.

Why is editing smoother then?

The writer has acquired layers of objectivity by then.

Two days of not looking at the article have allowed them to breathe easily around it.

It allows the subconscious mind of the writer to get some perspective and distance themselves from all that they had written first.

The first draft is usually a brain dump of sorts.

They will happily kill their darlings now.

They will slice and dice the chaff from the grain ruthlessly.

Editing should always be done with a pair of fresh eyes.

Layers of objectivity are formed in those 48 hours that you take a break from the first draft.

If you’re writing and editing at the same time, you are churning out crappy shit.

I gleaned a practical understanding of habits and systems beyond the run-of-the-mill advice offered online when I sank my teeth into the pages of the most popular book in that genre. Yes, you guessed right — it is Atomic Habits.

It was the way in which Clear summed up the premise of the habit that was able to get me to truly make changes in my routine. Changes that I have been able to sustain.

I was able to set up a system in my life that continues to simplify my day. And make the most of my time.

#3- How Six Months of Applying The Concepts I First Read Has Made Me Much The Wiser For My Time

For six months, I experimented with the ideas presented in the book and applied them.

They worked for me and in the process I learnt a lot about my own strengths and weaknesses.

Nearly half my book has pages that have been dogeared and paragraphs that have been highlighted with the wax crayon highlighters.

I distill information in the deeper layers of my inner mind that way.

It’s my process when I’m truly enjoying a book.

The core philosophy of our identities and belief systems being aligned with our habits was crucial to my understanding of why we stick with some habits. It led me to form sustainable habits.

I designed my habits such that they would be coherent with my core values and belief systems.

And now I can form habits that will work for me. Not against me.

For 180 days after that, I did not look at the book.

Last month, I was in the mood to pick up a self-help book.

No prizes for guessing which book I reached out for.

Correct — Atomic Habits.

I went back to the book after 6 months.

It was like peeling the layers of an onion.

It was like discovering delicious new nuggets and ideas after distancing myself from it, for six months.

So akin to reading an article that you may have written 6 months ago.

So much has transpired in life by then, that you are co-relating it with how you have applied the principles when you first read about them.

You have evolved in these 6 months because of them.

You can now take the trajectory a little bit further.

You are already in the groove of having initiated the change.

A little nudge from a familiar voice will take you higher on the trajectory.

Why should you not go all the way and reap some more benefits?

#4- How Akin it is to The Holiday You Took to That Same Hill Station One Year Ago

Photo by Victoria Rain on Pexels

It is like going to your favourite getaway in the hills after a year.

You’ll spot new nooks and crannies that you feel never existed in the first place.

Plus, it has the soothing scent of familiarity.

Déjà vu with a novelty quotient attached to it.

As people are busy making New Year’s resolutions each year with the help of the latest book in the category of self-help, what I do is pick up a copy of Atomic Habits and gain new insights.

So many pages from my original copy have been dogeared. I add to that process after 6 months again. Pick up my wax fluorescent highlighters yet again. Get my hands dirty. So fun.

Reading it after a gap of 6 months is leading to many more ‘aha’s now.

So many familiar zones are oozing with new perspectives as I have lived life in those 6 months and my worldview has expanded in those 6 months.

I am eager to experiment with those concepts and apply myself a little more differently now.

#5- Something That Made a Positive Impact Straight Off The Bat Should Be Reinforced

This practice of going back to this single book every 6 months has helped me really build on my habit of working out. It has expanded my understanding of how’ and why’ a habit gets formed.

After 6 months, I’m more malleable and likely to stick to my habits even on days, when I’m not in the mood to work out.

Two consecutive days off from the habit loop can form a new habit of ‘not working out.’

I love to meet people who work out and forge friendships with them. That way our conversations about working out are bound to come up.

— Conversations about Body Composition Analysis, meal plans, leg day, muscle mass, etc and so much more about fitness.

— How much more their bodies have become toned over the last 2–3 years.

— These conversations linger in the emotional hemisphere of my brain long after I’ve parted with my friends for the day.

— It keeps egging me on to be consistent with my practice of working out.

— This habit of making friends with people who are serious about fitness is a direct offshoot of devouring the pages of Atomic Habits every 6 months. (refer to the paragraph that I have quoted from the book, right at the beginning of the article).

Sometimes when a book has such a transformative impact on you, it becomes crucial to disconnect from it for a bit — say 3 months or 6 months.

You would have become wiser through those months, and are willing to glean some more insights.

#6- Why Did I Choose to Give The Example of Atomic Habits

Photo by Pew Nguyen on Pexels

I gave the example of Atomic Habits because of its mass appeal.

There’s not a single person that I know who hasn’t read this path-breaking gem.

There are several books that I revisit after 6 months and crosscheck the insights with how much of a headway I’ve made over the last 6 months.

And start applying concepts that I’ve missed out on.

But of all of them, Atomic Habits remains my favourite book that is revisiting-worthy every 180 days, 1000 times over.

Give it a shot after 6 months of reading it. Bet it’ll take you by surprise!

Enjoyed the article. A little something about me:

Reading
Self Help Books
Effective Learning
Different Perspectives
Bouncin And Behavin Blogs
Recommended from ReadMedium