Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

Publish vs Produce in MassTransit with Kafka

I want to implement state machine integrated with Kafka topics. Whenever some message will be produced to a topic, I want state machine to react by changing a state. I have two questions:

  1. Is producing a message on a topic identical with publishing an event?
  2. How to wire things up in a proper way? Some simple code example would be welcome.
question from:https://stackoverflow.com/questions/65626143/publish-vs-produce-in-masstransit-with-kafka

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Produce is not the same as Publish. You can use Produce to send messages to a topic in Kafka from a state machine:

Initially(
    When(Started)
        .Produce(x => x.Init<KafkaMessage>(new {Text = "text"}))
        .TransitionTo(Active));

There are unit tests that show how it works, I don't believe it is documented yet. It was added in this commit


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...