Kafka producer and consumer in seperate EC2 instance












0















I have 2 ec2 instances one for Kafka broker and the other for Kafka Consumer. May i know how to connect both the ec2 instance to communicate with each other. If i produce a message in my broker i need to get it in the consumer.



Basically, i am looking for that part of configuration where i need to give the consumer information in the broker ec2 instance and vice versa (whichever way it works) . Do i need to use some api or something ?



I have tried in a single node cluster and it worked.










share|improve this question

























  • You are trying to access from Java or manually from console?

    – asolanki
    Nov 23 '18 at 6:20






  • 1





    You could improve your question by showing exactly what you've tried on a single node that works, and the error that you get when trying it across two nodes.

    – Robin Moffatt
    Nov 23 '18 at 9:03
















0















I have 2 ec2 instances one for Kafka broker and the other for Kafka Consumer. May i know how to connect both the ec2 instance to communicate with each other. If i produce a message in my broker i need to get it in the consumer.



Basically, i am looking for that part of configuration where i need to give the consumer information in the broker ec2 instance and vice versa (whichever way it works) . Do i need to use some api or something ?



I have tried in a single node cluster and it worked.










share|improve this question

























  • You are trying to access from Java or manually from console?

    – asolanki
    Nov 23 '18 at 6:20






  • 1





    You could improve your question by showing exactly what you've tried on a single node that works, and the error that you get when trying it across two nodes.

    – Robin Moffatt
    Nov 23 '18 at 9:03














0












0








0








I have 2 ec2 instances one for Kafka broker and the other for Kafka Consumer. May i know how to connect both the ec2 instance to communicate with each other. If i produce a message in my broker i need to get it in the consumer.



Basically, i am looking for that part of configuration where i need to give the consumer information in the broker ec2 instance and vice versa (whichever way it works) . Do i need to use some api or something ?



I have tried in a single node cluster and it worked.










share|improve this question
















I have 2 ec2 instances one for Kafka broker and the other for Kafka Consumer. May i know how to connect both the ec2 instance to communicate with each other. If i produce a message in my broker i need to get it in the consumer.



Basically, i am looking for that part of configuration where i need to give the consumer information in the broker ec2 instance and vice versa (whichever way it works) . Do i need to use some api or something ?



I have tried in a single node cluster and it worked.







apache-kafka kafka-consumer-api kafka-producer-api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 9:03









Robin Moffatt

6,8421329




6,8421329










asked Nov 23 '18 at 4:41









RanjithRanjith

234




234













  • You are trying to access from Java or manually from console?

    – asolanki
    Nov 23 '18 at 6:20






  • 1





    You could improve your question by showing exactly what you've tried on a single node that works, and the error that you get when trying it across two nodes.

    – Robin Moffatt
    Nov 23 '18 at 9:03



















  • You are trying to access from Java or manually from console?

    – asolanki
    Nov 23 '18 at 6:20






  • 1





    You could improve your question by showing exactly what you've tried on a single node that works, and the error that you get when trying it across two nodes.

    – Robin Moffatt
    Nov 23 '18 at 9:03

















You are trying to access from Java or manually from console?

– asolanki
Nov 23 '18 at 6:20





You are trying to access from Java or manually from console?

– asolanki
Nov 23 '18 at 6:20




1




1





You could improve your question by showing exactly what you've tried on a single node that works, and the error that you get when trying it across two nodes.

– Robin Moffatt
Nov 23 '18 at 9:03





You could improve your question by showing exactly what you've tried on a single node that works, and the error that you get when trying it across two nodes.

– Robin Moffatt
Nov 23 '18 at 9:03












3 Answers
3






active

oldest

votes


















0














It does not matter you are hosting your broker in ec-2 or elsewhere as long as it is accessible to consumer.



A sample consumer in Java using StringDeserializer for both key and value. You need to use the KafkaConsumer API if you are accessing from a Java program



 Properties props = new Properties();
props.put("bootstrap.servers", "YOUR_KAFKA_BROKER_ADDRESS");
props.put("group.id", "test");
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Arrays.asList("foo", "bar"));
while (true) {
ConsumerRecords<String, String> records = consumer.poll(100);
for (ConsumerRecord<String, String> record : records)
System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
}


https://kafka.apache.org/10/javadoc/?org/apache/kafka/clients/consumer/KafkaConsumer.html






share|improve this answer































    0














    If you're using Kafka across machines, you need to configure the listeners correctly. This article explains how: https://rmoff.net/2018/08/02/kafka-listeners-explained/






    share|improve this answer































      0















      where i need to give the consumer information in the broker




      Brokers don't push messages to consumers, so you wouldn't give the information for the consumer to any broker



      Any code that works against a single broker should work for more than one, assuming network settings are configured properly






      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440739%2fkafka-producer-and-consumer-in-seperate-ec2-instance%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        It does not matter you are hosting your broker in ec-2 or elsewhere as long as it is accessible to consumer.



        A sample consumer in Java using StringDeserializer for both key and value. You need to use the KafkaConsumer API if you are accessing from a Java program



         Properties props = new Properties();
        props.put("bootstrap.servers", "YOUR_KAFKA_BROKER_ADDRESS");
        props.put("group.id", "test");
        props.put("enable.auto.commit", "true");
        props.put("auto.commit.interval.ms", "1000");
        props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList("foo", "bar"));
        while (true) {
        ConsumerRecords<String, String> records = consumer.poll(100);
        for (ConsumerRecord<String, String> record : records)
        System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
        }


        https://kafka.apache.org/10/javadoc/?org/apache/kafka/clients/consumer/KafkaConsumer.html






        share|improve this answer




























          0














          It does not matter you are hosting your broker in ec-2 or elsewhere as long as it is accessible to consumer.



          A sample consumer in Java using StringDeserializer for both key and value. You need to use the KafkaConsumer API if you are accessing from a Java program



           Properties props = new Properties();
          props.put("bootstrap.servers", "YOUR_KAFKA_BROKER_ADDRESS");
          props.put("group.id", "test");
          props.put("enable.auto.commit", "true");
          props.put("auto.commit.interval.ms", "1000");
          props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
          props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
          KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
          consumer.subscribe(Arrays.asList("foo", "bar"));
          while (true) {
          ConsumerRecords<String, String> records = consumer.poll(100);
          for (ConsumerRecord<String, String> record : records)
          System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
          }


          https://kafka.apache.org/10/javadoc/?org/apache/kafka/clients/consumer/KafkaConsumer.html






          share|improve this answer


























            0












            0








            0







            It does not matter you are hosting your broker in ec-2 or elsewhere as long as it is accessible to consumer.



            A sample consumer in Java using StringDeserializer for both key and value. You need to use the KafkaConsumer API if you are accessing from a Java program



             Properties props = new Properties();
            props.put("bootstrap.servers", "YOUR_KAFKA_BROKER_ADDRESS");
            props.put("group.id", "test");
            props.put("enable.auto.commit", "true");
            props.put("auto.commit.interval.ms", "1000");
            props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
            props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
            KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
            consumer.subscribe(Arrays.asList("foo", "bar"));
            while (true) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            for (ConsumerRecord<String, String> record : records)
            System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
            }


            https://kafka.apache.org/10/javadoc/?org/apache/kafka/clients/consumer/KafkaConsumer.html






            share|improve this answer













            It does not matter you are hosting your broker in ec-2 or elsewhere as long as it is accessible to consumer.



            A sample consumer in Java using StringDeserializer for both key and value. You need to use the KafkaConsumer API if you are accessing from a Java program



             Properties props = new Properties();
            props.put("bootstrap.servers", "YOUR_KAFKA_BROKER_ADDRESS");
            props.put("group.id", "test");
            props.put("enable.auto.commit", "true");
            props.put("auto.commit.interval.ms", "1000");
            props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
            props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
            KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
            consumer.subscribe(Arrays.asList("foo", "bar"));
            while (true) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            for (ConsumerRecord<String, String> record : records)
            System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
            }


            https://kafka.apache.org/10/javadoc/?org/apache/kafka/clients/consumer/KafkaConsumer.html







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 6:30









            asolankiasolanki

            36829




            36829

























                0














                If you're using Kafka across machines, you need to configure the listeners correctly. This article explains how: https://rmoff.net/2018/08/02/kafka-listeners-explained/






                share|improve this answer




























                  0














                  If you're using Kafka across machines, you need to configure the listeners correctly. This article explains how: https://rmoff.net/2018/08/02/kafka-listeners-explained/






                  share|improve this answer


























                    0












                    0








                    0







                    If you're using Kafka across machines, you need to configure the listeners correctly. This article explains how: https://rmoff.net/2018/08/02/kafka-listeners-explained/






                    share|improve this answer













                    If you're using Kafka across machines, you need to configure the listeners correctly. This article explains how: https://rmoff.net/2018/08/02/kafka-listeners-explained/







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 23 '18 at 9:02









                    Robin MoffattRobin Moffatt

                    6,8421329




                    6,8421329























                        0















                        where i need to give the consumer information in the broker




                        Brokers don't push messages to consumers, so you wouldn't give the information for the consumer to any broker



                        Any code that works against a single broker should work for more than one, assuming network settings are configured properly






                        share|improve this answer




























                          0















                          where i need to give the consumer information in the broker




                          Brokers don't push messages to consumers, so you wouldn't give the information for the consumer to any broker



                          Any code that works against a single broker should work for more than one, assuming network settings are configured properly






                          share|improve this answer


























                            0












                            0








                            0








                            where i need to give the consumer information in the broker




                            Brokers don't push messages to consumers, so you wouldn't give the information for the consumer to any broker



                            Any code that works against a single broker should work for more than one, assuming network settings are configured properly






                            share|improve this answer














                            where i need to give the consumer information in the broker




                            Brokers don't push messages to consumers, so you wouldn't give the information for the consumer to any broker



                            Any code that works against a single broker should work for more than one, assuming network settings are configured properly







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 23 '18 at 15:49









                            cricket_007cricket_007

                            81.2k1142111




                            81.2k1142111






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440739%2fkafka-producer-and-consumer-in-seperate-ec2-instance%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Futebolista

                                Feedback on college project

                                Albești (Vaslui)