ConnectEverything / ConnectEverything/nats-by-example
Create stream in docker compose config file
- Dominant language
- Go
- Stars
- 207
- Forks
- 51
- PR merge metrics
- No merged PRs in 30d
Description
Really nice project you have here.
I have a problem trying to create a stream in the configuration file, it would be nice if you could add a example for this.
Here is what I'm doing now, with the container up I connect to nats and cant see mistream , but after the addstream line test stream is display.
How I can configure streams in the config file?
docker-compose.yml
```
version: '3.5'
services:
nats:
image: nats:2.9.15-alpine3.17
container_name: nats
restart: unless-stopped
command: --js
ports:
- "4222:4222"
- "8222:8222"
networks:
- web
volumes:
- ./conf/nats-server.conf:/etc/nats/nats-server.conf
networks:
web:
external: true
```
nats-server.conf
```
port: 4222
jetstream: enabled
monitor_port: 8222
jetstream {
store_dir: "/data/jetstream"
store_type: "file"
streams {
name: "mistream"
subjects: ["mistream.*"]
retention {
limit: 100
max_bytes: 1G
}
max_msg_size: 500KB
}
}
cluster {
name: "my_cluster"
port: 6222
authorization {
user: ruser
password: T0pS3cr3t
timeout: 2
}
routes = []
}
```
main.go
```
func main() {
nc, err := nats.Connect("nats://localhost:4222")
if err != nil {
fmt.Println("Connection error:", err)
return
}
defer nc.Close()
js, err := nc.JetStream()
if err != nil {
fmt.Println("Error Jetstream:", err)
return
}
c := <-js.StreamNames()
println(c)
js.AddStream(&nats.StreamConfig{
Name: "test",
})
c = <-js.StreamNames()
println(c)
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Review the repository's runnable examples alongside the reported docker-compose.yml, nats-server.conf, and main.go. Run the configuration against NATS and verify that it creates mistream without the manual AddStream call; document the working stream configuration and usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker-compose, go
- Domain
- devops, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100