EzyRabbitMQ Configration

Updated at 1685687763000

1. Configuration List

EzyRabbitMQ provides a list of configurations in bellow table:

PropertyDefault ValueDescription
1rabbitmq.urinullRabbitMQ uri
2rabbitmq.hostlocalhostRabbitMQ host
3rabbitmq.port5672RabbitMQ port
4rabbitmq.usernameguestRabbitMQ username
5activemq.passwordguestActiveMQ password
6rabbitmq.vhost/RabbitMQ vhost
7rabbitmq.max_connection_attempts0Maximum number of connection retry
8rabbitmq.requested_heart_beat15The requested heartbeat timeout
9rabbitmq.shared_thread_pool_size0Number of threads of the executor to use for consumer operation dispatch by default for newly created connections
10rabbitmq.producersnullList of RabbitMQ producers
11rabbitmq.consumersnullList of RabbitMQ consumers
12rabbitmq.topicsnullList of RabbitMQ topics

For every producer, EzyRabbitMQ provides bellow properties:

PropertyDefault ValueDescription
1exchange[producer name]-exchangeName of the request exchange
2prefetch_count0Maximum number of messages that the server will deliver, 0 if unlimited
3request_queue_name[producer name]-request-queueName of the request queue
4request_routing_key[producer name]-request-routing-keyName of the request routing key
5reply_queue_name[producer name]-replyName of the reply queue
6capacity10000Capacity of the producer
7default_timeoutno timeoutDefault timeout of a rpc request in millisecond

For every consumer, EzyRabbitMQ provides bellow properties:

PropertyDefault ValueDescription
1exchange[consumer name]-exchangeName of the request exchange
2prefetch_count0Maximum number of messages that the server will deliver, 0 if unlimited
3request_queue_name[consumer name]-request-queueName of the request queue
4reply_routing_key[consumer name]-reply-routing-keyName of the reply routing key
5thread_pool_size1Thread pool size for request message handler

For every topic, EzyRabbitMQ provides bellow properties:

PropertyDefault ValueDescription
1exchangetopic-[topic name]-exchange-Producer for the topic settings
2prefetch_count0Maximum number of messages that the server will deliver, 0 if unlimited
3producernullTopic producer's settings
4producer.routing_keytopic-[topic-name]-routing-keyTopic producer's routing key
5producer.enabletrue if producer is not null or false if producer is nullTopic producer's enable or not
6consumernullTopic's consumer settings
7consumer.queue_namerandom uuidConsumer's queue name
8consumer.enabletrue if consumer is not null or false if consumer is nullTopic consumer's enable or not

2. An Example

Let's we neen create a producer and a consumer named test and a topic named hello, you can put bellow configuration to your application.yaml file:

# for application.yaml
rabbitmq:
  producers:
    test: default
  consumers:
    test: default
  topics:
    hello:
      producer: default
      consumer: default

Or for application.properties file:

# for application.properties
rabbitmq.producers.test=default
rabbitmq.consumers.test=default
rabbitmq.topics.hello.producer=default
rabbitmq.topics.hello.consumer=default

3. Configure for producer

You can configure for producer like this:

EzyRabbitMQProxy proxy = EzyRabbitMQProxy.builder()
    .scan("com.tvd12.ezymq.rabbitmq.test")
    .mapTopicMessageType("hello", "hello", SumRequest.class)
    .build();
EzyRabbitRpcProducer producer = proxy.getRpcProducer("test");

4. Configure for consumer

You can configure for consumer like this:

EzyRabbitMQProxy.builder()
    .addSingleton(someSingleton)
    .scan("com.tvd12.ezymq.rabbitmq.test")
    .build();

5. Topic usage

You can get the topic like this:

EzyRabbitTopic<SumRequest> sumTopic = proxy.getTopic("hello");

And use the topic to publish a message like this:

sumTopic.publish("hello", new SumRequest(a, b));

You also can add message consumer for the topic like this:

sumTopic.addConsumer("hello", message ->
    System.out.println("sum request: " + message)
);