kayleg / cloud-pubsub

Google Cloud PubSub client in rust
MIT License
31 stars 21 forks source link

How to relate ack_ids and messages in subscription::get_messages result? #14

Closed hseeberger closed 3 years ago

hseeberger commented 3 years ago

In subscription::get_messages the ack_ids are decoupled from the converted messages, since the function returns two vectors.

        let messages = response.received_messages.unwrap_or_default();
        let ack_ids: Vec<String> = messages
            .as_slice()
            .iter()
            .map(|packet| packet.ack_id.clone())
            .collect();
        let packets = messages
            .into_iter()
            .filter_map(|packet| match T::from(packet.message) {
                Ok(o) => Some(o),
                Err(e) => {
                    error!("Failed converting pubsub {}", e,);
                    None
                }
            })
            .collect();

        Ok((packets, ack_ids))

If messages cannot be converted, they are dropped. So how would I know which ack_id is for which message? On the happy path the are correlated by index, but if some messages are dropped, that is no longer the case.