@@ -7,26 +7,28 @@ import (
77 "time"
88
99 "github.com/42atomys/webhooked/internal/valuable"
10+ amqp "github.com/rabbitmq/amqp091-go"
1011 "github.com/rs/zerolog/log"
11- "github.com/streadway/amqp"
1212)
1313
1414type RabbitmqStorageSpec struct {
15- DatabaseURL valuable.Valuable `mapstructure:"databaseUrl" json:"databaseUrl"`
16- QueueName string `mapstructure:"queueName" json:"queueName"`
17- DefinedContentType string `mapstructure:"contentType" json:"contentType"`
18- Durable bool `mapstructure:"durable" json:"durable"`
19- DeleteWhenUnused bool `mapstructure:"deleteWhenUnused" json:"deleteWhenUnused"`
20- Exclusive bool `mapstructure:"exclusive" json:"exclusive"`
21- NoWait bool `mapstructure:"noWait" json:"noWait"`
22- Mandatory bool `mapstructure:"mandatory" json:"mandatory"`
23- Immediate bool `mapstructure:"immediate" json:"immediate"`
24- Exchange string `mapstructure:"exchange" json:"exchange"`
25- MaxAttempt int `mapstructure:"maxAttempt" json:"maxAttempt"`
26-
27- client * amqp.Connection
28- channel * amqp.Channel
29- routingKey amqp.Queue
15+ DatabaseURL valuable.Valuable `mapstructure:"databaseUrl" json:"databaseUrl"`
16+ MaxAttempt int `mapstructure:"maxAttempt" json:"maxAttempt"`
17+ // QueueDeclare
18+ QueueName string `mapstructure:"queueName" json:"queueName"`
19+ Durable * bool `mapstructure:"durable" json:"durable"`
20+ DeleteWhenUnused bool `mapstructure:"deleteWhenUnused" json:"deleteWhenUnused"`
21+ Exclusive bool `mapstructure:"exclusive" json:"exclusive"`
22+ NoWait bool `mapstructure:"noWait" json:"noWait"`
23+ // Publish
24+ Exchange string `mapstructure:"exchange" json:"exchange"`
25+ DefinedContentType string `mapstructure:"contentType" json:"contentType"`
26+ Mandatory bool `mapstructure:"mandatory" json:"mandatory"`
27+ Immediate bool `mapstructure:"immediate" json:"immediate"`
28+
29+ client * amqp.Connection
30+ channel * amqp.Channel
31+ queue amqp.Queue
3032}
3133
3234func (s * RabbitmqStorageSpec ) EnsureConfigurationCompleteness () error {
@@ -38,6 +40,11 @@ func (s *RabbitmqStorageSpec) EnsureConfigurationCompleteness() error {
3840 s .MaxAttempt = 5
3941 }
4042
43+ if s .Durable == nil {
44+ durable := true
45+ s .Durable = & durable
46+ }
47+
4148 return nil
4249}
4350
@@ -61,9 +68,9 @@ func (s *RabbitmqStorageSpec) Initialize() error {
6168 }
6269 }()
6370
64- if s .routingKey , err = s .channel .QueueDeclare (
71+ if s .queue , err = s .channel .QueueDeclare (
6572 s .QueueName ,
66- s .Durable ,
73+ * s .Durable ,
6774 s .DeleteWhenUnused ,
6875 s .Exclusive ,
6976 s .NoWait ,
@@ -77,9 +84,10 @@ func (s *RabbitmqStorageSpec) Initialize() error {
7784
7885func (s * RabbitmqStorageSpec ) Store (ctx context.Context , value []byte ) error {
7986 for attempt := 0 ; attempt < s .MaxAttempt ; attempt ++ {
80- err := s .channel .Publish (
87+ err := s .channel .PublishWithContext (
88+ ctx ,
8189 s .Exchange ,
82- s .routingKey .Name ,
90+ s .queue .Name ,
8391 s .Mandatory ,
8492 s .Immediate ,
8593 amqp.Publishing {
0 commit comments