diff --git a/filas-aula-2/Evidences/CouldNotProcess.png b/filas-aula-2/Evidences/CouldNotProcess.png new file mode 100644 index 0000000..51a60ff Binary files /dev/null and b/filas-aula-2/Evidences/CouldNotProcess.png differ diff --git a/filas-aula-2/Evidences/InvalidCoupon.png b/filas-aula-2/Evidences/InvalidCoupon.png new file mode 100644 index 0000000..520d22b Binary files /dev/null and b/filas-aula-2/Evidences/InvalidCoupon.png differ diff --git a/filas-aula-2/Evidences/Processed.png b/filas-aula-2/Evidences/Processed.png new file mode 100644 index 0000000..556719c Binary files /dev/null and b/filas-aula-2/Evidences/Processed.png differ diff --git a/filas-aula-2/Evidences/Resultado.png b/filas-aula-2/Evidences/Resultado.png new file mode 100644 index 0000000..b6a68d7 Binary files /dev/null and b/filas-aula-2/Evidences/Resultado.png differ diff --git a/filas-aula-2/README.md b/filas-aula-2/README.md new file mode 100644 index 0000000..317bfc7 --- /dev/null +++ b/filas-aula-2/README.md @@ -0,0 +1,18 @@ +# Desafio 02 + +Foram criadas as filas e exchanges para o RabbitMQ, sendo que, após os testes foram obtidos os seguintes resultados: + +### Execução completa do lote: +![](Evidences/Resultado.png) + +### Cenário de sucesso (Processed): + +![](Evidences/Processed.png) + +### Cenário de falha (Cupom inválido): + +![](Evidences/InvalidCoupon.png) + +### Cenário de falha (Connection error - could not process): + +![](Evidences/CouldNotProcess.png) diff --git a/filas-aula-2/a/Dockerfile b/filas-aula-2/a/Dockerfile new file mode 100644 index 0000000..8217f56 --- /dev/null +++ b/filas-aula-2/a/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.15 + +WORKDIR /go/src/fullcycle + +COPY templates . + +# Install go dependencies +RUN go get github.com/joho/godotenv && \ + go get github.com/wesleywillians/go-rabbitmq/queue + +RUN GOOS=linux go build + +ENTRYPOINT [ "./fullcycle" ] \ No newline at end of file diff --git a/filas-aula-2/b/Dockerfile b/filas-aula-2/b/Dockerfile new file mode 100644 index 0000000..e37e52d --- /dev/null +++ b/filas-aula-2/b/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:1.15.3 + +WORKDIR /go/src/fullcycle + +COPY . . + +RUN GOOS=linux go build b.go + +ENTRYPOINT [ "./b" ] \ No newline at end of file diff --git a/filas-aula-2/b/b.go b/filas-aula-2/b/b.go index 9aa26d0..dd60bc4 100644 --- a/filas-aula-2/b/b.go +++ b/filas-aula-2/b/b.go @@ -2,14 +2,14 @@ package main import ( "encoding/json" - "github.com/joho/godotenv" - uuid "github.com/satori/go.uuid" - "github.com/streadway/amqp" - "github.com/wesleywillians/go-rabbitmq/queue" "io/ioutil" "log" "net/http" "net/url" + "github.com/joho/godotenv" + uuid "github.com/google/uuid" + "github.com/streadway/amqp" + "github.com/wesleywillians/go-rabbitmq/queue" ) type Result struct { @@ -23,7 +23,8 @@ type Order struct { } func NewOrder() Order { - return Order{ID: uuid.NewV4()} + id := uuid.New(); + return Order{ID: id} } const ( diff --git a/filas-aula-2/b/go.mod b/filas-aula-2/b/go.mod new file mode 100644 index 0000000..27f2bfa --- /dev/null +++ b/filas-aula-2/b/go.mod @@ -0,0 +1,11 @@ +module github.com/codeedu/avancadev-micrservice-1dia + +go 1.15 + +require ( + github.com/joho/godotenv v1.3.0 + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + github.com/satori/go.uuid v1.2.0 + github.com/wesleywillians/go-rabbitmq v0.0.0-20201027193450-55e6a80937af + gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect +) \ No newline at end of file diff --git a/filas-aula-2/c/Dockerfile b/filas-aula-2/c/Dockerfile new file mode 100644 index 0000000..6450107 --- /dev/null +++ b/filas-aula-2/c/Dockerfile @@ -0,0 +1,9 @@ +FROM golang:1.15 + +WORKDIR /go/src/fullcycle + +COPY . . + +RUN GOOS=linux go build + +ENTRYPOINT [ "./fullcycle" ] \ No newline at end of file diff --git a/filas-aula-2/c/c.go b/filas-aula-2/c/c.go index 68690b1..a80ac33 100644 --- a/filas-aula-2/c/c.go +++ b/filas-aula-2/c/c.go @@ -54,4 +54,4 @@ func home(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, string(jsonResult)) -} \ No newline at end of file +} diff --git a/filas-aula-2/docker-compose.yaml b/filas-aula-2/docker-compose.yaml index 321a603..672df01 100644 --- a/filas-aula-2/docker-compose.yaml +++ b/filas-aula-2/docker-compose.yaml @@ -1,9 +1,14 @@ version: '3' +volumes: + rabbitdata: + driver: local + services: rabbit: image: "rabbitmq:3-management" + hostname: 'rabbithost' environment: RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG" RABBITMQ_DEFAULT_USER: "rabbitmq" @@ -11,4 +16,28 @@ services: RABBITMQ_DEFAULT_VHOST: "/" ports: - "15672:15672" - - "5672:5672" \ No newline at end of file + - "5672:5672" + volumes: + - rabbitdata:/var/lib/rabbitmq + restart: on-failure + + microservice-a: + build: ./a + ports: + - 9090:9090 + depends_on: + - rabbit + restart: on-failure + + microservice-b: + build: + context: ./b + depends_on: + - rabbit + restart: on-failure + + microservice-c: + build: ./c + ports: + - 9092:9092 + restart: on-failure diff --git a/microsservicos-aula-1/a/a.go b/microsservicos-aula-1/a/a.go deleted file mode 100644 index 3510a55..0000000 --- a/microsservicos-aula-1/a/a.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "encoding/json" - "github.com/hashicorp/go-retryablehttp" - "html/template" - "io/ioutil" - "log" - "net/http" - "net/url" -) - -type Result struct { - Status string -} - -func main() { - http.HandleFunc("/", home) - http.HandleFunc("/process", process) - http.ListenAndServe(":9090", nil) -} - -func home(w http.ResponseWriter, r *http.Request) { - t := template.Must(template.ParseFiles("templates/home.html")) - t.Execute(w, Result{}) -} - -func process(w http.ResponseWriter, r *http.Request) { - - result := makeHttpCall("http://localhost:9091", r.FormValue("coupon"), r.FormValue("cc-number")) - - t := template.Must(template.ParseFiles("templates/home.html")) - t.Execute(w, result) -} - -func makeHttpCall(urlMicroservice string, coupon string, ccNumber string) Result { - - values := url.Values{} - values.Add("coupon", coupon) - values.Add("ccNumber", ccNumber) - - retryClient := retryablehttp.NewClient() - retryClient.RetryMax = 5 - - res, err := retryClient.PostForm(urlMicroservice, values) - if err != nil { - result := Result{Status: "Servidor fora do ar!"} - return result - } - - defer res.Body.Close() - - data, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Fatal("Error processing result") - } - - result := Result{} - - json.Unmarshal(data, &result) - - return result - -} diff --git a/microsservicos-aula-1/a/templates/home.html b/microsservicos-aula-1/a/templates/home.html deleted file mode 100644 index cba777a..0000000 --- a/microsservicos-aula-1/a/templates/home.html +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - Checkout example · Bootstrap - - - - -
-
-

Checkout

-
- - {{ if eq .Status ""}} -
-
-
-

- Carrinho - 1 -

-
    -
  • -
    -
    Tênis Adidas
    -
    - R$ 100,00 -
  • - -
  • - Total - R$ 100,00 -
  • -
- -
- -
-
-
-

Dados pessoais

-
-
- - -
-
- - -
-
- -
- -

Pagamento

- - -
-
- - -
-
- - -
-
-
-
- - - -
-
- - -
-
-
- -
-
-
- {{ else}} -

Resultado da operação: {{ .Status }}

- {{end}} - - - -
- - diff --git a/microsservicos-aula-1/b/b.go b/microsservicos-aula-1/b/b.go deleted file mode 100644 index 38acb90..0000000 --- a/microsservicos-aula-1/b/b.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net/http" - "net/url" -) - -type Result struct { - Status string -} - -func main() { - http.HandleFunc("/", home) - http.ListenAndServe(":9091", nil) -} - -func home(w http.ResponseWriter, r *http.Request) { - coupon := r.PostFormValue("coupon") - ccNumber := r.PostFormValue("ccNumber") - - resultCoupon := makeHttpCall("http://localhost:9092", coupon) - - result := Result{Status: "declined"} - - if ccNumber == "1" { - result.Status = "approved" - } - - if resultCoupon.Status == "invalid" { - result.Status = "invalid coupon" - } - - jsonData, err := json.Marshal(result) - if err != nil { - log.Fatal("Error processing json") - } - - fmt.Fprintf(w, string(jsonData)) -} - - -func makeHttpCall(urlMicroservice string, coupon string) Result { - - values := url.Values{} - values.Add("coupon", coupon) - - res, err := http.PostForm(urlMicroservice, values) - if err != nil { - result := Result{Status: "Servidor fora do ar!"} - return result - } - - defer res.Body.Close() - - data, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Fatal("Error processing result") - } - - result := Result{} - - json.Unmarshal(data, &result) - - return result - -} diff --git a/microsservicos-aula-1/c/c.go b/microsservicos-aula-1/c/c.go deleted file mode 100644 index 68690b1..0000000 --- a/microsservicos-aula-1/c/c.go +++ /dev/null @@ -1,57 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "log" - "net/http" -) - -type Coupon struct { - Code string -} - -type Coupons struct { - Coupon []Coupon -} - -func (c Coupons) Check(code string) string { - for _, item := range c.Coupon { - if code == item.Code { - return "valid" - } - } - return "invalid" -} - -type Result struct { - Status string -} - -var coupons Coupons - -func main() { - coupon := Coupon{ - Code: "abc", - } - - coupons.Coupon = append(coupons.Coupon, coupon) - - http.HandleFunc("/", home) - http.ListenAndServe(":9092", nil) -} - -func home(w http.ResponseWriter, r *http.Request) { - coupon := r.PostFormValue("coupon") - valid := coupons.Check(coupon) - - result := Result{Status: valid} - - jsonResult, err := json.Marshal(result) - if err != nil { - log.Fatal("Error converting json") - } - - fmt.Fprintf(w, string(jsonResult)) - -} \ No newline at end of file diff --git a/microsservicos-aula-1/go.mod b/microsservicos-aula-1/go.mod deleted file mode 100644 index 3937b0c..0000000 --- a/microsservicos-aula-1/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/codeedu/avancadev-micrservice-1dia - -go 1.15 - -require github.com/hashicorp/go-retryablehttp v0.6.7 diff --git a/microsservicos-aula-1/go.sum b/microsservicos-aula-1/go.sum deleted file mode 100644 index 344c0a4..0000000 --- a/microsservicos-aula-1/go.sum +++ /dev/null @@ -1,12 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= -github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-retryablehttp v0.6.7 h1:8/CAEZt/+F7kR7GevNHulKkUjLht3CPmn7egmhieNKo= -github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=