You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Adaryl Wakefield <ad...@hotmail.com> on 2017/04/17 11:48:34 UTC

Kafka producer doesn't produce

Now I’m curious why the below just sits and does nothing.

import java.util.Properties;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class SimpleProducer {
 
 public static void main(String[] args) throws Exception{
    
    String topicName = "test_topic";
    
    Properties props = new Properties();
    
    
    props.put("bootstrap.servers", "server:6667");
    
    props.put("acks", "all");
    

    props.put("retries", 0);
    
    props.put("batch.size", 16384);
    
 
    props.put("linger.ms", 1);
    
    
    props.put("buffer.memory", 33554432);
    
    props.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
       
    props.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");
    
    Producer<String, String> producer = new KafkaProducer<String, String>(props);
          
    for(int i = 0; i < 10; i++)
       producer.send(new ProducerRecord<String, String>(topicName, Integer.toString(i), Integer.toString(i)));
       System.out.println("Message sent successfully");
       producer.close();
 }
}


Adaryl "Bob" Wakefield, MBA
Principal
Mass Street Analytics, LLC
913.938.6685
www.massstreet.net
www.linkedin.com/in/bobwakefieldmba
Twitter: @BobLovesData

-----Original Message-----
From: Vinod KC [mailto:VKC@hortonworks.com] 
Sent: Monday, April 17, 2017 6:25 AM
To: users@kafka.apache.org
Subject: Re: Kafka won't take messages

Can you check the value of ‘listeners’ in server.properties ?
Eg: listeners=PLAINTEXT://<host>:<port>
Ensure the port you are connecting is correct


On 4/17/17, 4:34 PM, "Adaryl Wakefield" <ad...@hotmail.com> wrote:

    [2017-04-17 07:03:20,183] ERROR Error when sending message to topic test_topic with key: null, value: 22 bytes with error: (
    org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
    org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
    
    Adaryl "Bob" Wakefield, MBA
    Principal
    Mass Street Analytics, LLC
    913.938.6685
    www.massstreet.net
    www.linkedin.com/in/bobwakefieldmba
    Twitter: @BobLovesData
    
    -----Original Message-----
    From: Sandeep Nemuri [mailto:nhsandeep6@gmail.com] 
    Sent: Monday, April 17, 2017 5:48 AM
    To: users@kafka.apache.org
    Subject: Re: Kafka won't take messages
    
    When you run the producer it will be expecting you to produce some message(s). Run a consumer simultaneously and enter some message in producer console. you should be able to see the same in at console consumer output.
    
    On Mon, Apr 17, 2017 at 3:39 PM, Adaryl Wakefield < adaryl.wakefield@hotmail.com> wrote:
    
    > My cluster is not accepting connections and messages for some reason. 
    > I'm not sure where to start troubleshooting. When I try to test it with:
    > $ bin/kafka-console-producer.sh --broker-list localhost:6667 --topic 
    > test_topic
    >
    > It just hangs. When I try to run a Simple Producer, I get the same result.
    >
    > Adaryl "Bob" Wakefield, MBA
    > Principal
    > Mass Street Analytics, LLC
    > 913.938.6685
    > www.massstreet.net
    > www.linkedin.com/in/bobwakefieldmba
    > Twitter: @BobLovesData
    >
    >
    
    
    --
    *  Regards*
    *  Sandeep Nemuri*
    


RE: Kafka producer doesn't produce

Posted by Adaryl Wakefield <ad...@hotmail.com>.
Solution:
1. producer.close() needed to be moved out of the for loop.
2. I needed to alter my host file so the IP would resolve.

Adaryl "Bob" Wakefield, MBA
Principal
Mass Street Analytics, LLC
913.938.6685
www.massstreet.net
www.linkedin.com/in/bobwakefieldmba
Twitter: @BobLovesData

-----Original Message-----
From: Adaryl Wakefield [mailto:adaryl.wakefield@hotmail.com] 
Sent: Monday, April 17, 2017 6:49 AM
To: users@kafka.apache.org
Subject: Kafka producer doesn't produce

Now I’m curious why the below just sits and does nothing.

import java.util.Properties;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class SimpleProducer {
 
 public static void main(String[] args) throws Exception{
    
    String topicName = "test_topic";
    
    Properties props = new Properties();
    
    
    props.put("bootstrap.servers", "server:6667");
    
    props.put("acks", "all");
    

    props.put("retries", 0);
    
    props.put("batch.size", 16384);
    
 
    props.put("linger.ms", 1);
    
    
    props.put("buffer.memory", 33554432);
    
    props.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
       
    props.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");
    
    Producer<String, String> producer = new KafkaProducer<String, String>(props);
          
    for(int i = 0; i < 10; i++)
       producer.send(new ProducerRecord<String, String>(topicName, Integer.toString(i), Integer.toString(i)));
       System.out.println("Message sent successfully");
       producer.close();
 }
}


Adaryl "Bob" Wakefield, MBA
Principal
Mass Street Analytics, LLC
913.938.6685
www.massstreet.net
www.linkedin.com/in/bobwakefieldmba
Twitter: @BobLovesData

-----Original Message-----
From: Vinod KC [mailto:VKC@hortonworks.com] 
Sent: Monday, April 17, 2017 6:25 AM
To: users@kafka.apache.org
Subject: Re: Kafka won't take messages

Can you check the value of ‘listeners’ in server.properties ?
Eg: listeners=PLAINTEXT://<host>:<port>
Ensure the port you are connecting is correct


On 4/17/17, 4:34 PM, "Adaryl Wakefield" <ad...@hotmail.com> wrote:

    [2017-04-17 07:03:20,183] ERROR Error when sending message to topic test_topic with key: null, value: 22 bytes with error: (
    org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
    org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
    
    Adaryl "Bob" Wakefield, MBA
    Principal
    Mass Street Analytics, LLC
    913.938.6685
    www.massstreet.net
    www.linkedin.com/in/bobwakefieldmba
    Twitter: @BobLovesData
    
    -----Original Message-----
    From: Sandeep Nemuri [mailto:nhsandeep6@gmail.com] 
    Sent: Monday, April 17, 2017 5:48 AM
    To: users@kafka.apache.org
    Subject: Re: Kafka won't take messages
    
    When you run the producer it will be expecting you to produce some message(s). Run a consumer simultaneously and enter some message in producer console. you should be able to see the same in at console consumer output.
    
    On Mon, Apr 17, 2017 at 3:39 PM, Adaryl Wakefield < adaryl.wakefield@hotmail.com> wrote:
    
    > My cluster is not accepting connections and messages for some reason. 
    > I'm not sure where to start troubleshooting. When I try to test it with:
    > $ bin/kafka-console-producer.sh --broker-list localhost:6667 --topic 
    > test_topic
    >
    > It just hangs. When I try to run a Simple Producer, I get the same result.
    >
    > Adaryl "Bob" Wakefield, MBA
    > Principal
    > Mass Street Analytics, LLC
    > 913.938.6685
    > www.massstreet.net
    > www.linkedin.com/in/bobwakefieldmba
    > Twitter: @BobLovesData
    >
    >
    
    
    --
    *  Regards*
    *  Sandeep Nemuri*