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
|
||||
logsPath: ./logs
|
||||
tracing:
|
||||
rabbitMQEnabled: true
|
||||
rabbitMQEnabled: false
|
||||
rabbitMQURI: ""
|
||||
|
@ -6,7 +6,7 @@ services:
|
||||
#network_mode: host # Not work on Mac OS
|
||||
container_name: beelzebub
|
||||
restart: always
|
||||
ports: # Remove me, if use configuration network_mode: host
|
||||
ports: # Remove me, if you use configuration network_mode: host
|
||||
- "22:22"
|
||||
- "8080:8080"
|
||||
- "80:80"
|
||||
@ -16,13 +16,3 @@ services:
|
||||
- rabbitmq
|
||||
volumes:
|
||||
- "./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/")
|
||||
|
||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||
failOnError(err, fmt.Sprintf("Error during coreConfigurations: "))
|
||||
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsCore: "))
|
||||
|
||||
fileLogs := configureLoggingByConfigurations(coreConfigurations.Core.Logging)
|
||||
defer fileLogs.Close()
|
||||
@ -33,13 +33,9 @@ func main() {
|
||||
if !configured {
|
||||
rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
|
||||
}
|
||||
conn, err := amqp.Dial(rabbitMQURI)
|
||||
failOnError(err, "Failed to connect to RabbitMQ")
|
||||
defer conn.Close()
|
||||
|
||||
channel, err = conn.Channel()
|
||||
failOnError(err, "Failed to open a channel")
|
||||
conn, channel := buildRabbitMQ(rabbitMQURI)
|
||||
defer channel.Close()
|
||||
defer conn.Close()
|
||||
}
|
||||
|
||||
// Init Protocol strategies
|
||||
@ -126,3 +122,13 @@ func configureLoggingByConfigurations(configurations parser.Logging) *os.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