Skip to content
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

Ack for PubSub message delivery #16

Open
7 tasks done
minghuaw opened this issue Jul 21, 2021 · 1 comment
Open
7 tasks done

Ack for PubSub message delivery #16

minghuaw opened this issue Jul 21, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@minghuaw
Copy link
Owner

minghuaw commented Jul 21, 2021

Why?

As of 0.8.0-alpha.4, the PubSub message deliveries are not Acked by the subscriber. TCP itself could suffice the delivery or message safety requirement for most cases, but I would like to make it configurable for the cases where explicit Ack is preferred. The proposed implementation is like follows

Proposal

There will be three different AckModes.

  1. AckModeNone, no Ack message will be sent back
  2. AckModeAuto, an Ack will be sent back automatically upon message delivery to the client
  3. AckModeManual, instead of receiving Result<Topic::Item, Error> from the Subscriber stream, the user will receive Result<Delivery<Topic::Item>, Error> from the Subscriber stream. The message content (Topic::Item) can be obtained by calling the .ack() method on the Delivery<_> object.

A ClientBuilder will be added where the AckMode can be configured, and AckModeNone will be the default if the AckMode is not configured. Below shows the proposed example usage

// Configure `AckMode`
let builder = Client::builder() // `AckModeNone` is set by default
    .set_ack_mode_none() // this will explicitly set the `AckMode` to `AckModeNone`
    .set_ack_mode_auto() // set the `AckMode` to `AckModeAuto`
    .set_ack_mode_manual(); // set the `AckMode` to `AckModeManual`

After the builder is configured, use the builder to dial to the server. The usage from this point on for AckModeNone and AckModeAuto will remain the same as before. Thus the code below will only show the proposed usage of AckModeManual

let client = builder.dial(address).await.unwrap();
let subscriber: Subscriber<Topic, AckModeManual> = client.subscriber::<Topic>(cap).unwrap();

while let Some(result)  = subscriber.next().await {
    let delivery = result.unwrap()
    let item = delivery.ack().unwrap(); // item is of type `Topic::Item`
    // .. do something with the item
}

Progress

In no particular order

  • Code cleanup
  • Add type state to Client and Server
  • Verify AckModeNone just works with existing tests and examples
  • Add implementation of setting max retries
  • Add implementation of AckModeAuto
  • Add implementation of AckModeManual
    • Add struct Delivery { .. }
@minghuaw minghuaw added the enhancement New feature or request label Jul 21, 2021
@minghuaw minghuaw self-assigned this Jul 21, 2021
@minghuaw minghuaw added the help wanted Extra attention is needed label Jul 21, 2021
@minghuaw
Copy link
Owner Author

Initial implementation is added in 0.8.0-beta.0 (PR #17). This issue will remain open for issues related to Ack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant