简体   繁体   English

如何在Lagom中向Kafka主题发布消息

[英]How to publish a message to a Kafka Topic in Lagom

I have started using lagom recently. 我最近开始使用lagom。 Trying out a microservice where I receive a kafka message and after some processing publish another message to a different kafka topic. 试用微服务,我会收到一条kafka消息,经过一些处理后,将另一条消息发布到另一个kafka主题。 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. 我无法从其他客户端建立Temperature DTO来进行POST。 So I created my on DTO which is exactly similar to HelloEvent - in my case its KafkaEvent. 因此,我在DTO上创建了与HelloEvent完全相似的DTO-在我的情况下是其KafkaEvent。

I tried to use the code from here 我试图从这里使用代码

However I did not see the topic created after performing POST operation. 但是,执行POST操作后,我没有看到创建的主题。 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. 我在kafka服务器日志或项目中没有看到任何错误。

Is there any step I am missing? 我缺少任何步骤吗? or my understanding is wrong in usage of PubSubRegistry? 还是我的理解在使用PubSubRegistry中是错误的?

Please do let me know if further details are required. 如果需要更多详细信息,请告诉我。

Thanks in advance 提前致谢

Naveena 纳韦纳

If you want to use Kafka, you are using incorrect approach. 如果要使用Kafka,则使用的方法不正确。 This post that you described does not use Kafka. 您描述的帖子不使用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. 如果您想使用Kafka,则需要使用Message Broker支持 ,它将创建您想要的东西。 Please read section limitations , it will give you mire information. 请阅读本节限制 ,它将为您提供泥潭信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM