<commit_before>extern crate kafka;
use kafka::client::KafkaClient;

fn main() {
    let dest = "localhost:9092";
    println!("Publishing to {}", dest);
    let mut client = KafkaClient::new(vec!(dest.to_owned()));
    client.load_metadata_all().unwrap();
    match client.send_message(1, 100, "my-topic".to_owned(), "msg".to_owned().into_bytes()) {
        Ok(e) => {println!("OK {:?}", e);},
        Err(e) => {println!("Error {:?}", e);}
    }
}
<commit_msg>#! Print a message when target topic does not yet exist<commit_after>extern crate kafka;

use kafka::client::KafkaClient;

/// This program demonstrates sending a single message through
/// `KafkaClient`.
fn main() {
    let broker = "localhost:9092";
    let topic = "my-topic";
    let data = "hello, kafka";

    println!("About to publish a message at {} to: {}", broker, topic);

    // ~ create the client and load metadata for all available topics
    let mut client = KafkaClient::new(vec!(broker.to_owned()));
    if let Err(e) = client.load_metadata_all() {
        println!("Failed to load meta data from {}: {}", broker, e);
        return;
    }
    // ~ make sure to print out a warning message when the target
    // topic does not yet exist
    if !client.topic_partitions.contains_key(topic) {
        println!("No such topic at {}: {}", broker, topic);
        return;
    }
    // ~ now send a small message (if the specified topic would have
    // not been existent) the client would drop the message.
    let r = client.send_message(1, 100, topic.to_owned(), data.as_bytes().to_owned());
    println!("message sent: {:?}", r);
}

{'fraction_non_alphanumeric': 0.15818858560794044, 'fraction_numerical': 0.009925558312655087, 'mean_word_length': 3.336021505376344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5352797', 'n_tokens_mistral': 508, 'n_tokens_neox': 495, 'n_words': 155}