|
14 | 14 | #
|
15 | 15 | # @param zookeeper
|
16 | 16 | # The connection string for the ZooKeeper connection in the form host:port.
|
17 |
| -# Multiple hosts can be given to allow fail-over. |
| 17 | +# Multiple hosts can be given to allow fail-over. Kafka < 3.0.0 only! |
| 18 | +# |
| 19 | +# @param bootstrap_server |
| 20 | +# The Kafka server to connect to in the form host:port. Kafka >= 2.2.0 only! |
18 | 21 | #
|
19 | 22 | # @param replication_factor
|
20 | 23 | # The replication factor for each partition in the topic being created. If
|
|
32 | 35 | # See the Kafka documentation for full details on the topic configs.
|
33 | 36 | #
|
34 | 37 | define kafka::topic (
|
35 |
| - String[1] $ensure = '', |
36 |
| - String[1] $zookeeper = '', |
| 38 | + Optional[String[1]] $ensure = undef, |
| 39 | + Optional[String[1]] $zookeeper = undef, |
| 40 | + Optional[String[1]] $bootstrap_server = undef, |
37 | 41 | Integer $replication_factor = 1,
|
38 | 42 | Integer $partitions = 1,
|
39 | 43 | String[1] $bin_dir = '/opt/kafka/bin',
|
40 | 44 | Optional[Hash[String[1],String[1]]] $config = undef,
|
41 | 45 | ) {
|
42 | 46 | $_zookeeper = "--zookeeper ${zookeeper}"
|
| 47 | + $_bootstrap_server = "--bootstrap-server ${bootstrap_server}" |
43 | 48 | $_replication_factor = "--replication-factor ${replication_factor}"
|
44 | 49 | $_partitions = "--partitions ${partitions}"
|
45 | 50 |
|
| 51 | + if !$zookeeper and !$bootstrap_server { |
| 52 | + fail('Either zookeeper or bootstrap_server parameter must be defined!') |
| 53 | + } |
| 54 | + |
| 55 | + if $zookeeper { |
| 56 | + $_connection = $_zookeeper |
| 57 | + } else { |
| 58 | + $_connection = $_bootstrap_server |
| 59 | + } |
| 60 | + |
46 | 61 | if $config {
|
47 | 62 | $_config_array = $config.map |$key, $value| { "--config ${key}=${value}" }
|
48 | 63 | $_config = join($_config_array, ' ')
|
|
53 | 68 | if $ensure == 'present' {
|
54 | 69 | exec { "create topic ${name}":
|
55 | 70 | path => "/usr/bin:/usr/sbin/:/bin:/sbin:${bin_dir}",
|
56 |
| - command => "kafka-topics.sh --create ${_zookeeper} ${_replication_factor} ${_partitions} --topic ${name} ${_config}", |
57 |
| - unless => "kafka-topics.sh --list ${_zookeeper} | grep -x ${name}", |
| 71 | + command => "kafka-topics.sh --create ${_connection} ${_replication_factor} ${_partitions} --topic ${name} ${_config}", |
| 72 | + unless => "kafka-topics.sh --list ${_connection} | grep -x ${name}", |
58 | 73 | }
|
59 | 74 | }
|
60 | 75 | }
|
0 commit comments