-
Notifications
You must be signed in to change notification settings - Fork 269
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
Impossible to send a FutureRecord without key #370
Comments
Look at the definition of the FutureProducer: pub struct FutureRecord<'a, K: ToBytes + ?Sized, P: ToBytes + ?Sized> {
/// Required destination topic.
pub topic: &'a str,
/// Optional destination partition.
pub partition: Option<i32>,
/// Optional payload.
pub payload: Option<&'a P>,
/// Optional key.
pub key: Option<&'a K>,
/// Optional timestamp.
pub timestamp: Option<i64>,
/// Optional message headers.
pub headers: Option<OwnedHeaders>,
}
[...]
/// Sets the destination payload of the record.
pub fn payload(mut self, payload: &'a P) -> FutureRecord<'a, K, P> {
self.payload = Some(payload);
self
}
/// Sets the destination key of the record.
pub fn key(mut self, key: &'a K) -> FutureRecord<'a, K, P> {
self.key = Some(key);
self
} As you never set the key the compiler doesn't know the type of So in your case you could solve it via: async fn create_json(data: String, producer: Data<FutureProducer>) {
let record: FutureRecord<String, String> = FutureRecord::to("test").payload(&format!("{}", Json(AddResp { result: data }).result));
producer
.send(
record,
Timeout::Never,
)
.await;
} Now |
Ah, it was just that thing 😕 I see that I'm really new on rust… Thank you a lot |
Hi, I have following method and expect random message distribution between consumers in consumer group, but all produced messages consumed by single consumer in group. How could I fix this? Removing async fn produce(&self, message: &T) -> Option<()> {
let json = serde_json::to_string(&message).ok()?;
let record: FutureRecord<String, String> = FutureRecord::to(&self.topic).payload(&json);
self.producer
.send(record, Duration::from_secs(0))
.await
.ok()?;
Some(())
} |
Hi, I'm trying to send a payload without a key to Kafka and I'm obtaining this error:
My IDE shows me this error:
Without the key:
But it's working with the key:
Versions:
Have you any idea?
Thanks
The text was updated successfully, but these errors were encountered: