@@ -203,4 +203,65 @@ var _ = Describe("AMQP publisher ", func() {
203203
204204 Expect (connection .Close (context .Background ())).To (BeNil ())
205205 })
206+
207+ It ("Message should durable by default" , func () {
208+ // https://github.com/rabbitmq/rabbitmq-server/pull/13918
209+
210+ // Here we test the default behavior of the message durability
211+ // The lib should set the Header.Durable to true by default
212+ // when the Header is set by the user
213+ // it is up to the user to set the Header.Durable to true or false
214+ connection , err := Dial (context .Background (), "amqp://" , nil )
215+ Expect (err ).To (BeNil ())
216+ Expect (connection ).NotTo (BeNil ())
217+ name := generateNameWithDateTime ("Message should durable by default" )
218+ _ , err = connection .Management ().DeclareQueue (context .Background (), & QuorumQueueSpecification {
219+ Name : name ,
220+ })
221+ Expect (err ).To (BeNil ())
222+
223+ publisher , err := connection .NewPublisher (context .Background (), & QueueAddress {Queue : name }, nil )
224+ Expect (err ).To (BeNil ())
225+ Expect (publisher ).NotTo (BeNil ())
226+
227+ msg := NewMessage ([]byte ("hello" ))
228+ Expect (msg .Header ).To (BeNil ())
229+ publishResult , err := publisher .Publish (context .Background (), msg )
230+ Expect (err ).To (BeNil ())
231+ Expect (publishResult ).NotTo (BeNil ())
232+ Expect (publishResult .Outcome ).To (Equal (& StateAccepted {}))
233+ Expect (msg .Header ).NotTo (BeNil ())
234+ Expect (msg .Header .Durable ).To (BeTrue ())
235+
236+ consumer , err := connection .NewConsumer (context .Background (), name , nil )
237+ Expect (err ).To (BeNil ())
238+ Expect (consumer ).NotTo (BeNil ())
239+ dc , err := consumer .Receive (context .Background ())
240+ Expect (err ).To (BeNil ())
241+ Expect (dc ).NotTo (BeNil ())
242+ Expect (dc .Message ().Header ).NotTo (BeNil ())
243+ Expect (dc .Message ().Header .Durable ).To (BeTrue ())
244+ Expect (dc .Accept (context .Background ())).To (BeNil ())
245+
246+ msgNotPersistent := NewMessage ([]byte ("hello" ))
247+ msgNotPersistent .Header = & amqp.MessageHeader {
248+ Durable : false ,
249+ }
250+ publishResult , err = publisher .Publish (context .Background (), msgNotPersistent )
251+ Expect (err ).To (BeNil ())
252+ Expect (publishResult ).NotTo (BeNil ())
253+ Expect (publishResult .Outcome ).To (Equal (& StateAccepted {}))
254+ Expect (msgNotPersistent .Header ).NotTo (BeNil ())
255+ Expect (msgNotPersistent .Header .Durable ).To (BeFalse ())
256+ dc , err = consumer .Receive (context .Background ())
257+ Expect (err ).To (BeNil ())
258+ Expect (dc ).NotTo (BeNil ())
259+ Expect (dc .Message ().Header ).NotTo (BeNil ())
260+ Expect (dc .Message ().Header .Durable ).To (BeFalse ())
261+ Expect (dc .Accept (context .Background ())).To (BeNil ())
262+ Expect (publisher .Close (context .Background ())).To (BeNil ())
263+ Expect (connection .Management ().DeleteQueue (context .Background (), name )).To (BeNil ())
264+ Expect (connection .Close (context .Background ())).To (BeNil ())
265+
266+ })
206267})
0 commit comments