yoshidan / google-cloud-rust

Google Cloud Client Libraries for Rust.
MIT License
216 stars 81 forks source link

[PubSub] Failed precondition when using ordering key. #226

Closed okkero closed 5 months ago

okkero commented 6 months ago

Seems like Publisher doesn't batch messages correctly based on ordering key. When calling .publish(...) multiple times with different ordering keys I get the following error: Status { code: FailedPrecondition, message: "In a single publish request, all messages must have no ordering key or they must all have the same ordering key. [code=539b]", source: None }

Per the Publisher documentation it looks like it is supposed to be able to handle different ordering keys just fine: "Each item is added with a given key. Items added to the empty string key are handled in random order. Items added to any other key are handled sequentially."

I don't know if this is a documentation issue or an implementation issue, but at least I could not find anything in the documentation stating that multiple different ordering keys is not supported by a single Publisher. I guess the workaround for now would be to use one Publisher per ordering key.

yoshidan commented 6 months ago

We have investigated and found that this is an implementation issue and will correct it. Although the number of requests has increased, the error can be suppressed by setting the bundle_size to 1 in the PublisherConfig, so please use this as a work-around.

 let topic = client.topic("test-topic2");
 let publisher = topic.new_publisher(Some(
        PublisherConfig {
                bundle_size: 1,
                ..Default::default()
        }
));
okkero commented 6 months ago

Thank you for the suggested workaround