Posts

Running Apache Kafka in Windows

Windows Kafka Setup steps: 1) Download Kafka and unzip. 2) Start Zookeeper: kafka_2.10-0.8.2.1\bin\windows\zookeeper-server-start.bat tools\kafka_2.10-0.8.2.1\config\zookeeper.properties 3) Start Kafka Server kafka_2.10-0.8.2.1\bin\windows\kafka-server-start.bat tools\kafka_2.10-0.8.2.1\config\server.properties 4) List topics, to make sure Kafka is up and running kafka_2.10-0.8.2.1\bin\windows\kafka-topics.bat --list --zookeeper localhost:2181 5) Create new Topic, examples: kafka-topics.bat --create --topic sensor1 --replication-factor 1 --zookeeper localhost:2181 --partition 5 6) Produce some sample Kafka Messages: kafka_2.10-0.8.2.1\bin\windows\kafka-console-producer.sh --broker-list localhost:9092 --topic sensor1 6) Consumer to Test whether above produced messages are successfully published to Kafka broker: kafka_2.10-0.8.2.1\bin\windows\kafka-console-consumer.bat --zookeeper localhost:2181 --topic sensor1 --from-beginning 7) Stop Kafka Server: tools\kafka_2....

String Literal as Sychronization Lock

String Literal are unique. When we create another string with same literal, the second reference will point to first object itself. Please pay attention while using Strings as Synchronization locks. package com.sudheer.springbrain; public class SringLiteralThread implements Runnable { String lock; SringLiteralThread (String lock) { this.lock = lock; } @Override public void run() { System.out.println(Thread.currentThread() + " : Trying lock"); synchronized (lock) { System.out.println(Thread.currentThread() + " : Acquired lock"); if (true) { while (true) { // Some infinite loop } } } System.out.println(Thread.currentThread() + " : Done"); } public static void main(String[] args) { String lock = "abc"; String lock2 = "abc"; //String lock = new String("abc"); //String lock2 = new String("abc"); Thread t1 = new Thread(new SringLiteralThread(lock)); t1.st...

Implementing common application headers using Maven Overlay

Image
Many web applications these days are not really a single deployed instances, they are a set of applications (.ear files) deployed in different application server instances. Typically the developers divide them based on the tabs or functionality. For example, the landing or overview is one deployment, where as, billing and reports could be separate deployment and so on. But one thing which will be common in all these individual applications would be the application header (i'm not talking about http headers) which shows the page navigation. This header can have multi-level navigation structure. When user click on say Billing tab which is deployed in different app server instance, the request goes to that new server, new session gets created and page will be rendered with its own headers. The look n feel of this Billing page header would be kept same as Overview page, to make this transition unnoticeable to user. For the above purpose, the developers end up in implementing the same h...

Considering using Java Variable Arguments

one day i came across this situation, we have a Java project (LoggerCore) which is a common project used by many other projects. I had to modify a method signature in LoggerCore project, but was afraid that i would end up cascading changes in all the projects to satisfy java compiler. Started thinking that there should be someway to modify my project and common projects with out touching other projects which also use this common one. Suddenly it flashed while driving home, Java Variable Arguments. Let us have look at the code snippets: public SpringBrainLogger logIt(String referenceNumber) { ... } This is the original method signature in LoggerCore project, if I have to pass extra information, i need to add new argument and add it through out its reference. How tedious? Easily error prone! public SpringBrainLogger logIt(String referenceNumber, LogInfo... info) { ... } Intead, I considered doing this. I added LogInfo... info which is Java variable argument syntax. Boon: - Dont hav...