Skip to content

Latest commit

 

History

History
96 lines (76 loc) · 4.44 KB

README.md

File metadata and controls

96 lines (76 loc) · 4.44 KB

Kafka

See also:

Kafka on AWS

"We recommend using d2.xlarge if you're using instance storage, or r3.xlarge or m4.2xlarge if you’re using EBS"

Configuration

See lib/kafka/kafka.rake :service:configure

Look for "kafka" in:

  • config/settings/{stage}.yml
  • config/deploy/{stage}.yml

Capistrano tasks

$ bundle exec cap -T | grep kafka
cap kafka:nodes:check_settings                        # List settings in this project
cap kafka:nodes:create                                # Create nodes
cap kafka:nodes:etc_hosts_private                     # Compose entries for /etc/hosts using private IPs
cap kafka:nodes:etc_hosts_public                      # Compose entries for /etc/hosts using public IPs
cap kafka:nodes:find                                  # Find and describe all nodes
cap kafka:nodes:reboot                                # Reboot Kafka systems - WARNING, can reset IPs
cap kafka:nodes:ssh_config_private                    # Compose private entries for ~/.ssh/config for nodes
cap kafka:nodes:ssh_config_public                     # Compose public entries for ~/.ssh/config for nodes
cap kafka:nodes:terminate                             # Terminate nodes
cap kafka:service:advertised_listeners                # Compose public advertised.listeners for brokers
cap kafka:service:brokers                             # Compose public brokers for client connections
cap kafka:service:brokers_private                     # Compose private brokers for client connections
cap kafka:service:configure                           # Configure Kafka service
cap kafka:service:install                             # Install Kafka service
cap kafka:service:listeners                           # Compose private listeners for brokers
cap kafka:service:start                               # Start Kafka service
cap kafka:service:status                              # Status of Kafka service
cap kafka:service:stop                                # Stop Kafka service
cap kafka:service:tail_server_log[server]             # tail -n250 ${KAFKA_HOME}/logs/server.log

Using Kafka

For this quick test, it's assumed there is a local installation of Kafka available in /opt/kafka. This test will use some Kafka utilities to work with the AWS cluster. It's a good idea to match the local version with the AWS cluster version.

export KAFKA_HOME=/opt/kafka
export STAGE={stage}

# get the zookeeper connection details (replace 'test' with your capistrano {stage})
ZK=$(bundle exec cap ${STAGE} zookeeper:service:connections)
KAFKA_ZK="${ZK}/kafka"
echo $KAFKA_ZK

# list all the topics (should be zero for first installation)
${KAFKA_HOME}/bin/kafka-topics.sh --zookeeper ${KAFKA_ZK} --list

# create a 'test' topic
# - replication-factor must be less than or equal to the number of brokers
${KAFKA_HOME}/bin/kafka-topics.sh --zookeeper ${KAFKA_ZK} --create   --topic test --partitions 2 --replication-factor 1 --if-not-exists
${KAFKA_HOME}/bin/kafka-topics.sh --zookeeper ${KAFKA_ZK} --describe --topic test

# use console utils to observe pub/sub activity
# - create a new screen session
#   - it should inherit the ENV values for $STAGE and $KAFKA_HOME set above
# - use screen to create a vertical split window for the producer and consumer:
#   - `^a |` to split vertically and `^A tab` to jump between them
#   - `^a c` to create a new session in the right side window
#   - `^a ?` for screen help

# - in the left window:
# get the kafka broker list (replace 'test' with your capistrano {stage})
KAFKA_BROKERS=$(bundle exec cap ${STAGE} kafka:service:brokers)
echo $KAFKA_BROKERS
# create the producer using:
${KAFKA_HOME}/bin/kafka-console-producer.sh --broker-list ${KAFKA_BROKERS} --topic test

# - in the right window:
# get the kafka broker list (replace 'test' with your capistrano {stage})
KAFKA_BROKERS=$(bundle exec cap ${STAGE} kafka:service:brokers)
echo $KAFKA_BROKERS
# create the consumer using:
${KAFKA_HOME}/bin/kafka-console-consumer.sh --bootstrap-server ${KAFKA_BROKERS} --topic test

# - back in the left window, `^A |`, type in some one-line messages to the 'test' topic
# - watch the consumer in the right window echo back the messages