123 lines
4.6 KiB
Ruby
123 lines
4.6 KiB
Ruby
class Kafka < Formula
|
|
desc "Open-source distributed event streaming platform"
|
|
homepage "https://kafka.apache.org/"
|
|
url "https://www.apache.org/dyn/closer.lua?path=kafka/2.8.0/kafka_2.13-2.8.0.tgz"
|
|
mirror "https://archive.apache.org/dist/kafka/2.8.0/kafka_2.13-2.8.0.tgz"
|
|
sha256 "3fa380ae5d1385111ee9c83b0d1806172924ffec2e29399fd1a42671a97492c6"
|
|
license "Apache-2.0"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, big_sur: "2419e9580114e1927801684919abd741fa1b90dc05b458209e40848da97f536f"
|
|
sha256 cellar: :any_skip_relocation, catalina: "2419e9580114e1927801684919abd741fa1b90dc05b458209e40848da97f536f"
|
|
sha256 cellar: :any_skip_relocation, mojave: "0dcd62ccde3266e7e2719e06bc40c8f9ec837e9d37dcffc18bd9b8d78c1536b7"
|
|
end
|
|
|
|
depends_on "openjdk"
|
|
depends_on "zookeeper"
|
|
|
|
def install
|
|
data = var/"lib"
|
|
inreplace "config/server.properties",
|
|
"log.dirs=/tmp/kafka-logs", "log.dirs=#{data}/kafka-logs"
|
|
|
|
inreplace "config/zookeeper.properties",
|
|
"dataDir=/tmp/zookeeper", "dataDir=#{data}/zookeeper"
|
|
|
|
# remove Windows scripts
|
|
rm_rf "bin/windows"
|
|
|
|
libexec.install "libs"
|
|
|
|
prefix.install "bin"
|
|
bin.env_script_all_files(libexec/"bin", Language::Java.java_home_env)
|
|
Dir["#{bin}/*.sh"].each { |f| mv f, f.to_s.gsub(/.sh$/, "") }
|
|
|
|
mv "config", "kafka"
|
|
etc.install "kafka"
|
|
libexec.install_symlink etc/"kafka" => "config"
|
|
|
|
# create directory for kafka stdout+stderr output logs when run by launchd
|
|
(var+"log/kafka").mkpath
|
|
end
|
|
|
|
plist_options manual: "zookeeper-server-start -daemon #{HOMEBREW_PREFIX}/etc/kafka/zookeeper.properties & kafka-server-start #{HOMEBREW_PREFIX}/etc/kafka/server.properties"
|
|
|
|
def plist
|
|
<<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>WorkingDirectory</key>
|
|
<string>#{HOMEBREW_PREFIX}</string>
|
|
<key>ProgramArguments</key>
|
|
<array>
|
|
<string>#{opt_bin}/kafka-server-start</string>
|
|
<string>#{etc}/kafka/server.properties</string>
|
|
</array>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
<key>KeepAlive</key>
|
|
<true/>
|
|
<key>StandardErrorPath</key>
|
|
<string>#{var}/log/kafka/kafka_output.log</string>
|
|
<key>StandardOutPath</key>
|
|
<string>#{var}/log/kafka/kafka_output.log</string>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
ENV["LOG_DIR"] = "#{testpath}/kafkalog"
|
|
|
|
(testpath/"kafka").mkpath
|
|
cp "#{etc}/kafka/zookeeper.properties", testpath/"kafka"
|
|
cp "#{etc}/kafka/server.properties", testpath/"kafka"
|
|
inreplace "#{testpath}/kafka/zookeeper.properties", "#{var}/lib", testpath
|
|
inreplace "#{testpath}/kafka/server.properties", "#{var}/lib", testpath
|
|
|
|
zk_port = free_port
|
|
kafka_port = free_port
|
|
inreplace "#{testpath}/kafka/zookeeper.properties", "clientPort=2181", "clientPort=#{zk_port}"
|
|
inreplace "#{testpath}/kafka/server.properties" do |s|
|
|
s.gsub! "zookeeper.connect=localhost:2181", "zookeeper.connect=localhost:#{zk_port}"
|
|
s.gsub! "#listeners=PLAINTEXT://:9092", "listeners=PLAINTEXT://:#{kafka_port}"
|
|
end
|
|
|
|
begin
|
|
fork do
|
|
exec "#{bin}/zookeeper-server-start #{testpath}/kafka/zookeeper.properties " \
|
|
"> #{testpath}/test.zookeeper-server-start.log 2>&1"
|
|
end
|
|
|
|
sleep 15
|
|
|
|
fork do
|
|
exec "#{bin}/kafka-server-start #{testpath}/kafka/server.properties " \
|
|
"> #{testpath}/test.kafka-server-start.log 2>&1"
|
|
end
|
|
|
|
sleep 30
|
|
|
|
system "#{bin}/kafka-topics --bootstrap-server localhost:#{kafka_port} --create --if-not-exists " \
|
|
"--replication-factor 1 --partitions 1 --topic test > #{testpath}/kafka/demo.out " \
|
|
"2>/dev/null"
|
|
pipe_output "#{bin}/kafka-console-producer --bootstrap-server localhost:#{kafka_port} --topic test 2>/dev/null",
|
|
"test message"
|
|
system "#{bin}/kafka-console-consumer --bootstrap-server localhost:#{kafka_port} --topic test " \
|
|
"--from-beginning --max-messages 1 >> #{testpath}/kafka/demo.out 2>/dev/null"
|
|
system "#{bin}/kafka-topics --bootstrap-server localhost:#{kafka_port} --delete --topic test " \
|
|
">> #{testpath}/kafka/demo.out 2>/dev/null"
|
|
ensure
|
|
system "#{bin}/kafka-server-stop"
|
|
system "#{bin}/zookeeper-server-stop"
|
|
sleep 10
|
|
end
|
|
|
|
assert_match(/test message/, File.read("#{testpath}/kafka/demo.out"))
|
|
end
|
|
end
|