EzyRabbitMQ Configration
Updated at 17288905570001. Configuration List
EzyRabbitMQ provides a list of configurations in bellow table:Property | Default Value | Description | |
1 | rabbitmq.uri | null | RabbitMQ uri |
2 | rabbitmq.host | localhost | RabbitMQ host |
3 | rabbitmq.port | 5672 | RabbitMQ port |
4 | rabbitmq.username | guest | RabbitMQ username |
5 | rabbitmq.password | guest | ActiveMQ password |
6 | rabbitmq.vhost | / | RabbitMQ vhost |
7 | rabbitmq.max_connection_attempts | 0 | Maximum number of connection retry |
8 | rabbitmq.requested_heart_beat | 15 | The requested heartbeat timeout |
9 | rabbitmq.shared_thread_pool_size | 0 | Number of threads of the executor to use for consumer operation dispatch by default for newly created connections |
10 | rabbitmq.producers | null | List of RabbitMQ producers |
11 | rabbitmq.consumers | null | List of RabbitMQ consumers |
12 | rabbitmq.topics | null | List of RabbitMQ topics |
For every producer, EzyRabbitMQ provides bellow properties:
Property | Default Value | Description | |
1 | exchange | [producer name]-exchange | Name of the request exchange |
2 | prefetch_count | 0 | Maximum number of messages that the server will deliver, 0 if unlimited |
3 | request_queue_name | [producer name]-request-queue | Name of the request queue |
4 | request_routing_key | [producer name]-request-routing-key | Name of the request routing key |
5 | reply_queue_name | [producer name]-reply | Name of the reply queue |
6 | capacity | 10000 | Capacity of the producer |
7 | default_timeout | no timeout | Default timeout of a rpc request in millisecond |
For every consumer, EzyRabbitMQ provides bellow properties:
Property | Default Value | Description | |
1 | exchange | [consumer name]-exchange | Name of the request exchange |
2 | prefetch_count | 0 | Maximum number of messages that the server will deliver, 0 if unlimited |
3 | request_queue_name | [consumer name]-request-queue | Name of the request queue |
4 | reply_routing_key | [consumer name]-reply-routing-key | Name of the reply routing key |
5 | thread_pool_size | 1 | Thread pool size for request message handler |
For every topic, EzyRabbitMQ provides bellow properties:
Property | Default Value | Description | |
1 | exchange | topic-[topic name]-exchange- | Producer for the topic settings |
2 | prefetch_count | 0 | Maximum number of messages that the server will deliver, 0 if unlimited |
3 | producer | null | Topic producer's settings |
4 | producer.routing_key | topic-[topic-name]-routing-key | Topic producer's routing key |
5 | producer.enable | true if producer is not null or false if producer is null | Topic producer's enable or not |
6 | consumer | null | Topic's consumer settings |
7 | consumer.queue_name | random uuid | Consumer's queue name |
8 | consumer.enable | true if consumer is not null or false if consumer is null | Topic 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) );