Skip to content

Commit f45a6eb

Browse files
committed
Fix upgrade rabbitmq version cause BuiltinExchangeType has 4 new types.
1 parent 0a60783 commit f45a6eb

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

amqp-impl/src/main/java/io/streamnative/pulsar/handlers/amqp/AmqpExchange.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,20 @@ public interface AmqpExchange {
3434
*
3535
*/
3636
enum Type{
37-
Direct,
38-
Fanout,
39-
Topic,
40-
Headers;
37+
Direct("direct"),
38+
Fanout("fanout"),
39+
Topic("topic"),
40+
Headers("headers"),
41+
ConsistentHash("x-consistent-hash"),
42+
ModulusHash("x-modulus-hash"),
43+
LocalRandom("x-local-random"),
44+
Random("x-random");
45+
46+
private final String type;
47+
48+
Type(String type) {
49+
this.type = type;
50+
}
4151

4252
public static Type value(String type) {
4353
if (type == null || type.length() == 0) {
@@ -53,11 +63,24 @@ public static Type value(String type) {
5363
return Topic;
5464
case "headers":
5565
return Headers;
66+
case "x-consistent-hash":
67+
return ConsistentHash;
68+
case "x-modulus-hash":
69+
return ModulusHash;
70+
case "x-local-random":
71+
return LocalRandom;
72+
case "x-random":
73+
return Random;
5674
default:
5775
return null;
5876
}
5977
}
6078

79+
@Override
80+
public String toString() {
81+
return type;
82+
}
83+
6184
}
6285

6386
/**

amqp-impl/src/main/java/io/streamnative/pulsar/handlers/amqp/ExchangeMessageRouter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ public static ExchangeMessageRouter getInstance(PersistentExchange exchange, Exe
301301
case Direct -> new DirectExchangeMessageRouter(exchange, routeExecutor);
302302
case Topic -> new TopicExchangeMessageRouter(exchange, routeExecutor);
303303
case Headers -> new HeadersExchangeMessageRouter(exchange, routeExecutor);
304+
default -> null;
304305
};
305306
}
306307

tests/src/test/java/io/streamnative/pulsar/handlers/amqp/rabbitmq/functional/ExchangeDeclareTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.streamnative.pulsar.handlers.amqp.rabbitmq.functional;
1818

19+
import static org.junit.Assert.assertEquals;
1920
import com.rabbitmq.client.BuiltinExchangeType;
2021
import com.rabbitmq.client.Channel;
2122
import com.rabbitmq.client.Connection;
@@ -116,11 +117,9 @@ public void exchangeDeclaredWithEnumerationEquivalentOnRecoverableConnection()
116117

117118
private void doTestExchangeDeclaredWithEnumerationEquivalent(Channel channel)
118119
throws IOException, InterruptedException {
119-
for (BuiltinExchangeType exchangeType : new BuiltinExchangeType[]{
120-
BuiltinExchangeType.DIRECT,
121-
BuiltinExchangeType.FANOUT,
122-
BuiltinExchangeType.TOPIC,
123-
BuiltinExchangeType.HEADERS}) {
120+
assertEquals("There are 8 standard exchange types",
121+
8, BuiltinExchangeType.values().length);
122+
for (BuiltinExchangeType exchangeType : BuiltinExchangeType.values()) {
124123
channel.exchangeDeclare(NAME, exchangeType);
125124
verifyEquivalent(NAME, exchangeType.getType(), false, false, null);
126125
deleteExchangeWithRetry();

0 commit comments

Comments
 (0)