mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Refactoring Factory RabbitMQ
This commit is contained in:
@ -5,5 +5,5 @@ core:
|
|||||||
logDisableTimestamp: true
|
logDisableTimestamp: true
|
||||||
logsPath: ./logs
|
logsPath: ./logs
|
||||||
tracing:
|
tracing:
|
||||||
rabbitMQEnabled: true
|
rabbitMQEnabled: false
|
||||||
rabbitMQURI: ""
|
rabbitMQURI: ""
|
||||||
|
@ -6,7 +6,7 @@ services:
|
|||||||
#network_mode: host # Not work on Mac OS
|
#network_mode: host # Not work on Mac OS
|
||||||
container_name: beelzebub
|
container_name: beelzebub
|
||||||
restart: always
|
restart: always
|
||||||
ports: # Remove me, if use configuration network_mode: host
|
ports: # Remove me, if you use configuration network_mode: host
|
||||||
- "22:22"
|
- "22:22"
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
- "80:80"
|
- "80:80"
|
||||||
@ -16,13 +16,3 @@ services:
|
|||||||
- rabbitmq
|
- rabbitmq
|
||||||
volumes:
|
volumes:
|
||||||
- "./configurations:/configurations"
|
- "./configurations:/configurations"
|
||||||
|
|
||||||
rabbitmq:
|
|
||||||
image: rabbitmq:3-management-alpine
|
|
||||||
container_name: 'rabbitmq'
|
|
||||||
ports:
|
|
||||||
- "5672:5672"
|
|
||||||
- "15672:15672"
|
|
||||||
environment:
|
|
||||||
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
|
|
||||||
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
|
|
20
main.go
20
main.go
@ -20,7 +20,7 @@ func main() {
|
|||||||
parser := parser.Init("./configurations/beelzebub.yaml", "./configurations/services/")
|
parser := parser.Init("./configurations/beelzebub.yaml", "./configurations/services/")
|
||||||
|
|
||||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||||
failOnError(err, fmt.Sprintf("Error during coreConfigurations: "))
|
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsCore: "))
|
||||||
|
|
||||||
fileLogs := configureLoggingByConfigurations(coreConfigurations.Core.Logging)
|
fileLogs := configureLoggingByConfigurations(coreConfigurations.Core.Logging)
|
||||||
defer fileLogs.Close()
|
defer fileLogs.Close()
|
||||||
@ -33,13 +33,9 @@ func main() {
|
|||||||
if !configured {
|
if !configured {
|
||||||
rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
|
rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
|
||||||
}
|
}
|
||||||
conn, err := amqp.Dial(rabbitMQURI)
|
conn, channel := buildRabbitMQ(rabbitMQURI)
|
||||||
failOnError(err, "Failed to connect to RabbitMQ")
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
channel, err = conn.Channel()
|
|
||||||
failOnError(err, "Failed to open a channel")
|
|
||||||
defer channel.Close()
|
defer channel.Close()
|
||||||
|
defer conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init Protocol strategies
|
// Init Protocol strategies
|
||||||
@ -126,3 +122,13 @@ func configureLoggingByConfigurations(configurations parser.Logging) *os.File {
|
|||||||
}
|
}
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildRabbitMQ(rabbitMQURI string) (*amqp.Connection, *amqp.Channel) {
|
||||||
|
conn, err := amqp.Dial(rabbitMQURI)
|
||||||
|
failOnError(err, "Failed to init Dial rabbitMQ")
|
||||||
|
|
||||||
|
channel, err := conn.Channel()
|
||||||
|
failOnError(err, "Failed to connect on Channel")
|
||||||
|
|
||||||
|
return conn, channel
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user