Skip to content

Commit

Permalink
Fix consumer connection
Browse files Browse the repository at this point in the history
  • Loading branch information
muhfaris committed Dec 26, 2019
1 parent 64996e7 commit b7c1f90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
23 changes: 16 additions & 7 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ConfigRabbitMQArgument struct {
Vhost string
AutoReconnect bool
ExitOnErr bool
Type string

QueueConfig QueueConfig
QueueBind QueueBindConfig
Expand Down Expand Up @@ -76,6 +77,10 @@ func NewQueue(cfg ConfigRabbitMQArgument) *ConfigRabbitMQArgument {
queue.url = queue.getURL()
queue.consumers = make([]messageConsumer, 0)

if queue.Type == "" {
log.Fatalln("Error client type is empty")
}

queue.connect()
go queue.reconnector()
return &queue
Expand Down Expand Up @@ -147,10 +152,12 @@ func (q *ConfigRabbitMQArgument) reconnector() {
logError("Reconnecting after connection closed", err)

q.connect()
q.declareExchangeQueue()
q.declareQueue()
q.bindingQueue()
q.recoverConsumers()
if q.Type == ClientConsumerType {
q.declareExchangeQueue()
q.declareQueue()
q.bindingQueue()
q.recoverConsumers()
}
}
}
}
Expand All @@ -167,9 +174,11 @@ func (q *ConfigRabbitMQArgument) connect() {
log.Println("Connection established!")

q.openChannel()
q.declareExchangeQueue()
q.declareQueue()
q.bindingQueue()
if q.Type == ClientConsumerType {
q.declareExchangeQueue()
q.declareQueue()
q.bindingQueue()
}

return
}
Expand Down
9 changes: 9 additions & 0 deletions constanta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package fmq

const (
// ClientConsumerType tipe client rabbitnya sebagai consumer
ClientConsumerType = "CONSUMER"

// ClientProducerType tipe client rabbitnya sebagai producer
ClientProducerType = "PRODUCER"
)

0 comments on commit b7c1f90

Please sign in to comment.