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

Kafka Headers getting clobbered for some reason #237

Open
samkhopkar opened this issue Jun 25, 2024 · 1 comment
Open

Kafka Headers getting clobbered for some reason #237

samkhopkar opened this issue Jun 25, 2024 · 1 comment

Comments

@samkhopkar
Copy link

samkhopkar commented Jun 25, 2024

I am setting the Kafka headers as follows in the publisher record

   ```
  string app_name = AppInfo::app_info().app_name();
     string host_name = IPAddress::our_host_name();
    record->headers() = {{
        kafka::Header{kafka::Header::Key{"Source"},  kafka::Header::Value{app_name.c_str(), app_name.size()}},
        kafka::Header{kafka::Header::Key{"Host"}, kafka::Header::Value{host_name.c_str(), host_name.size()}}
    }};

When I try to print them in the consumer as follows as string they seem be clobbered

   const string Headers() const 
    { 
        std::ostringstream outs;
        KAFKA_API::Headers headers = _consumer_record.headers();
        std::for_each(headers.cbegin(), headers.cend(),
              [&outs](const auto& header) 
              {
                  outs << ((outs.str().length() == 0) ? "" : ",") << header.key << "=" << std::string((const char *)header.value.data(),header.value.size());
              });
        return outs.str(); 
    }

Output of Headers

` Headers [Source=^@^@^@^@^@^@^@^@Ð^H^@ð^F^?^@^@her,Host=^@^@^@^@^@^@^@^@Ð^H^@ð^F^?^@^@group.com]`

Any ideas what I am doing wrong ?
@samkhopkar
Copy link
Author

Please disregard this issue - it is resolved now. The Header value ConstBuffer data pointer was not valid as local strings were used by sender

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

1 participant