From 758504be2f6cfa3560e79e17bdb9dd48b6f31f9a Mon Sep 17 00:00:00 2001 From: Vladislav Filatov Date: Wed, 28 Aug 2024 13:37:14 +0200 Subject: [PATCH 1/5] Add an option to make a persistent interceptor queue (cherry picked from commit cfcaecf2c5674a0915d311b8ced2cc3634383576) --- coyote.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/coyote.go b/coyote.go index fbda297..31819d4 100644 --- a/coyote.go +++ b/coyote.go @@ -110,6 +110,10 @@ func main() { Value: &listen{}, Usage: "Exchange & routing key combinations to listen messages.", }, + &cli.BoolFlag{ + Name: "persistent", + Usage: "Creates the persistent interceptor queue.", + }, &cli.StringFlag{ Name: "queue", Value: "interceptor", @@ -174,17 +178,32 @@ func main() { log.Printf("💔 Terminating AMQP channel") }() + persistent := ctx.Bool("persistent") q, err := ch.QueueDeclare( fmt.Sprintf("%s.%s", ctx.String("queue"), uuid.NewString()), // queue name - false, // is durable - true, // is auto delete - true, // is exclusive - false, // is no wait - nil, // args + false, // is durable + !persistent, // is auto delete + !persistent, // is exclusive + false, // is no wait + nil, // args ) if err != nil { return fmt.Errorf("%s %w", color.RedString("failed to declare a queue:"), err) } + if persistent { + defer func() { + log.Printf("💔 Deleting queue %s", q.Name) + _, err := ch.QueueDelete( + q.Name, + false, // IfUnused: delete only if the queue is unused + false, // IfEmpty: delete only if the queue is empty + false, // NoWait: wait for server confirmation + ) + if err != nil { + log.Fatalf("Failed to delete the queue: %v", err) + } + }() + } for _, c := range ctx.Generic("exchange").(*listen).c { err = ch.ExchangeDeclarePassive( From 5aa8d1a566b972b40c13e4cf0ac008686aa9929c Mon Sep 17 00:00:00 2001 From: Vladislav Filatov Date: Tue, 3 Sep 2024 13:52:40 +0200 Subject: [PATCH 2/5] Add the 'persistent' option to readme (cherry picked from commit 98519176e6197a5d3429c35122f9816cbbbdbbe2) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 428580e..7b0fb95 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ GLOBAL OPTIONS: --insecure Skips certificate verification. (default: false) --noprompt Disables password prompt. (default: false) --silent Disables terminal print. (default: false) + --persistent Creates a persistent interceptor queue. (default: false) --help, -h show help --version, -v print the version ``` From 2810bb5f2023194f35b83701f57fd8aa7d2288cf Mon Sep 17 00:00:00 2001 From: Vladislav Filatov Date: Tue, 3 Sep 2024 15:20:59 +0200 Subject: [PATCH 3/5] Fix tests (cherry picked from commit 322a21240289a81df3440d91397d6133856e73d4) --- coyote.go | 8 ++++---- coyote_test.go | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/coyote.go b/coyote.go index 31819d4..da056b8 100644 --- a/coyote.go +++ b/coyote.go @@ -110,10 +110,6 @@ func main() { Value: &listen{}, Usage: "Exchange & routing key combinations to listen messages.", }, - &cli.BoolFlag{ - Name: "persistent", - Usage: "Creates the persistent interceptor queue.", - }, &cli.StringFlag{ Name: "queue", Value: "interceptor", @@ -135,6 +131,10 @@ func main() { Name: "silent", Usage: "Disables terminal print.", }, + &cli.BoolFlag{ + Name: "persistent", + Usage: "Creates a persistent interceptor queue.", + }, }, Action: func(ctx *cli.Context) error { u, err := url.Parse(ctx.String("url")) diff --git a/coyote_test.go b/coyote_test.go index 9345afd..e4d6a30 100644 --- a/coyote_test.go +++ b/coyote_test.go @@ -148,6 +148,7 @@ GLOBAL OPTIONS: --insecure Skips certificate verification. (default: false) --noprompt Disables password prompt. (default: false) --silent Disables terminal print. (default: false) + --persistent Creates a persistent interceptor queue. (default: false) --help, -h show help --version, -v print the version` ) From 2bb63efe9acf6882ae2a7824af04c51a3477da61 Mon Sep 17 00:00:00 2001 From: Gokhun Celik Date: Tue, 3 Sep 2024 23:02:52 +0200 Subject: [PATCH 4/5] Use queue flag to create persistent queues --- coyote.go | 31 +++++++++---------------------- coyote_test.go | 3 +-- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/coyote.go b/coyote.go index da056b8..8affb86 100644 --- a/coyote.go +++ b/coyote.go @@ -112,8 +112,7 @@ func main() { }, &cli.StringFlag{ Name: "queue", - Value: "interceptor", - Usage: "Interceptor queue name.", + Usage: "Interceptor queue name. If provided, interceptor queue will not be auto deleted.", }, &cli.StringFlag{ Name: "store", @@ -131,10 +130,6 @@ func main() { Name: "silent", Usage: "Disables terminal print.", }, - &cli.BoolFlag{ - Name: "persistent", - Usage: "Creates a persistent interceptor queue.", - }, }, Action: func(ctx *cli.Context) error { u, err := url.Parse(ctx.String("url")) @@ -178,9 +173,15 @@ func main() { log.Printf("💔 Terminating AMQP channel") }() - persistent := ctx.Bool("persistent") + var queueName string + persistent := ctx.IsSet("queue") + if persistent { + queueName = ctx.String("queue") + } else { + queueName = fmt.Sprintf("%s.%s", "coyote", uuid.NewString()) + } q, err := ch.QueueDeclare( - fmt.Sprintf("%s.%s", ctx.String("queue"), uuid.NewString()), // queue name + queueName, // queue name false, // is durable !persistent, // is auto delete !persistent, // is exclusive @@ -190,20 +191,6 @@ func main() { if err != nil { return fmt.Errorf("%s %w", color.RedString("failed to declare a queue:"), err) } - if persistent { - defer func() { - log.Printf("💔 Deleting queue %s", q.Name) - _, err := ch.QueueDelete( - q.Name, - false, // IfUnused: delete only if the queue is unused - false, // IfEmpty: delete only if the queue is empty - false, // NoWait: wait for server confirmation - ) - if err != nil { - log.Fatalf("Failed to delete the queue: %v", err) - } - }() - } for _, c := range ctx.Generic("exchange").(*listen).c { err = ch.ExchangeDeclarePassive( diff --git a/coyote_test.go b/coyote_test.go index e4d6a30..a7c39fb 100644 --- a/coyote_test.go +++ b/coyote_test.go @@ -143,12 +143,11 @@ COMMANDS: GLOBAL OPTIONS: --url value RabbitMQ url, must start with amqps:// or amqp://. --exchange value Exchange & routing key combinations to listen messages. - --queue value Interceptor queue name. (default: "interceptor") + --queue value Interceptor queue name. If provided, interceptor queue will not be auto deleted. --store value SQLite filename to store events. --insecure Skips certificate verification. (default: false) --noprompt Disables password prompt. (default: false) --silent Disables terminal print. (default: false) - --persistent Creates a persistent interceptor queue. (default: false) --help, -h show help --version, -v print the version` ) From f484fad6f32882be9a10e8b8819ad1cb9a2f7202 Mon Sep 17 00:00:00 2001 From: Gokhun Celik Date: Tue, 3 Sep 2024 23:11:01 +0200 Subject: [PATCH 5/5] Update readme --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7b0fb95..4fde26e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Coyote -Coyote is a RabbitMQ message sink. The default routing key is `#` so every message in the given `exchange` is routed to a ephemeral `interceptor` queue. +Coyote is a RabbitMQ message sink. The default routing key is `#` so every message in the given `exchange` is routed to an `interceptor` queue. ## Install @@ -31,7 +31,7 @@ USAGE: --exchange myexchange1,myexchange2=mykey2 # Messages with or without routing keys in multiple exchanges VERSION: - v0.14.0 + v0.16.0 COMMANDS: help, h Shows a list of commands or help for one command @@ -39,12 +39,11 @@ COMMANDS: GLOBAL OPTIONS: --url value RabbitMQ url, must start with amqps:// or amqp://. --exchange value Exchange & routing key combinations to listen messages. - --queue value Interceptor queue name. (default: "interceptor") + --queue value Interceptor queue name. If provided, interceptor queue will not be auto deleted. --store value SQLite filename to store events. --insecure Skips certificate verification. (default: false) --noprompt Disables password prompt. (default: false) --silent Disables terminal print. (default: false) - --persistent Creates a persistent interceptor queue. (default: false) --help, -h show help --version, -v print the version ```