/
kafka.rb
122 lines (98 loc) 路 4.96 KB
/
kafka.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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/3.7.0/kafka_2.13-3.7.0.tgz"
mirror "https://archive.apache.org/dist/kafka/3.7.0/kafka_2.13-3.7.0.tgz"
sha256 "65f26e5937bbb76dfe78dfb416730dfa7e3378b27e13fd1e204f1a1099bfaf9c"
license "Apache-2.0"
livecheck do
url "https://kafka.apache.org/downloads"
regex(/href=.*?kafka[._-]v?\d+(?:\.\d+)+-(\d+(?:\.\d+)+)\.t/i)
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_sonoma: "c941187b23171c340b9f3f5edfbe6dc40113e7e6348372c1df94368666720e63"
sha256 cellar: :any_skip_relocation, arm64_ventura: "c941187b23171c340b9f3f5edfbe6dc40113e7e6348372c1df94368666720e63"
sha256 cellar: :any_skip_relocation, arm64_monterey: "c941187b23171c340b9f3f5edfbe6dc40113e7e6348372c1df94368666720e63"
sha256 cellar: :any_skip_relocation, sonoma: "bca045c1e894583a4ba40ad9076848b982c046a3c2aa798fc7ffa120a85e6329"
sha256 cellar: :any_skip_relocation, ventura: "bca045c1e894583a4ba40ad9076848b982c046a3c2aa798fc7ffa120a85e6329"
sha256 cellar: :any_skip_relocation, monterey: "bca045c1e894583a4ba40ad9076848b982c046a3c2aa798fc7ffa120a85e6329"
sha256 cellar: :any_skip_relocation, x86_64_linux: "c941187b23171c340b9f3f5edfbe6dc40113e7e6348372c1df94368666720e63"
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/kraft/server.properties",
"log.dirs=/tmp/kraft-combined-logs", "log.dirs=#{data}/kraft-combined-logs"
inreplace "config/kraft/controller.properties",
"log.dirs=/tmp/kraft-controller-logs", "log.dirs=#{data}/kraft-controller-logs"
inreplace "config/kraft/broker.properties",
"log.dirs=/tmp/kraft-broker-logs", "log.dirs=#{data}/kraft-broker-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.overridable_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
service do
run [opt_bin/"kafka-server-start", etc/"kafka/server.properties"]
keep_alive true
working_dir HOMEBREW_PREFIX
log_path var/"log/kafka/kafka_output.log"
error_log_path var/"log/kafka/kafka_output.log"
end
test do
ENV["LOG_DIR"] = "#{testpath}/kafkalog"
# Workaround for https://issues.apache.org/jira/browse/KAFKA-15413
# See https://github.com/Homebrew/homebrew-core/pull/133887#issuecomment-1679907729
ENV.delete "COLUMNS"
(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