@@ -151,5 +151,42 @@ await topologyManager.CreateQueueAsync(new QueueConfiguration
151151
152152 Assert . Equal ( "foo2" , ( await newQueue1Consumer . ReceiveAsync ( CancellationToken ) ) . GetBody < string > ( ) ) ;
153153 }
154+
155+ [ Fact ]
156+ public async Task Should_create_last_value_queue ( )
157+ {
158+ var connection = await CreateConnection ( ) ;
159+ var address = Guid . NewGuid ( ) . ToString ( ) ;
160+ var queue = Guid . NewGuid ( ) . ToString ( ) ;
161+ var lastValueKey = "my-last-value-key" ;
162+
163+ var topologyManager = await connection . CreateTopologyManagerAsync ( ) ;
164+ await topologyManager . CreateAddressAsync ( address , RoutingType . Multicast ) ;
165+ await topologyManager . CreateQueueAsync ( new QueueConfiguration
166+ {
167+ Address = address ,
168+ Name = queue ,
169+ RoutingType = RoutingType . Multicast ,
170+ LastValueKey = lastValueKey
171+ } ) ;
172+
173+ var producer = await connection . CreateProducerAsync ( address , RoutingType . Multicast ) ;
174+
175+ // Send series of messages with the same last value key
176+ await producer . SendAsync ( new Message ( "foo1" ) { ApplicationProperties = { [ lastValueKey ] = "1" } } ) ;
177+ await producer . SendAsync ( new Message ( "foo2" ) { ApplicationProperties = { [ lastValueKey ] = "1" } } ) ;
178+ await producer . SendAsync ( new Message ( "foo3" ) { ApplicationProperties = { [ lastValueKey ] = "1" } } ) ;
179+
180+ // Send series of messages with another last value key
181+ await producer . SendAsync ( new Message ( "foo4" ) { ApplicationProperties = { [ lastValueKey ] = "2" } } ) ;
182+ await producer . SendAsync ( new Message ( "foo5" ) { ApplicationProperties = { [ lastValueKey ] = "2" } } ) ;
183+ await producer . SendAsync ( new Message ( "foo6" ) { ApplicationProperties = { [ lastValueKey ] = "2" } } ) ;
184+
185+ var consumer = await connection . CreateConsumerAsync ( address , queue , CancellationToken ) ;
186+
187+ // Only messages foo3 and foo6 should survive
188+ Assert . Equal ( "foo3" , ( await consumer . ReceiveAsync ( CancellationToken ) ) . GetBody < string > ( ) ) ;
189+ Assert . Equal ( "foo6" , ( await consumer . ReceiveAsync ( CancellationToken ) ) . GetBody < string > ( ) ) ;
190+ }
154191 }
155192}
0 commit comments