Refactoring Factory RabbitMQ

This commit is contained in:
Mario
2022-06-04 17:44:15 +02:00
parent caf95dc9da
commit c3000493d1

19
main.go
View File

@ -33,9 +33,13 @@ func main() {
if !configured { if !configured {
rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
} }
conn, channel := buildRabbitMQ(rabbitMQURI) conn, err := amqp.Dial(rabbitMQURI)
defer channel.Close() failOnError(err, "Failed to connect to RabbitMQ")
defer conn.Close() defer conn.Close()
channel, err = conn.Channel()
failOnError(err, "Failed to open a channel")
defer channel.Close()
} }
// Init Protocol strategies // Init Protocol strategies
@ -77,6 +81,7 @@ func traceStrategyStdoutAndRabbitMQ(event tracer.Event) {
}).Info("New Event") }).Info("New Event")
if channel != nil { if channel != nil {
log.Debug("Push Event on queue")
eventJSON, err := json.Marshal(event) eventJSON, err := json.Marshal(event)
failOnError(err, "Failed to Marshal Event") failOnError(err, "Failed to Marshal Event")
@ -122,13 +127,3 @@ 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
}