The examples mentioned to create a Consistent hashing exchange in the RabbitMQ Consistent Hasing Github uses Channel to create exchanges :
private static String CONSISTENT_HASH_EXCHANGE_TYPE = "x-consistent-hash";
...
Channel ch = conn.createChannel();
...
ch.exchangeDeclare("e1", CONSISTENT_HASH_EXCHANGE_TYPE, true, false, null);
@Configuration
@EnableAutoConfiguration
public class AMQPConfig {
public static final String QUEUENAME = "consistentHashing-Q1";
public static final String EXCHANGENAME = "consistentHashing-DE1";
public static final String RK = "consistentHashing-RK1";
@Bean
public Queue queue() {
return QueueBuilder.nonDurable(QUEUENAME).autoDelete().build();
}
@Bean
public DirectExchange directExchange() {
return ExchangeBuilder.directExchange(EXCHANGENAME).autoDelete().withArgument("Type", "x-consistent-hash").build();
}
@Bean
public Binding binding(Queue queue, Exchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(RK).noargs();
}
}
Was able to create Consistent Hashing Exchange in Spring boot AMQP using the below code :
@Bean
public CustomExchange customExchange() {
CustomExchange customExchange = new CustomExchange(EXCHANGENAME, "x-consistent-hash", false, true);
customExchange.addArgument("hash-header", "client-id");
return customExchange;
}