From f5db091d921e0ff96cf75b0c51c635b52971f832 Mon Sep 17 00:00:00 2001 From: QJoly Date: Wed, 18 Sep 2024 19:53:31 +0200 Subject: [PATCH] chore: Update module paths for autocoffee components --- .gitignore | 1 + README.md | 16 +++++++- coffee-maker/docker-compose.yaml | 2 +- coffee-maker/go.mod | 2 +- controller/docker-compose.yaml | 2 +- controller/go.mod | 2 +- routes/docker-compose.yaml | 2 +- routes/go.mod | 2 +- samples/betterSub/go.mod | 13 ------ samples/betterSub/go.sum | 12 ------ samples/betterSub/main.go | 32 --------------- samples/microService/go.mod | 13 ------ samples/microService/go.sum | 12 ------ samples/microService/main.go | 48 ---------------------- samples/queueGroup/go.mod | 13 ------ samples/queueGroup/go.sum | 12 ------ samples/queueGroup/main.go | 28 ------------- samples/request/go.mod | 13 ------ samples/request/go.sum | 12 ------ samples/request/main.go | 40 ------------------ samples/simplePub/go.mod | 13 ------ samples/simplePub/go.sum | 12 ------ samples/simplePub/main.go | 27 ------------- samples/simpleSub/go.mod | 13 ------ samples/simpleSub/go.sum | 12 ------ samples/simpleSub/main.go | 40 ------------------ samples/stream/go.mod | 14 ------- samples/stream/go.sum | 14 ------- samples/stream/main.go | 69 -------------------------------- stock-manager/go.mod | 2 +- stock-manager/main.go | 6 --- 31 files changed, 23 insertions(+), 476 deletions(-) delete mode 100644 samples/betterSub/go.mod delete mode 100644 samples/betterSub/go.sum delete mode 100644 samples/betterSub/main.go delete mode 100644 samples/microService/go.mod delete mode 100644 samples/microService/go.sum delete mode 100644 samples/microService/main.go delete mode 100644 samples/queueGroup/go.mod delete mode 100644 samples/queueGroup/go.sum delete mode 100644 samples/queueGroup/main.go delete mode 100644 samples/request/go.mod delete mode 100644 samples/request/go.sum delete mode 100644 samples/request/main.go delete mode 100644 samples/simplePub/go.mod delete mode 100644 samples/simplePub/go.sum delete mode 100644 samples/simplePub/main.go delete mode 100644 samples/simpleSub/go.mod delete mode 100644 samples/simpleSub/go.sum delete mode 100644 samples/simpleSub/main.go delete mode 100644 samples/stream/go.mod delete mode 100644 samples/stream/go.sum delete mode 100644 samples/stream/main.go diff --git a/.gitignore b/.gitignore index f734cd7..befc201 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ go.work.sum \#**# **.db +seed.txt \ No newline at end of file diff --git a/README.md b/README.md index 95c548d..2d00db6 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ -# coffee-shop \ No newline at end of file +# AutoCoffee - a NATS based microservices demo + +This is a simple demo of a microservices architecture using NATS as the messaging system. The demo is based on a "coffee shop" scenario where clients can order coffee in an automated way. + +# Architecture + +The demo consists of the following components: +- `routes` - a service that exposes a web interface for clients to order coffee. +- `controller` - a service that receives the orders from the `routes` service, check the stock (using the `stock` service) and send the order to `coffee-makers` services. +- `stock` - a service that keeps track of the stock of coffee beans in a database. +- `coffee-makers` - a service that receives the orders from the `controller` service and makes the coffee. The service updates the stock in the `stock` service when an order is completed. + +# Running the demo + +You will need to have a NATS server running. diff --git a/coffee-maker/docker-compose.yaml b/coffee-maker/docker-compose.yaml index 6540e86..99115aa 100644 --- a/coffee-maker/docker-compose.yaml +++ b/coffee-maker/docker-compose.yaml @@ -2,7 +2,7 @@ version: '3.8' services: coffee-makers: - image: ghcr.io/une-tasse-de-cafe/coffee-shop/coffeemakers:latest + image: ghcr.io/une-tasse-de-cafe/autocoffee/coffeemakers:latest build: . environment: - "NATS_URL=192.168.128.51:4222" diff --git a/coffee-maker/go.mod b/coffee-maker/go.mod index f965c0f..edd7892 100644 --- a/coffee-maker/go.mod +++ b/coffee-maker/go.mod @@ -1,4 +1,4 @@ -module github.com/qjoly/coffee-shop/coffee-maker +module github.com/qjoly/autocoffee/coffee-maker go 1.22.5 diff --git a/controller/docker-compose.yaml b/controller/docker-compose.yaml index f5cbf0e..c1c6cef 100644 --- a/controller/docker-compose.yaml +++ b/controller/docker-compose.yaml @@ -1,7 +1,7 @@ version: '3.8' services: routes: - image: ghcr.io/une-tasse-de-cafe/coffee-shop/controller:latest + image: ghcr.io/une-tasse-de-cafe/autocoffee/controller:latest build: . environment: - "NATS_URL=192.168.128.51:4222" diff --git a/controller/go.mod b/controller/go.mod index cea4377..29bcbeb 100644 --- a/controller/go.mod +++ b/controller/go.mod @@ -1,4 +1,4 @@ -module github.com/une-tasse-de-cafe/coffee-shop/controller +module github.com/une-tasse-de-cafe/autocoffee/controller go 1.22.6 diff --git a/routes/docker-compose.yaml b/routes/docker-compose.yaml index b7ac5af..da72f86 100644 --- a/routes/docker-compose.yaml +++ b/routes/docker-compose.yaml @@ -1,7 +1,7 @@ version: '3.8' services: routes: - image: ghcr.io/une-tasse-de-cafe/coffee-shop/routes:latest + image: ghcr.io/une-tasse-de-cafe/autocoffee/routes:latest build: . ports: - 8080:8080 diff --git a/routes/go.mod b/routes/go.mod index e93ff0d..a8b688f 100644 --- a/routes/go.mod +++ b/routes/go.mod @@ -1,4 +1,4 @@ -module github.com/une-tasse-de-cafe/coffee-shop/routes +module github.com/une-tasse-de-cafe/autocoffee/routes go 1.21.6 diff --git a/samples/betterSub/go.mod b/samples/betterSub/go.mod deleted file mode 100644 index 752ff9c..0000000 --- a/samples/betterSub/go.mod +++ /dev/null @@ -1,13 +0,0 @@ -module github.com/une-tasse-de-cafe/coffee-shop/samples/betterSub - -go 1.21.6 - -require github.com/nats-io/nats.go v1.37.0 - -require ( - github.com/klauspost/compress v1.17.2 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect -) diff --git a/samples/betterSub/go.sum b/samples/betterSub/go.sum deleted file mode 100644 index ad86381..0000000 --- a/samples/betterSub/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= -github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/samples/betterSub/main.go b/samples/betterSub/main.go deleted file mode 100644 index b8a8490..0000000 --- a/samples/betterSub/main.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "log" - - "github.com/nats-io/nats.go" -) - -func main() { - - nc, err := nats.Connect("192.168.128.51:4222,192.168.128.52:4222,192.168.128.53:4222") - if err != nil { - log.Fatal(err) - } - defer nc.Close() - - if _, err = nc.Subscribe("coffee.*", func(m *nats.Msg) { - fmt.Println("Hello") - fmt.Println(m.Data) - if err != nil { - fmt.Println(err.Error()) - } - - }); err != nil { - log.Fatal(err) - } - - for { - } - -} diff --git a/samples/microService/go.mod b/samples/microService/go.mod deleted file mode 100644 index b0c117d..0000000 --- a/samples/microService/go.mod +++ /dev/null @@ -1,13 +0,0 @@ -module github.com/une-tasse-de-cafe/coffee-shop/samples/microService - -go 1.22.5 - -require github.com/nats-io/nats.go v1.37.0 - -require ( - github.com/klauspost/compress v1.17.2 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect -) diff --git a/samples/microService/go.sum b/samples/microService/go.sum deleted file mode 100644 index ad86381..0000000 --- a/samples/microService/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= -github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/samples/microService/main.go b/samples/microService/main.go deleted file mode 100644 index a381973..0000000 --- a/samples/microService/main.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - "strings" - - "github.com/nats-io/nats.go" - services "github.com/nats-io/nats.go/micro" -) - -func main() { - ctx := context.Background() - - natsUrl := os.Getenv("NATS_URL") - if len(strings.TrimSpace(natsUrl)) == 0 { - natsUrl = "192.168.128.51:4222" - } - fmt.Printf("Echo service using NATS url '%s'\n", natsUrl) - nc, err := nats.Connect(natsUrl) - if err != nil { - panic(err) - } - - // request handler - echoHandler := func(req services.Request) { - req.Respond(req.Data()) - } - - fmt.Println("Starting echo service") - - _, err = services.AddService(nc, services.Config{ - Name: "EchoService", - Version: "1.0.0", - // base handler - Endpoint: &services.EndpointConfig{ - Subject: "svc.echo", - Handler: services.HandlerFunc(echoHandler), - }, - }) - - if err != nil { - panic(err) - } - - <-ctx.Done() -} diff --git a/samples/queueGroup/go.mod b/samples/queueGroup/go.mod deleted file mode 100644 index 16bc2f5..0000000 --- a/samples/queueGroup/go.mod +++ /dev/null @@ -1,13 +0,0 @@ -module github.com/une-tasse-de-cafe/coffee-shop/samples/queueGroup - -go 1.21.6 - -require github.com/nats-io/nats.go v1.37.0 - -require ( - github.com/klauspost/compress v1.17.2 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect -) diff --git a/samples/queueGroup/go.sum b/samples/queueGroup/go.sum deleted file mode 100644 index ad86381..0000000 --- a/samples/queueGroup/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= -github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/samples/queueGroup/main.go b/samples/queueGroup/main.go deleted file mode 100644 index 9cd7d98..0000000 --- a/samples/queueGroup/main.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "fmt" - "log" - - "github.com/nats-io/nats.go" -) - -func main() { - - nc, err := nats.Connect("192.168.128.51:4222,192.168.128.52:4222,192.168.128.53:4222") - if err != nil { - log.Fatal(err) - } - defer nc.Close() - - if _, err := nc.QueueSubscribe("coffee.>", "coffee-maker", func(m *nats.Msg) { - fmt.Println("New order received") - fmt.Println(string(m.Data)) - }); err != nil { - log.Fatal(err) - } - - for { - } - -} diff --git a/samples/request/go.mod b/samples/request/go.mod deleted file mode 100644 index c70eb38..0000000 --- a/samples/request/go.mod +++ /dev/null @@ -1,13 +0,0 @@ -module github.com/une-tasse-de-cafe/coffee-shop/samples/request - -go 1.22.6 - -require github.com/nats-io/nats.go v1.37.0 - -require ( - github.com/klauspost/compress v1.17.2 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect -) diff --git a/samples/request/go.sum b/samples/request/go.sum deleted file mode 100644 index ad86381..0000000 --- a/samples/request/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= -github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/samples/request/main.go b/samples/request/main.go deleted file mode 100644 index a449e02..0000000 --- a/samples/request/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "fmt" - "os" - "time" - - "github.com/nats-io/nats.go" -) - -func main() { - - url := os.Getenv("NATS_URL") - if url == "" { - url = "192.168.128.51:4222" - } - - nc, _ := nats.Connect(url) - defer nc.Drain() - - rep, err := nc.Request("greet.joe", nil, time.Second) - if err != nil { - fmt.Println("Err " + err.Error()) - return - } - fmt.Println(rep) - - fmt.Println(string(rep.Data)) - - rep, _ = nc.Request("greet.sue", nil, time.Second) - fmt.Println(string(rep.Data)) - - rep, _ = nc.Request("greet.bob", nil, time.Second) - fmt.Println(string(rep.Data)) - - //sub.Unsubscribe() - - _, err = nc.Request("greet.joe", nil, time.Second) - fmt.Println(err) -} diff --git a/samples/simplePub/go.mod b/samples/simplePub/go.mod deleted file mode 100644 index a3b390e..0000000 --- a/samples/simplePub/go.mod +++ /dev/null @@ -1,13 +0,0 @@ -module github.com/une-tasse-de-cafe/coffee-shop/samples/simplePub - -go 1.22.6 - -require github.com/nats-io/nats.go v1.37.0 - -require ( - github.com/klauspost/compress v1.17.2 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect -) diff --git a/samples/simplePub/go.sum b/samples/simplePub/go.sum deleted file mode 100644 index ad86381..0000000 --- a/samples/simplePub/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= -github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/samples/simplePub/main.go b/samples/simplePub/main.go deleted file mode 100644 index ca56fd0..0000000 --- a/samples/simplePub/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "github.com/nats-io/nats.go" - "log" -) - -func main() { - - nc, err := nats.Connect("nats://192.168.128.51:4222") - - if err != nil { - log.Fatal(err) - } - - defer nc.Close() - subj, msg := "coffee.krups-01", []byte("{\"size\":\"medium\", \"bean_type\":\"Arabica\", \"name\":\"Quentin\", \"milk\": \"free\", \"sugar_count\":2 }") - nc.Publish(subj, msg) - - nc.Flush() - - if err := nc.LastError(); err != nil { - log.Fatal(err) - } else { - log.Printf("Published [%s] : '%s'\n", subj, msg) - } -} diff --git a/samples/simpleSub/go.mod b/samples/simpleSub/go.mod deleted file mode 100644 index f2967ed..0000000 --- a/samples/simpleSub/go.mod +++ /dev/null @@ -1,13 +0,0 @@ -module github.com/une-tasse-de-cafe/coffee-shop/samples/simpleSub - -go 1.21.6 - -require github.com/nats-io/nats.go v1.37.0 - -require ( - github.com/klauspost/compress v1.17.2 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect -) diff --git a/samples/simpleSub/go.sum b/samples/simpleSub/go.sum deleted file mode 100644 index ad86381..0000000 --- a/samples/simpleSub/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= -github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/samples/simpleSub/main.go b/samples/simpleSub/main.go deleted file mode 100644 index b1bafac..0000000 --- a/samples/simpleSub/main.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "fmt" - "os" - "time" - - "github.com/nats-io/nats.go" -) - -const ( - topic = "coffee.*" -) - -func main() { - - url := os.Getenv("NATS_URL") - if url == "" { - url = "192.168.128.51:4222,192.168.128.52:4222" - } - - nc, _ := nats.Connect(url) - defer nc.Drain() - - fmt.Printf("Listening to topic %s \n", topic) - sub, _ := nc.SubscribeSync(topic) - - msg, _ := sub.NextMsg(10 * time.Minute) - if msg == nil { - fmt.Println("no message received") - os.Exit(1) - } - fmt.Printf("msg data: %q on subject %q\n", string(msg.Data), msg.Subject) - - time.Sleep(10 * time.Second) - msg, _ = sub.NextMsg(10 * time.Minute) - - fmt.Printf("msg data: %q on subject %q\n", string(msg.Data), msg.Subject) - -} diff --git a/samples/stream/go.mod b/samples/stream/go.mod deleted file mode 100644 index 884c112..0000000 --- a/samples/stream/go.mod +++ /dev/null @@ -1,14 +0,0 @@ -module github.com/qjoly/coffee-shop/samples/stream - -go 1.22.5 - -require github.com/nats-io/nats.go v1.37.0 - -require ( - github.com/klauspost/compress v1.17.2 // indirect - github.com/nats-io/nkeys v0.4.7 // indirect - github.com/nats-io/nuid v1.0.1 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/text v0.14.0 // indirect -) diff --git a/samples/stream/go.sum b/samples/stream/go.sum deleted file mode 100644 index f28013d..0000000 --- a/samples/stream/go.sum +++ /dev/null @@ -1,14 +0,0 @@ -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= -github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= -github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= -github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= -github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= diff --git a/samples/stream/main.go b/samples/stream/main.go deleted file mode 100644 index c125b3d..0000000 --- a/samples/stream/main.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "context" - "fmt" - "log" - "os" - "time" - - "github.com/nats-io/nats.go" - "github.com/nats-io/nats.go/jetstream" -) - -const ( - consumerName = "coffee-maker" -) - -func main() { - nc, _ := nats.Connect(os.Getenv("NATS_URL")) - defer nc.Close() - - js, err := jetstream.New(nc) - if err != nil { - log.Fatal(err) - } - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - cfgStream := jetstream.StreamConfig{ - Replicas: 3, - Name: "coffeeorders", - Subjects: []string{"coffee.orders"}, - Storage: jetstream.FileStorage, - Retention: jetstream.InterestPolicy, - AllowDirect: true, - } - - _, err = js.CreateOrUpdateStream(ctx, cfgStream) - if err != nil { - log.Fatal(err) - } - - cfgConsu := jetstream.ConsumerConfig{ - Name: consumerName, - FilterSubject: "coffee.orders", - Durable: consumerName, - } - - cons, err := js.CreateConsumer(ctx, cfgStream.Name, cfgConsu) - if err != nil { - log.Fatal(err) - } - - cc, err := cons.Consume(func(msg jetstream.Msg) { - fmt.Printf("New message from %s : %s - ", msg.Subject(), string(msg.Data())) - msg.Ack() - time.Sleep(500 * time.Millisecond) - fmt.Printf("\n") - }) - - if err != nil { - log.Fatal(err) - } - defer cc.Drain() - - fmt.Println("wait forever") - for { - } -} diff --git a/stock-manager/go.mod b/stock-manager/go.mod index bc4ccbb..77a8583 100644 --- a/stock-manager/go.mod +++ b/stock-manager/go.mod @@ -1,4 +1,4 @@ -module github.com/une-tasse-de-cafe/coffee-shop/stock-manager +module github.com/une-tasse-de-cafe/autocoffee/stock-manager go 1.21.6 diff --git a/stock-manager/main.go b/stock-manager/main.go index 1c1e228..2202e65 100644 --- a/stock-manager/main.go +++ b/stock-manager/main.go @@ -66,12 +66,6 @@ func main() { } } - // Connect to NATS server - url := os.Getenv("NATS_URL") - if url == "" { - url = "192.168.128.51:4222" - } - opt, err := nats.NkeyOptionFromSeed("seed.txt") if err != nil { log.Fatal(err)