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

How to set BaseRecord key as none #635

Open
siweilvxing opened this issue Nov 27, 2023 · 1 comment
Open

How to set BaseRecord key as none #635

siweilvxing opened this issue Nov 27, 2023 · 1 comment

Comments

@siweilvxing
Copy link

I don't want set key in BaseRecord like this

let br = BaseRecord::with_opaque_to("flow-file-info", ()).payload(fi);

but hint

impl<'a, K: ToBytes + ?Sized, P: ToBytes + ?Sized, D: IntoOpaque> BaseRecord<'a, K, P, D> {
                ^^^^^^^ required by this bound in `BaseRecord::<'a, K, P, D>::with_opaque_to`

so, I fix like this

let br = BaseRecord::with_opaque_to("flow-file-info", ()).payload(fi).key("");

how do I set key as none?

@FaveroFerreira
Copy link

FaveroFerreira commented Dec 12, 2023

Take a look at the BaseRecord definition:

pub struct BaseRecord<'a, K: ToBytes + ?Sized = (), P: ToBytes + ?Sized = (), D: IntoOpaque = ()> {
    /// 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.
    ///
    /// Note that Kafka represents timestamps as the number of milliseconds
    /// since the Unix epoch.
    pub timestamp: Option<i64>,
    /// Optional message headers.
    pub headers: Option<OwnedHeaders>,
    /// Required delivery opaque (defaults to `()` if not required).
    pub delivery_opaque: D,
}

It takes 3 generics and defaults to () when you dont set them.

You can just not set your .key(...) and specify your type. Also, opaque is () by default if you don't want to use it just use BaseRecord::to(topic).

let br: BaseRecord<'_, (), [u8]> = BaseRecord::to(topic).payload(&payload[..]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants