@@ -203,4 +203,62 @@ var _ = Describe("AMQP publisher ", func() {
203
203
204
204
Expect (connection .Close (context .Background ())).To (BeNil ())
205
205
})
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 := NewMessageWithPersistence ([]byte ("hello" ), false )
247
+ publishResult , err = publisher .Publish (context .Background (), msgNotPersistent )
248
+ Expect (err ).To (BeNil ())
249
+ Expect (publishResult ).NotTo (BeNil ())
250
+ Expect (publishResult .Outcome ).To (Equal (& StateAccepted {}))
251
+ Expect (msgNotPersistent .Header ).NotTo (BeNil ())
252
+ Expect (msgNotPersistent .Header .Durable ).To (BeFalse ())
253
+ dc , err = consumer .Receive (context .Background ())
254
+ Expect (err ).To (BeNil ())
255
+ Expect (dc ).NotTo (BeNil ())
256
+ Expect (dc .Message ().Header ).NotTo (BeNil ())
257
+ Expect (dc .Message ().Header .Durable ).To (BeFalse ())
258
+ Expect (dc .Accept (context .Background ())).To (BeNil ())
259
+ Expect (publisher .Close (context .Background ())).To (BeNil ())
260
+ Expect (connection .Management ().DeleteQueue (context .Background (), name )).To (BeNil ())
261
+ Expect (connection .Close (context .Background ())).To (BeNil ())
262
+
263
+ })
206
264
})
0 commit comments