Skip to content

Commit c898b3c

Browse files
committed
feat(queueType): Allow to set queueType from client
1 parent 0756b75 commit c898b3c

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

async/async-rabbit/src/main/java/org/reactivecommons/async/rabbit/InstanceIdentifier.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@
33
import lombok.AccessLevel;
44
import lombok.NoArgsConstructor;
55

6+
import java.util.UUID;
7+
68
@NoArgsConstructor(access = AccessLevel.PRIVATE)
79
public class InstanceIdentifier {
10+
private static final String INSTANCE_ID = UUID.randomUUID().toString().replace("-", "");
11+
812
public static String getInstanceId(String kind) {
13+
return getInstanceId(kind, INSTANCE_ID);
14+
}
15+
16+
public static String getInstanceId(String kind, String defaultHost) {
917
String host = System.getenv("HOSTNAME");
1018
if (host == null || host.isEmpty()) {
11-
return kind;
19+
return defaultHost + "-" + kind;
1220
}
1321
return host + "-" + kind;
1422
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.reactivecommons.async.rabbit;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
class InstanceIdentifierTest {
8+
9+
@Test
10+
void shouldGetInstanceIdFromUuid() {
11+
String instanceId = InstanceIdentifier.getInstanceId("events");
12+
var expectedLength = 39;
13+
assertThat(instanceId).endsWith("-events").hasSize(expectedLength);
14+
}
15+
16+
@Test
17+
void shouldGetInstanceIdFromEnv() {
18+
String instanceId = InstanceIdentifier.getInstanceId("events", "host123");
19+
assertThat(instanceId).isEqualTo("host123-events");
20+
}
21+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.reactivecommons.async.rabbit.communications;
2+
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.Test;
5+
import org.junit.jupiter.api.extension.ExtendWith;
6+
import org.mockito.Mock;
7+
import org.mockito.junit.jupiter.MockitoExtension;
8+
import reactor.rabbitmq.QueueSpecification;
9+
import reactor.rabbitmq.Sender;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
@ExtendWith(MockitoExtension.class)
14+
class TopologyCreatorTest {
15+
@Mock
16+
private Sender sender;
17+
18+
private TopologyCreator creator;
19+
20+
@BeforeEach
21+
void setUp() {
22+
creator = new TopologyCreator(sender, "quorum");
23+
}
24+
25+
@Test
26+
void shouldInjectQueueType() {
27+
QueueSpecification spec = creator.fillQueueType(QueueSpecification.queue("durable"));
28+
assertThat(spec.getArguments()).containsEntry("x-queue-type", "quorum");
29+
}
30+
31+
@Test
32+
void shouldForceClassicQueueTypeWhenAutodelete() {
33+
QueueSpecification spec = creator.fillQueueType(QueueSpecification.queue("autodelete").autoDelete(true));
34+
assertThat(spec.getArguments()).containsEntry("x-queue-type", "classic");
35+
}
36+
37+
@Test
38+
void shouldForceClassicQueueTypeWhenExclusive() {
39+
QueueSpecification spec = creator.fillQueueType(QueueSpecification.queue("exclusive").exclusive(true));
40+
assertThat(spec.getArguments()).containsEntry("x-queue-type", "classic");
41+
}
42+
}

0 commit comments

Comments
 (0)