-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Software Architecture in Go: Extensibility - Part 5
Enable build tags and docker args to support Redis. https://youtu.be/Wb24mcqNGD4
- Loading branch information
1 parent
d84bd8f
commit a3e35e0
Showing
7 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:build !rabbitmq | ||
//go:build kafka | ||
|
||
package main | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//go:build !kafka && !rabbitmq | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/go-redis/redis/v8" | ||
|
||
cmdinternal "github.com/MarioCarrion/todo-api/cmd/internal" | ||
"github.com/MarioCarrion/todo-api/internal" | ||
"github.com/MarioCarrion/todo-api/internal/envvar" | ||
internalredis "github.com/MarioCarrion/todo-api/internal/redis" | ||
"github.com/MarioCarrion/todo-api/internal/service" | ||
) | ||
|
||
// RedisMessageBroker represents Redis as a Message Broker. | ||
type RedisMessageBroker struct { | ||
client *redis.Client | ||
publisher service.TaskMessageBrokerPublisher | ||
} | ||
|
||
// NewMessageBrokerPublisher initializes a new Redis Broker. | ||
func NewMessageBrokerPublisher(conf *envvar.Configuration) (MessageBrokerPublisher, error) { //nolint: ireturn | ||
producer, err := cmdinternal.NewRedis(conf) | ||
if err != nil { | ||
return nil, internal.WrapErrorf(err, internal.ErrorCodeUnknown, "internal.NewRedis") | ||
} | ||
|
||
return &RedisMessageBroker{ | ||
client: producer, | ||
publisher: internalredis.NewTask(producer), | ||
}, nil | ||
} | ||
|
||
// Publisher returns the Redis broker. | ||
func (m *RedisMessageBroker) Publisher() service.TaskMessageBrokerPublisher { //nolint: ireturn | ||
return m.publisher | ||
} | ||
|
||
// Close closes the broker. | ||
func (m *RedisMessageBroker) Close() error { | ||
if err := m.client.Close(); err != nil { | ||
return internal.WrapErrorf(err, internal.ErrorCodeUnknown, "producer.Close") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
services: | ||
rest-server-redis: | ||
extends: | ||
file: compose.common.yml | ||
service: rest-server-common | ||
build: | ||
args: | ||
TAG: redis | ||
environment: | ||
REDIS_HOST: redis:6379 | ||
depends_on: | ||
redis: | ||
condition: service_healthy | ||
elasticsearch-indexer-redis: | ||
extends: | ||
file: compose.common.yml | ||
service: elasticsearch-indexer-common | ||
build: | ||
dockerfile: ./dockerfiles/elasticsearch-indexer-redis.Dockerfile | ||
environment: | ||
REDIS_HOST: redis:6379 | ||
depends_on: | ||
redis: | ||
condition: service_healthy | ||
redis: | ||
image: redis:7.0.9-alpine3.17 | ||
ports: | ||
- 6379:6379 | ||
healthcheck: | ||
test: ["CMD-SHELL", "redis-cli ping || exit 1"] | ||
interval: 20s | ||
timeout: 1s | ||
retries: 5 |