Skip to content

Mutable self requirement on send/ack/nack makes using difficult in highly async contexts #346

@chamons

Description

@chamons

These APIs (for example) all require &mut self

  • pub async fn send_non_blocking<T: SerializeMessage + Sized>(&mut self,message: T) -> Result<SendFuture, Error>
  • pub async fn ack(&mut self, msg: &Message<T>) -> Result<(), ConsumerError>
  • pub async fn nack(&mut self, msg: &Message<T>) -> Result<(), ConsumerError>

That makes sharing connections between many tokio tasks more difficult than I'd like.

Today I work around this by making an actor like worker that owns the connection and many clients send requests with oneshots to wait for completion. This is more non-trivial than I'd like.

I looked into why sending requires mutability and I found:

  • send_non_blocking calls send_non_blocking on the specific producer in the multi producer
  • That calls sends on either the single or partition with your message
  • That calls send_raw on the producer
  • Which calls send_inner
  • Which can call reconnect which requires replacing our connection with the new one
  • It also replaces the batch settings which requires mut
  • Also looking into it more the partitioned topic code also needs mutable to walk the partitions for round robin=

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions