Skip to content

Commit 942d0c9

Browse files
author
Felipe
committed
Added Image
1 parent b5e57b3 commit 942d0c9

File tree

8 files changed

+94
-19
lines changed

8 files changed

+94
-19
lines changed

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.13-alpine as builder
2+
ENV GOPATH="$HOME/go"
3+
RUN apk --no-cache add git
4+
WORKDIR $GOPATH/src
5+
6+
COPY . $GOPATH/src
7+
8+
RUN go get -d -v golang.org/x/net/html
9+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app consumer/*.go
10+
11+
12+
FROM alpine:latest
13+
RUN apk --no-cache add ca-certificates
14+
WORKDIR /root/
15+
16+
COPY --from=builder $HOME/go/src/app .
17+
CMD ["./app"]

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
docker:
2+
@docker-compose down
3+
@docker-compose build
4+
@docker-compose up -d
5+
6+
dockerdown:
7+
@docker-compose down
8+
9+
build:
10+
@echo "---- Building Application ----"
11+
@go build -o consumer consumer/*.go
12+
@go build -o producer producer/*.go
13+
14+
consume:
15+
@echo "---- Running Consumer ----"
16+
@export REDIS_HOST=localhost
17+
@export STREAM=events
18+
#@export GROUP=GroupOne
19+
@go run consumer/*.go
20+
21+
run:
22+
@echo "---- Running Producer ----"
23+
@export REDIS_HOST=localhost
24+
@export STREAM=events
25+
@go run producer/*.go

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ O Redis tem estratégias para guardar os dados em memória e em disco, garantind
1111

1212
# Redis Streams para Mensageria (ou Messaging)
1313

14+
![Design of flow](/media/flow.png)
15+
1416
**Pontos Positivos**
1517

1618
- Suporta Topicos e Filas

consumer/main.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ import (
1717
uuid "github.com/satori/go.uuid"
1818
)
1919

20-
const (
21-
streamName = "events"
22-
consumerGroup = "consumersOne"
23-
)
24-
2520
var (
26-
waitGrp sync.WaitGroup
27-
mutex sync.Mutex
28-
client *redis.Client
29-
start string = ">" //"0" //"0-0" //"-"
30-
consumerName string = uuid.NewV4().String()
21+
waitGrp sync.WaitGroup
22+
mutex sync.Mutex
23+
client *redis.Client
24+
start string = ">"
25+
streamName string = os.Getenv("STREAM")
26+
consumerGroup string = os.Getenv("GROUP")
27+
consumerName string = uuid.NewV4().String()
3128
)
3229

3330
func init() {
@@ -187,5 +184,5 @@ func processStream(stream redis.XMessage, retry bool, handlerFactory func(t even
187184
//client.XDel(streamName, stream.ID)
188185
client.XAck(streamName, consumerGroup, stream.ID)
189186

190-
//time.Sleep(3 * time.Second)
187+
//time.Sleep(2 * time.Second)
191188
}

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3'
2+
3+
services:
4+
redis:
5+
image: redis:alpine
6+
container_name: redis-srv
7+
ports:
8+
- 6379:6379
9+
10+
redis-commander:
11+
container_name: redis-commander-web
12+
hostname: redis-commander
13+
image: rediscommander/redis-commander:latest
14+
restart: always
15+
environment:
16+
- REDIS_HOSTS=local:redis:6379
17+
ports:
18+
- "8081:8081"
19+
20+
consumer:
21+
container_name: go-consumer
22+
build: '.'
23+
environment:
24+
REDIS_HOST: redis
25+
STREAM: events
26+
GROUP: GroupOne
27+
depends_on:
28+
- redis
29+
ports:
30+
- '8088:8088'
31+
restart: always

media/flow.png

30.3 KB
Loading

packages/utils/utils.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package utils
22

3-
import "github.com/go-redis/redis/v7"
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/go-redis/redis/v7"
8+
)
49

510
//NewRedisClient create a new instace of client redis
611
func NewRedisClient() (*redis.Client, error) {
712
client := redis.NewClient(&redis.Options{
8-
//Addr: "redis-14450.c1.asia-northeast1-1.gce.cloud.redislabs.com:14450",
9-
//Password: "37uaACndCvuQ1heADnHkishnAhMmosWq", // no password set
10-
Addr: "localhost:6379",
13+
Addr: fmt.Sprintf("%s:6379", os.Getenv("REDIS_HOST")),
1114
Password: "",
1215
DB: 0, // use default DB
1316
})

producer/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ package main
33
import (
44
"fmt"
55
"math/rand"
6+
"os"
67
"time"
78

89
evt "github.com/felipeagger/go-redis-streams/packages/event"
910
"github.com/felipeagger/go-redis-streams/packages/utils"
1011
"github.com/go-redis/redis/v7"
1112
)
1213

13-
const (
14-
streamName = "events"
14+
var (
15+
streamName string = os.Getenv("STREAM")
16+
client *redis.Client
1517
)
1618

17-
var client *redis.Client
18-
1919
func init() {
2020
var err error
2121
client, err = utils.NewRedisClient()

0 commit comments

Comments
 (0)