fdelbrayelle / generator-jhipster-kafka

A JHipster module that generates Apache Kafka consumers and producers and more!
Apache License 2.0
28 stars 10 forks source link

Send events through Kafka when CRUDing on entities #81

Open fdelbrayelle opened 4 years ago

fdelbrayelle commented 4 years ago
Overview of the feature request

When CRUDing on entities, it should send events in topics for given entities.

Maybe propose this by a prompt option?

This could be linked with #4 where consumer/producer would be created by hook when using jhipster entity Foo.

An event type could be send as a key when producing a message for instance:

byte[] key = "FOO_ENTITY_CREATION".getBytes();
byte[] value = "value".getBytes();
ProducerRecord<byte[],byte[]> record = new ProducerRecord<byte[],byte[]>("my-topic", key, value)
producer.send(record);

An enum could be generated with the different operations values (create, update, delete).

Motivation for or Use Case

Allowing the application to be event-driven.

Use case:

  1. Create a first JHipster application JH1 with a Foo entity, create a FooProducer.
  2. Create a first JHipster application JH2 with a Foo entity, create a FooConsumer.
  3. Create a Foo in the application.
  4. A creation event is send to the queuing.application_name.foo topic through FooProducer in JH1.
  5. The creation event is read in the queuing.application_name.foo topic by FooConsumer in JH2.

:warning: On JH2 the entity could not be deserialized correctly because the entity doesn't have the same package on JH1 and JH2. Make a test with current deserialization mode or see #63 for deserialization alternatives (to be priorized ?).

Add support for akhq to be launched on multiple apps.

Related issues or PR

4

fdelbrayelle commented 4 years ago

Is it in accordance with your use cases @pascalgrimaud?

pascalgrimaud commented 4 years ago

yes, it's nice it could be split into several part, like create, update and delete, and for each case, think about how to implement it.

The hardest would be deleted, as I think we should forbid this, and implement a logical delete, rather than a physical one. It should be discussed

fdelbrayelle commented 4 years ago

I think we should follow what it's done on the main generator for entities deletion. In my opinion, we just have to manage an event on CRUD operations, not operations themselves. What do you think?