EzyKafka Configuration
Updated at 16998036130001. Configuration List
EzyKafka provides a list of configurations in bellow table:Property | Default Value | Description | |
1 | kafka.consumers | null | List of kafka consumers |
2 | kafka.producers | null | List of kafka producers |
For every producer, EzyKafka provides bellow properties:
Property | Default Value | Description | |
1 | topic | producer name | Name of the kafka topic |
2 | bootstrap.servers | localhost:9092 | Kafka bootstrap servers |
3 | client.id | producer name | Kafka client id |
You can find out the all properties of kafka producer in the ProducerConfig class For every consumer, EzyKafka provides bellow properties:
Property | Default Value | Description | |
1 | topic | consumer name | Name of the kafka topic |
2 | bootstrap.servers | localhost:9092 | Kafka bootstrap servers |
3 | client.id | consumer name | Kafka client id for consumer |
4 | group.id | random uuid | Kafka group id for consumers |
You can find out the all properties of kafka consumer in the ConsumerConfig class
Let's careful with group.id
Let's take a look bellow image:
You can see, in a group, there is only one consumer can poll message at a time. Example, you have Consumer Group 2
with Consumer1 and Consumer2
, now Topic T1
has 2 messages: Message1, Message2
, so maybe Consumer1
or Consumer2
will poll the both messages or Consumer1 poll Message1
and Consumer2 poll Message2
. So, if you want to broadcast a message to the all consumer, you will need set value for group.id
property is difference for each consumer, or you don't need provide any value, EzyKafka will random an UUID for you.
2. An Example
Let's we neen create a producer and a consumer named hello-world
, you can put bellow configuration to your application.yaml
file:
# for application.yaml kafka: producers: hello-world: hello-world: test bootstrap.servers: localhost:9092 client.id: KafkaProducerExample consumers: hello-world: topic: hello-world group.id: KafkaConsumerExample
Or for application.properties
file:
# for application.properties kafka.producers.hello-world.topic=hello-world kafka.producers.hello-world.bootstrap.servers=localhost:9092 kafka.producers.hello-world.client.id=KafkaProducerExample kafka.consumers.hello-world.topic=test kafka.consumers.hello-world.group.id=KafkaConsumerExample
3. Configure for producer
You can configure for producer like this:
EzyKafkaProxy kafkaProxy = EzyKafkaProxy.builder() .scan("com.tvd12.ezymq.example.kafka") .build(); EzyKafkaProducer producer = kafkaProxy.getProducer("hello-world");
4. Configure for consumer
You can configure for consumer like this:
EzyKafkaProxy.builder()
.addSingleton(someSingleton)
.scan("com.tvd12.ezymq.example.kafka")
.build();
Please take a look ezymq-kafka for entire example.
Next step
You can see how to build a push message system.