133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/nats/io/kv.rb', line 133
def create_key_value(config)
config = if not config.is_a?(JetStream::API::StreamConfig)
KeyValue::API::KeyValueConfig.new(config)
else
config
end
config.history ||= 1
config.replicas ||= 1
if config.ttl
config.ttl = config.ttl * 1_000_000_000
end
stream = JetStream::API::StreamConfig.new(
name: "KV_#{config.bucket}",
subjects: ["$KV.#{config.bucket}.>"],
max_msgs_per_subject: config.history,
max_bytes: config.max_bytes,
max_age: config.ttl,
max_msg_size: config.max_value_size,
storage: config.storage,
num_replicas: config.replicas,
allow_rollup_hdrs: true,
deny_delete: true,
)
resp = add_stream(stream)
KeyValue.new(
name: config.bucket,
stream: stream.name,
pre: "$KV.#{config.bucket}.",
js: self,
)
end
|