|
22 | 22 |
|
23 | 23 | import com.rabbitmq.client.Connection;
|
24 | 24 | import com.rabbitmq.client.ConnectionFactory;
|
| 25 | +import com.rabbitmq.stream.Constants; |
25 | 26 | import com.rabbitmq.stream.Environment;
|
26 | 27 | import com.rabbitmq.stream.EnvironmentBuilder;
|
27 | 28 | import com.rabbitmq.stream.OffsetSpecification;
|
|
31 | 32 | import java.util.UUID;
|
32 | 33 | import java.util.concurrent.ConcurrentHashMap;
|
33 | 34 | import java.util.concurrent.CountDownLatch;
|
| 35 | +import java.util.concurrent.atomic.AtomicBoolean; |
| 36 | +import java.util.concurrent.atomic.AtomicInteger; |
34 | 37 | import java.util.concurrent.atomic.AtomicLong;
|
35 | 38 | import java.util.stream.IntStream;
|
36 | 39 | import org.junit.jupiter.api.AfterEach;
|
@@ -175,6 +178,39 @@ void allMessagesSentToSuperStreamWithRoutingKeyRoutingShouldBeThenConsumed() thr
|
175 | 178 | .isEqualTo(messageCount);
|
176 | 179 | }
|
177 | 180 |
|
| 181 | + @Test |
| 182 | + void messageIsNackedIfNoRouteFound() throws Exception { |
| 183 | + int messageCount = 10_000; |
| 184 | + routingKeys = new String[] {"amer", "emea", "apac"}; |
| 185 | + declareSuperStreamTopology(connection, superStream, routingKeys); |
| 186 | + Producer producer = |
| 187 | + environment.producerBuilder().stream(superStream) |
| 188 | + .routing(message -> message.getApplicationProperties().get("region").toString()) |
| 189 | + .key() |
| 190 | + .producerBuilder() |
| 191 | + .build(); |
| 192 | + |
| 193 | + AtomicBoolean confirmed = new AtomicBoolean(true); |
| 194 | + AtomicInteger code = new AtomicInteger(); |
| 195 | + CountDownLatch publishLatch = new CountDownLatch(1); |
| 196 | + producer.send( |
| 197 | + producer |
| 198 | + .messageBuilder() |
| 199 | + .applicationProperties() |
| 200 | + .entry("region", "atlantis") |
| 201 | + .messageBuilder() |
| 202 | + .build(), |
| 203 | + confirmationStatus -> { |
| 204 | + confirmed.set(confirmationStatus.isConfirmed()); |
| 205 | + code.set(confirmationStatus.getCode()); |
| 206 | + publishLatch.countDown(); |
| 207 | + }); |
| 208 | + |
| 209 | + assertThat(latchAssert(publishLatch)).completes(5); |
| 210 | + assertThat(confirmed).isFalse(); |
| 211 | + assertThat(code).hasValue(Constants.CODE_NO_ROUTE_FOUND); |
| 212 | + } |
| 213 | + |
178 | 214 | @Test
|
179 | 215 | void getLastPublishingIdShouldReturnLowestValue() throws Exception {
|
180 | 216 | int messageCount = 10_000;
|
|
0 commit comments