Skip to content

Commit

Permalink
Add --amqp-to
Browse files Browse the repository at this point in the history
Allows to use the anonymous terminus
  • Loading branch information
mkuratczyk committed Dec 17, 2024
1 parent a982571 commit c91403b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func RootCmd() *cobra.Command {
"AMQP application properties, eg. key1=val1,val2")
amqpPublisherFlags.StringSliceVar(&cfg.Amqp.Subjects, "amqp-subject", []string{},
"AMQP 1.0 message subject(s)")
amqpPublisherFlags.StringSliceVar(&cfg.Amqp.To, "amqp-to", []string{},
"AMQP 1.0 message To field (required for the anonymous terminus)")
amqpPublisherFlags.BoolVar(&cfg.Amqp.SendSettled, "amqp-send-settled", false,
"Send settled messages (fire and forget)")

Expand Down
7 changes: 6 additions & 1 deletion pkg/amqp10/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ func (p *Amqp10Publisher) Stop(reason string) {
func (p *Amqp10Publisher) prepareMessage() *amqp.Message {
utils.UpdatePayload(p.Config.UseMillis, &p.msg)
msg := amqp.NewMessage(p.msg)
msg.Properties = &amqp.MessageProperties{}

if len(p.Config.Amqp.AppProperties) > 0 {
msg.ApplicationProperties = make(map[string]any)
Expand All @@ -341,7 +342,11 @@ func (p *Amqp10Publisher) prepareMessage() *amqp.Message {
}

if len(p.Config.Amqp.Subjects) > 0 {
msg.Properties = &amqp.MessageProperties{Subject: &p.Config.Amqp.Subjects[metrics.MessagesPublished.Get()%uint64(len(p.Config.Amqp.Subjects))]}
msg.Properties.Subject = &p.Config.Amqp.Subjects[metrics.MessagesPublished.Get()%uint64(len(p.Config.Amqp.Subjects))]
}

if len(p.Config.Amqp.To) > 0 {
msg.Properties.To = &p.Config.Amqp.To[metrics.MessagesPublished.Get()%uint64(len(p.Config.Amqp.To))]
}

if p.Config.StreamFilterValueSet != "" {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var QueueTypes = map[QueueType][]string{

type AmqpOptions struct {
Subjects []string
To []string
SendSettled bool
ReleaseRate int
RejectRate int
Expand Down

0 comments on commit c91403b

Please sign in to comment.