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: + + +### Cenário de sucesso (Processed): + + + +### Cenário de falha (Cupom inválido): + + + +### Cenário de falha (Connection error - could not process): + + 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 @@ - - -
- - - -