-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use message headers from rabbitMQ on runners (#62)
* use message headers from rabbitMQ on runners fixes #61 * fix lint issues
- Loading branch information
1 parent
455b376
commit b5e651c
Showing
11 changed files
with
267 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package rabbit | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/leandro-lugaresi/message-cannon/runner" | ||
"github.com/streadway/amqp" | ||
) | ||
|
||
func getHeaders(msg amqp.Delivery) runner.Headers { | ||
headers := runner.Headers{ | ||
"Content-Type": msg.ContentType, | ||
"Content-Encoding": msg.ContentEncoding, | ||
"Correlation-Id": msg.CorrelationId, | ||
"Message-Id": msg.MessageId, | ||
} | ||
for k, v := range msg.Headers { | ||
switch vt := v.(type) { | ||
case int, int16, int32, int64, float32, float64, string, []byte, time.Time, bool: | ||
headers[k] = vt | ||
} | ||
} | ||
xdeaths, ok := msg.Headers["x-death"].([]interface{}) | ||
if ok { | ||
headers["Message-Deaths"] = processDeaths(xdeaths) | ||
} | ||
|
||
return headers | ||
} | ||
|
||
func processDeaths(xdeaths []interface{}) string { | ||
var ( | ||
count, deathCount int64 | ||
) | ||
for _, ideath := range xdeaths { | ||
xdeath, ok := ideath.(amqp.Table) | ||
if !ok { | ||
continue | ||
} | ||
if xdeath["reason"] != "expired" { | ||
count, _ = xdeath["count"].(int64) | ||
deathCount += count | ||
} | ||
} | ||
return strconv.FormatInt(deathCount, 10) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.