Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create stream in docker compose config file #103

Open
Kowiste opened this issue Mar 25, 2023 · 1 comment
Open

Create stream in docker compose config file #103

Kowiste opened this issue Mar 25, 2023 · 1 comment

Comments

@Kowiste
Copy link

Kowiste commented Mar 25, 2023

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)
}
@bruth
Copy link
Collaborator

bruth commented Oct 17, 2023

Hi @Kowiste, NATS does not support defining streams in the configuration file. The options are programmatically through the client libraries (e.g. Go), the CLI, a Terraform provider, or nack (a k8s controller).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants