go-micro.dev/v5@v5.12.0/store/nats-js-kv/README.md (about) 1 # NATS JetStream Key Value Store Plugin 2 3 This plugin uses the NATS JetStream [KeyValue Store](https://docs.nats.io/nats-concepts/jetstream/key-value-store) to implement the Go-Micro store interface. 4 5 You can use this plugin like any other store plugin. 6 To start a local NATS JetStream server run `nats-server -js`. 7 8 To manually create a new storage object call: 9 10 ```go 11 natsjskv.NewStore(opts ...store.Option) 12 ``` 13 14 The Go-Micro store interface uses databases and tables to store keys. These translate 15 to buckets (key value stores) and key prefixes. If no database (bucket name) is provided, "default" will be used. 16 17 You can call `Write` with any arbitrary database name, and if a bucket with that name does not exist yet, 18 it will be automatically created. 19 20 If a table name is provided, it will use it to prefix the key as `<table>_<key>`. 21 22 To delete a bucket, and all the key/value pairs in it, pass the `DeleteBucket` option to the `Delete` 23 method, then they key name will be interpreted as a bucket name, and the bucket will be deleted. 24 25 Next to the default store options, a few NATS specific options are available: 26 27 28 ```go 29 // NatsOptions accepts nats.Options 30 NatsOptions(opts nats.Options) 31 32 // JetStreamOptions accepts multiple nats.JSOpt 33 JetStreamOptions(opts ...nats.JSOpt) 34 35 // KeyValueOptions accepts multiple nats.KeyValueConfig 36 // This will create buckets with the provided configs at initialization. 37 // 38 // type KeyValueConfig struct { 39 // Bucket string 40 // Description string 41 // MaxValueSize int32 42 // History uint8 43 // TTL time.Duration 44 // MaxBytes int64 45 // Storage StorageType 46 // Replicas int 47 // Placement *Placement 48 // RePublish *RePublish 49 // Mirror *StreamSource 50 // Sources []*StreamSource 51 } 52 KeyValueOptions(cfg ...*nats.KeyValueConfig) 53 54 // DefaultTTL sets the default TTL to use for new buckets 55 // By default no TTL is set. 56 // 57 // TTL ON INDIVIDUAL WRITE CALLS IS NOT SUPPORTED, only bucket wide TTL. 58 // Either set a default TTL with this option or provide bucket specific options 59 // with ObjectStoreOptions 60 DefaultTTL(ttl time.Duration) 61 62 // DefaultMemory sets the default storage type to memory only. 63 // 64 // The default is file storage, persisting storage between service restarts. 65 // Be aware that the default storage location of NATS the /tmp dir is, and thus 66 // won't persist reboots. 67 DefaultMemory() 68 69 // DefaultDescription sets the default description to use when creating new 70 // buckets. The default is "Store managed by go-micro" 71 DefaultDescription(text string) 72 73 // DeleteBucket will use the key passed to Delete as a bucket (database) name, 74 // and delete the bucket. 75 // This option should not be combined with the store.DeleteFrom option, as 76 // that will overwrite the delete action. 77 DeleteBucket() 78 ``` 79