Skip to content

Commit

Permalink
chore: add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bxcodec committed Aug 11, 2024
1 parent 218c5ba commit b3af4dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ func handler() interfaces.InboundMessageHandlerFunc {

```

## Advance Setups

### RabbitMQ -- Retry Concept

![Goqueue Retry Architecture RabbitMQ](misc/images/goqueue-retry.png)
Src: [Excalidraw Link](https://link.excalidraw.com/readonly/9sphJpzXzQIAVov3z8G7)

## Contribution

---
Expand Down
7 changes: 4 additions & 3 deletions internal/consumer/rabbitmq/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (r *rabbitMQ) initConsumer() {
r.msgReceiver = receiver
}

// initRetryModule initializes the retry module for the RabbitMQ consumer.
// It declares the retry exchange, dead letter exchange, and retry queues.
// It also binds the dead letter exchange to the original queue and the retry queues to the retry exchange.
func (r *rabbitMQ) initRetryModule() {
// declare retry exchange
err := r.consumerChannel.ExchangeDeclare(
Expand Down Expand Up @@ -380,8 +383,6 @@ func (r *rabbitMQ) requeueMessageWithDLQ(consumerMeta map[string]interface{}, ms
retries++
delayInSeconds := delayFn(retries)
routingKeyPrefixForRetryQueue := getRetryRoutingKey(r.option.QueueName, retries)
// it will publish to each retry queue with TTL is the delayInSeconds
// and there will n dead letter queues based on the limit of retries config
headers := receivedMsg.Headers
headers[headerKey.OriginalTopicName] = msg.Topic
headers[headerKey.OriginalActionName] = msg.Action
Expand All @@ -401,7 +402,7 @@ func (r *rabbitMQ) requeueMessageWithDLQ(consumerMeta map[string]interface{}, ms
Expiration: fmt.Sprintf("%d", delayInSeconds*10000),
},
)
// time.Sleep(5 * time.Second)

if requeueErr != nil {
logrus.WithFields(logrus.Fields{
"consumer_meta": consumerMeta,
Expand Down
Binary file added misc/images/goqueue-retry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b3af4dc

Please sign in to comment.