Skip to content

Commit dc65a4e

Browse files
committed
Send msgProps and appProps as integers
if they look like integers...
1 parent 1eddcdd commit dc65a4e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/amqp10/publisher.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ func (p *Amqp10Publisher) Stop(reason string) {
334334
}
335335
}
336336

337+
// maybeConvertToInt converts string values to integers if they look like integers
338+
func maybeConvertToInt(value string) any {
339+
// Try to parse as int64 first
340+
if intVal, err := strconv.ParseInt(value, 10, 64); err == nil {
341+
return intVal
342+
}
343+
// If it's not an integer, return as string
344+
return value
345+
}
346+
337347
func (p *Amqp10Publisher) prepareMessage() *amqp.Message {
338348
utils.UpdatePayload(p.Config.UseMillis, &p.msg)
339349
msg := amqp.NewMessage(p.msg)
@@ -342,7 +352,8 @@ func (p *Amqp10Publisher) prepareMessage() *amqp.Message {
342352
if len(p.Config.Amqp.AppProperties) > 0 {
343353
msg.ApplicationProperties = make(map[string]any)
344354
for key, val := range p.Config.Amqp.AppProperties {
345-
msg.ApplicationProperties[key] = val[metrics.MessagesPublished.Get()%uint64(len(val))]
355+
stringValue := val[metrics.MessagesPublished.Get()%uint64(len(val))]
356+
msg.ApplicationProperties[key] = maybeConvertToInt(stringValue)
346357
}
347358
}
348359

@@ -351,7 +362,8 @@ func (p *Amqp10Publisher) prepareMessage() *amqp.Message {
351362
msg.Annotations = make(map[interface{}]interface{})
352363
}
353364
for key, val := range p.Config.Amqp.MsgAnnotations {
354-
msg.Annotations[key] = val[metrics.MessagesPublished.Get()%uint64(len(val))]
365+
stringValue := val[metrics.MessagesPublished.Get()%uint64(len(val))]
366+
msg.Annotations[key] = maybeConvertToInt(stringValue)
355367
}
356368
}
357369

0 commit comments

Comments
 (0)