Compare commits

...

2 Commits

Author SHA1 Message Date
Naoki Kosaka da16b3da58 Update compose. 2021-10-17 23:22:09 +09:00
Naoki Kosaka 773f5e28ec Support AMQP Protocol. 2021-10-17 22:41:53 +09:00
6 changed files with 34 additions and 8 deletions

View File

@ -7,6 +7,10 @@ services:
test: ["CMD", "redis-cli", "ping"]
volumes:
- "./redisdata:/data"
# rabbitmq:
# restart: always
# image: rabbitmq:alpine
worker:
build: .
@ -20,6 +24,7 @@ services:
- "./config.yml:/var/lib/relay/config.yml"
depends_on:
- redis
# - rabbitmq
server:
build: .
@ -33,3 +38,4 @@ services:
- "./config.yml:/var/lib/relay/config.yml"
depends_on:
- redis
# - rabbitmq

View File

@ -123,7 +123,6 @@ func buildCommand() *cobra.Command {
func initConfig(cmd *cobra.Command) {
if verbose {
logrus.SetLevel(logrus.DebugLevel)
fmt.Println("DEBUG VIEW")
}
configPath := cmd.Flag("config").Value.String()
@ -137,6 +136,7 @@ func initConfig(cmd *cobra.Command) {
logrus.Warn("Config file not exist. Use environment variables.")
viper.BindEnv("ACTOR_PEM")
viper.BindEnv("BROKER_URL")
viper.BindEnv("REDIS_URL")
viper.BindEnv("RELAY_BIND")
viper.BindEnv("RELAY_DOMAIN")

View File

@ -1,4 +1,5 @@
# ACTOR_PEM: FILL_WITH_EACH_TEST
# BROKER_URL: FILL_WITH_EACH_TEST
# REDIS_URL: FILL_WITH_EACH_TEST
RELAY_BIND: 0.0.0.0:8080

View File

@ -19,7 +19,8 @@ type RelayConfig struct {
actorKey *rsa.PrivateKey
domain *url.URL
redisClient *redis.Client
redisURL string
brokerURL *url.URL
redisURL *url.URL
serverBind string
serviceName string
serviceSummary string
@ -57,8 +58,11 @@ func NewRelayConfig() (*RelayConfig, error) {
return nil, errors.New("ACTOR_PEM: " + err.Error())
}
redisURL := viper.GetString("REDIS_URL")
redisOption, err := redis.ParseURL(redisURL)
redisURL, err := url.ParseRequestURI(viper.GetString("REDIS_URL"))
if err != nil {
return nil, errors.New("REDIS_URL: " + err.Error())
}
redisOption, err := redis.ParseURL(redisURL.String())
if err != nil {
return nil, errors.New("REDIS_URL: " + err.Error())
}
@ -68,12 +72,19 @@ func NewRelayConfig() (*RelayConfig, error) {
return nil, errors.New("Redis Connection Test: " + err.Error())
}
brokerURL, err := url.ParseRequestURI(viper.GetString("BROKER_URL"))
if err != nil {
logrus.Warn("BROKER_URL: INVALID OR EMPTY. USE REDIS_URL.")
brokerURL = redisURL
}
serverBind := viper.GetString("RELAY_BIND")
return &RelayConfig{
actorKey: privateKey,
domain: domain,
redisClient: redisClient,
brokerURL: brokerURL,
redisURL: redisURL,
serverBind: serverBind,
serviceName: viper.GetString("RELAY_SERVICENAME"),
@ -120,19 +131,25 @@ func (relayConfig *RelayConfig) DumpWelcomeMessage(moduleName string, version st
- Configuration
RELAY NAME : %s
RELAY DOMAIN : %s
BROKER URL : %s
REDIS URL : %s
BIND ADDRESS : %s
JOB_CONCURRENCY : %s
`, version, moduleName, relayConfig.serviceName, relayConfig.domain.Host, relayConfig.redisURL, relayConfig.serverBind, strconv.Itoa(relayConfig.jobConcurrency))
`, version, moduleName, relayConfig.serviceName, relayConfig.domain.Host, relayConfig.brokerURL, relayConfig.redisURL, relayConfig.serverBind, strconv.Itoa(relayConfig.jobConcurrency))
}
// NewMachineryServer create Redis backed Machinery Server from RelayConfig.
func NewMachineryServer(globalConfig *RelayConfig) (*machinery.Server, error) {
cnf := &config.Config{
Broker: globalConfig.redisURL,
Broker: globalConfig.brokerURL.String(),
DefaultQueue: "relay",
ResultBackend: globalConfig.redisURL,
ResultBackend: globalConfig.redisURL.String(),
ResultsExpireIn: 1,
AMQP: &config.AMQPConfig{
Exchange: "relay_exchange",
ExchangeType: "direct",
BindingKey: "relay_task",
},
}
newServer, err := machinery.NewServer(cnf)

View File

@ -88,7 +88,7 @@ func TestRelayConfig_DumpWelcomeMessage(t *testing.T) {
"module NAME": "Testing",
"RELAY NANE": relayConfig.serviceName,
"RELAY DOMAIN": relayConfig.domain.Host,
"REDIS URL": relayConfig.redisURL,
"REDIS URL": relayConfig.redisURL.String(),
"BIND ADDRESS": relayConfig.serverBind,
}

View File

@ -46,6 +46,7 @@ relay --config /path/to/config.yml control
```yaml config.yml
ACTOR_PEM: /var/lib/relay/actor.pem
# BROKER_URL: amqp://guest:guest@rabbitmq:5672 # IF EMPTY, USE REDIS_URL
REDIS_URL: redis://redis:6379
RELAY_BIND: 0.0.0.0:8080
@ -63,6 +64,7 @@ JOB_CONCURRENCY: 50
This is **Optional** : When `config.yml` not exists, use environment variable.
- ACTOR_PEM
- BROKER_URL
- REDIS_URL
- RELAY_BIND
- RELAY_DOMAIN