279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/nats/io/kv.rb', line 279
def create_key_value(config)
config = if not config.is_a?(KeyValue::API::KeyValueConfig)
KeyValue::API::KeyValueConfig.new(config)
else
config
end
config.history ||= 1
config.replicas ||= 1
duplicate_window = 2 * 60 if config.ttl
if config.ttl < duplicate_window
duplicate_window = config.ttl
end
config.ttl = config.ttl * ::NATS::NANOSECONDS
end
stream = JetStream::API::StreamConfig.new(
name: "KV_#{config.bucket}",
description: config.description,
subjects: ["$KV.#{config.bucket}.>"],
allow_direct: config.direct,
allow_rollup_hdrs: true,
deny_delete: true,
discard: "new",
duplicate_window: duplicate_window * ::NATS::NANOSECONDS,
max_age: config.ttl,
max_bytes: config.max_bytes,
max_consumers: -1,
max_msg_size: config.max_value_size,
max_msgs: -1,
max_msgs_per_subject: config.history,
num_replicas: config.replicas,
storage: config.storage,
republish: config.republish,
)
si = add_stream(stream)
KeyValue.new(
name: config.bucket,
stream: stream.name,
pre: "$KV.#{config.bucket}.",
js: self,
direct: si.config.allow_direct
)
end
|