Skip to content

Create stream in docker compose config file #103

@kowiste

Description

@kowiste

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions