My first practical pass at Kafka JMX: enabling remote access safely and finding the measurements that explain cluster behavior.
A practical introduction to how Kafka distributes records across brokers and why partition planning matters.
A simple mental model for ZooKeeper, znodes, sessions, and why Kafka historically used it for cluster coordination.
In today’s data-driven world, the ability to process information in real-time is crucial.
Creating a Topic in a kafka-cluster is easy and well documented for the kafka-topics.sh or even the official API documentation.
While I continue to learn more about architecture and design of kafka, a quickstart to deploy & test kafka is a must.
Step 1: Add Chart Repo # In my local system it is already present which was confirmed by the listing
While reading Apache Kafka it was interesting analogy that they described
Event streaming is the digital equivalent of the human body’s central nervous system. — Apache Kafka It draws a great parallel between how the central nervous system allows for real time event generations and consumption in terms of reflex actions. The examples are well explained and captured here.
Streams are convenient way to reduce the line of codes, but an understanding them is equally challenging. I write this blog, after realising a desperate attempt at solving a trivial problem just took overwhelming time. (Could be that I am getting old, but never late to learn things again)
Prime number is an age old problem. I am trying to solve it via streams.
class PrimeCalculator { public int nth(int nth) { if (nth <= 0) throw new IllegalArgumentException(); // Will skip the nth - 1 // 2 to n-1 return IntStream.iterate(2, i -> i + 1).filter(PrimeCalculator::isPrime).skip(nth - 1).findFirst().getAsInt(); } public static boolean isPrime(int x) { // till half of x return IntStream.rangeClosed(2, (int) (x/2) ).dropWhile(i -> x % i != 0).findFirst().isEmpty(); } } Explanation # public int nth(int nth) { if (nth <= 0) throw new IllegalArgumentException(); // Will skip the nth - 1 // 2 to n-1 return IntStream.iterate(2, i -> i + 1).filter(PrimeCalculator::isPrime).skip(nth - 1).findFirst().getAsInt(); } The method nth(int) allows you to return the nth prime starting at 2, 3, 5....
The utility package java.util.function has this functional interface Consumer.
Each functional interface (Annotated with @FunctionalInterface) conceptually has a single method (abstract) called the functional method to which the lambda expression’s parameter and return types are matched against. Functional interfaces often represent abstract concepts like functions, actions, or predicates.
Continuing from the last blog how about checking a pangram using streams.
public class PangramChecker { private String allChars = "abcdefghijklmnopqrstuvwxyz"; public boolean isPangram(String input) { if (input.length() <= 0 || input.isBlank()){ return false; } return (allChars.chars().map(x -> (char) x).filter(x -> input.toLowerCase().indexOf(x) >= 0).count() == 26); } } All the for loops have been squeezed into a simple line
Stream is an new abstraction that lets one process data in a declarative way.
A stream does not store data and, in that sense, is not a data structure. It also never modifies the underlying data source. The easiest way to learn a new API or a construct is by trying it. So here is an exercise that I tried to learn the Stream API. This is an exercise from exercism.io.