naveena kedlaya
naveena kedlaya

Reputation: 1

How to publish a message to a Kafka Topic in Lagom

I have started using lagom recently. Trying out a microservice where I receive a kafka message and after some processing publish another message to a different kafka topic. Based on this link my understanding is, a message should be published on the constructed topic - especially this part of the sample code I am referring to.

final PubSubRef<Temperature> topic = pubSub.refFor(TopicId.of(Temperature.class, id));
      topic.publish(temperature);

I couldn’t build Temperature DTO to POST from rest client. So I created my on DTO which is exactly similar to HelloEvent - in my case its KafkaEvent.

I tried to use the code from here

However I did not see the topic created after performing POST operation. I did add print statements and they do appear in console.

 System.out.println("Received id:" + id);
   final PubSubRef<KafkaEvent> topic = pubSub.refFor(TopicId.of(KafkaEvent.class, id));
   topic.publish(temperature);
   System.out.println("Sent to:" + topic.toString());

I am not seeing any error in kafka server log or in my project.

Is there any step I am missing? or my understanding is wrong in usage of PubSubRegistry?

Please do let me know if further details are required.

Thanks in advance

Naveena

Upvotes: 0

Views: 577

Answers (1)

Vladislav Kievski
Vladislav Kievski

Reputation: 1647

If you want to use Kafka, you are using incorrect approach. This post that you described does not use Kafka. It just broadcast messages to all subscribers. If you want to use Kafka you need to use message broker support, it will create what you want. Please read section limitations, it will give you mire information.

Upvotes: 1

Related Questions