-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper way to Complete the message #3
Comments
Found a post from Scala/Rabit world, which probably means there's no easy solution for my issue: |
This topic is complicated and there isn't a general solution for Akka.Streams yet. You can read more about it in context of the Kafka connector from the jvm here and here. A possible solution for you problem could be to use var source = ServiceBusSource.Create(client);
var getBody = Flow.Create<BrokeredMessage>().Select(x => x.GetBody<string>());
var work = Flow.Create<string>().Select(i =>
{
Console.WriteLine($"Doing work: {i}");
return i;
});
var sink = Sink.ForEach<BrokeredMessage>(i =>
{
Console.WriteLine($"Complete: {i}");
i.Complete();
}).MapMaterializedValue(_ => NotUsed.Instance);
var g = RunnableGraph.FromGraph(GraphDsl.Create(builder =>
{
var broadcast = builder.Add(new Broadcast<BrokeredMessage>(2));
var merge = builder.Add(new ZipWith<BrokeredMessage, string, BrokeredMessage>(Keep.Left));
builder.From(source).To(broadcast);
builder.From(broadcast).To(merge.In0);
builder.From(broadcast).Via(getBody).Via(work).To(merge.In1);
builder.From(merge.Out).To(sink);
return ClosedShape.Instance;
}));
g.Run(mat); But you must make sure that you doesn't use Another approach would be to use a envelope instead of |
@mikhailshilkov there is a new blog post out about writing akka streams connectors. The AMQP connector ack's the messages as soon as they arrive, as you can see here. |
If you make it configurable, that's perfectly fine of course. |
@mikhailshilkov sorry for the delay, was quite busy the last weeks. |
It looks good, other than the fact that I don't see a possibility to configure if I want to auto-complete or not. |
I struggled a little bit withe the API, I had a additional ack parameter but then I encountered the problem with brokeredMessage.Complete vs CompleteAsync, maybe one would like to emit only completed messages downstream or use complete more like fire and forget and don't await the async call... Does that make sense ? |
Yes, nice |
That's not an issue of the library, but more a question on how to use it properly.
What's the right point to
Complete
the service bus message? Ideally, I want to do that after all the processing is done, so it the end of the stream graph. Here is my example:It has 4 parts:
Source
of SB messages.Flow
step to extract message body.Flow
step to simulate some real time-consuming error-prone work done on the message.Complete
the message.As you see, I had to pass the initial SB message in a tuple all the way through the pipeline, which doesn't look nice. I would have to deal with tuples which can be problematic for large pipelines and makes the code more complicated.
Are there other approaches? E.g. have the
Source
or other independentFlow
steps which could be signaled about the message processing success. Or should I ignore it altogether,Complete
the message immediately and then rely on Akka to do error handling? That would assume that Akka will never fail, which is wrong for machine-level failures I guess.Would be nice to get your opinion or a link to appropriate discussion.
The text was updated successfully, but these errors were encountered: