BAEL-4893 Exchanges, Queues, and Bindings in RabbitMQ (#10872)
* BAEL-4893 Add code for rabbitmq exchanges, queues, and bindings * BAEL-4893 Upgrade RabbitMQ client version Co-authored-by: Flaviu Cicio <f.cicio@glofox.com>
This commit is contained in:
parent
317009a78d
commit
af408b9830
|
@ -22,7 +22,7 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<amqp-client.version>3.6.6</amqp-client.version>
|
||||
<amqp-client.version>5.12.0</amqp-client.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,38 @@
|
|||
package com.baeldung.setup;
|
||||
|
||||
import com.rabbitmq.client.BuiltinExchangeType;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class Setup {
|
||||
|
||||
private static final String ORDERS_QUEUE_NAME = "orders-queue";
|
||||
private static final String ORDERS_EXCHANGE_NAME = "orders-direct-exchange";
|
||||
private static final String ORDERS_ALTERNATE_EXCHANGE_NAME = "orders-alternate-exchange";
|
||||
private static final String ORDERS_ROUTING_KEY = "orders-routing-key";
|
||||
|
||||
public static void main(String[] args) throws IOException, TimeoutException {
|
||||
ConnectionFactory factory = new ConnectionFactory();
|
||||
factory.setHost("localhost");
|
||||
Connection connection = factory.newConnection();
|
||||
Channel channel = connection.createChannel();
|
||||
|
||||
Map<String, Object> exchangeArguments = new HashMap<>();
|
||||
exchangeArguments.put("alternate-exchange", ORDERS_ALTERNATE_EXCHANGE_NAME);
|
||||
channel.exchangeDeclare(ORDERS_EXCHANGE_NAME, BuiltinExchangeType.DIRECT, true, false, exchangeArguments);
|
||||
|
||||
Map<String, Object> queueArguments = new HashMap<>();
|
||||
queueArguments.put("x-message-ttl", 60000);
|
||||
queueArguments.put("x-max-priority", 10);
|
||||
channel.queueDeclare(ORDERS_QUEUE_NAME, true, false, false, queueArguments);
|
||||
|
||||
channel.queueBind(ORDERS_QUEUE_NAME, ORDERS_EXCHANGE_NAME, ORDERS_ROUTING_KEY);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue