KAFKA

Install kafka, start zookeeper, create topic

Naranjito 2020. 12. 17. 12:09
  • brew

It shows me what I can do with brew funtion.

Joses-MacBook-Pro:~ joohyunyoon$ brew
Example usage:
  brew search [TEXT|/REGEX/]
  brew info [FORMULA...]
  brew install FORMULA...
  brew update
  brew upgrade [FORMULA...]
  brew uninstall FORMULA...
  brew list [FORMULA...]
  ...

 

  • brew search

The list of application it offers.

Joses-MacBook-Pro:~ joohyunyoon$ brew search
a2ps                                  goolabs                               ophcrack
a52dec                                goose                                 optipng
aacgain                               gopass                                opus
aalib                                 gor                                   opus-tools
aamath                                goreleaser                            opusfile
aardvark_shell_utils                  goreman                               oq
abcde                                 gosu                                  orbit
...

 

For example, if I want to know whthere kibana is available or no, let's search.

Joses-MacBook-Pro:~ joohyunyoon$ brew search kibana
==> Formulae
kibana                                                   kibana@6

 

  • brew install kafka
Joses-MacBook-Pro:~ joohyunyoon$ brew install kafka
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
acl2                   easy-rsa               ladspa-sdk             lua@5.3                simdjson
act                    eksctl                 ldpl                   lunchy                 sleef
aerc                   eleventy               leaf                   lunchy-go              snap
...

 

  • brew services start zookeeper

It roles as storage of kafka information.

Joses-MacBook-Pro:~ joohyunyoon$ brew services start zookeeper
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (61/61), done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 1033 (delta 21), reused 41 (delta 8), pack-reused 972

...

Tapped 1 command (40 files, 386.5KB).
==> Successfully started `zookeeper` (label: homebrew.mxcl.zookeeper)

 

  • brew services start kafka
Joses-MacBook-Pro:~ joohyunyoon$ brew services start kafka
==> Successfully started `kafka` (label: homebrew.mxcl.kafka)
Joses-MacBook-Pro:~ joohyunyoon$ brew info kafka
kafka: stable 2.6.0 (bottled)

...

==> Successfully started `zookeeper` (label: homebrew.mxcl.zookeeper)
Joses-MacBook-Pro:~ joohyunyoon$ brew services start kafka
==> Successfully started `kafka` (label: homebrew.mxcl.kafka)

 

  • brew info kafka

Once kafka installed, it offers various script for testing. In order to get the location of this script, use info.

And there is the location below.

Joses-MacBook-Pro:~ joohyunyoon$ brew info kafka
kafka: stable 2.6.0 (bottled)
Publish-subscribe messaging rethought as a distributed commit log
https://kafka.apache.org/
/usr/local/Cellar/kafka/2.6.0_1 (193 files, 62.4MB) *
...

 

  • cd /usr/local/Cellar/kafka/2.6.0_1/bin

Change directory where script located.

 

 

  • ./kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 -partitions 1 --topic joohyun

I came into it.

Let's create the topic which has one partition, one replication and put the name as joohyun.

Joses-MacBook-Pro:bin joohyunyoon$ ./kafka-topics --create --zookeeper 
localhost:2181 --replication-factor 1 -partitions 1 --topic joohyun
Created topic joohyun.

 

  • ./kafka-console-producer --broker-list localhost:9092 --topic joohyun

Let's put the data into the topic which name is joohyun.

Joses-MacBook-Pro:bin joohyunyoon$ ./kafka-console-producer --broker-list 
localhost:9092 --topic joohyun
>hello
>kafka

 

  • ./kafka-console-consumer --boostrap-server localhost:9092 --topic joohyun --from-beginning

Hey, data, are you in there? Ok, show me all of you.

Joses-MacBook-Pro:bin joohyunyoon$ ./kafka-console-consumer --boostrap-server localhost:9092 
--topic joohyun --from-beginning