Setup Kafka In Macos

OS : MacOS Sonoma - Silicon Chip

Date: 26-April-2025


Install:

brew install kafka


Start Kafka

To start kafka now and restart at login:

  brew services start kafka


Or, if you don't want/need a background service you can just run:

  /opt/homebrew/opt/kafka/bin/kafka-server-start /opt/homebrew/etc/kafka/server.properties


Create Topic

vishesh@visheshs-MacBook-Pro bin % /opt/homebrew/opt/kafka/bin/kafka-topics --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1

Created topic test-topic.


Verify Topic creation

vishesh@visheshs-MacBook-Pro bin % /opt/homebrew/opt/kafka/bin/kafka-topics --list --bootstrap-server localhost:9092

test-topic


Sending Producer

mauli@maulis-MacBook-Pro bin % /opt/homebrew/opt/kafka/bin/kafka-console-producer --bootstrap-server localhost:9092 --topic test-topic

>Hello Mauli

>$(date)

>`date`

>Its fun

mauli@maulis-MacBook-Pro bin % echo "Trying to send Message to topic using Pipe Symbol with correct command" | /opt/homebrew/opt/kafka/bin/kafka-console-producer --bootstrap-server localhost:9092 --topic test-topic

>>%

mauli@maulis-MacBook-Pro bin %


Receiver Consumer

/opt/homebrew/opt/kafka/bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic test-topic --from-beginning 

Hello Mauli

Hello Mauli from consumer

$(date)

`date`

Its fun

Trying to send Message to topic using Pipe Symbol with correct command


Setup topic to send keyvalue style

vishesh@visheshs-MacBook-Pro bin % /opt/homebrew/opt/kafka/bin/kafka-console-producer \

  --bootstrap-server localhost:9092 \

  --topic test-topic \

  --property "parse.key=true" \

  --property "key.separator=:"

>"key1:value1"

>"NAME: VISHESH"

>Hey Vidisha


Setup Topic to receive keyvalue style

vishesh@visheshs-MacBook-Pro bin % /opt/homebrew/opt/kafka/bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic test-topic --from-beginning \

> --property "print.key=true" \

  --property "key.separator= | "

null | Hello Mauli

null | $(date)

null | `date`

null | Its fun

null | Trying to send Message to topic using Pipe Symbol with correct command

"key1 | value1"

"NAME |  VISHESH"

null | Hey Vidisha



Comments

Popular posts from this blog

Angular Pie Chart

Spring Boot Export Data to Excel Example