title: Subscribe to Kafka Topics over websocket from client side
body: <p>We are trying to listen to the kafka topics using js code from browser once the Producer from server side pushes messages to the particular kafka topic.</p>
  
  <p>In the server side, kafka server and zookeeper are running at 9092 and 2181 port respectively.</p>
  
  <pre><code>String topicName = "test"; 
  Properties props = new Properties();
  props.put("bootstrap.servers", "localhost:9092");     
  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");
  props.put("partitioner.class",
          "org.apache.kafka.clients.producer.internals.DefaultPartitioner");
  Thread.currentThread().setContextClassLoader(null);
  Producer&lt;String, String&gt; producer = new KafkaProducer &lt;String, String&gt;(props);
  for(int i = 0; i &lt; 10; i++){
      producer.send(new ProducerRecord&lt;String, String&gt;(topicName, 
         Integer.toString(i), Integer.toString(i) + i));
      }
  producer.close();
  }catch(Exception e){
      e.printStackTrace();
  }
  </code></pre>
  
  <p>Client code snippet:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;My Page&lt;/head&gt;
  &lt;script src="stomp.js"&gt;&lt;/script&gt;
  &lt;script src="http://cdn.sockjs.org/sockjs-0.3.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  console.log('Starting: ');
  var socket = new SockJS('ws://localhost:9092');
  client = Stomp.over(socket);
  client.connect( "", "",
          function() {
              console.log('Connected: ');
              client.subscribe("/topic/test",
                  function( message ) {
                      alert( message );
                  }  
              );
          }
  );
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>From client side, while we are trying to connect via ws, only the Starting: console is getting printed and Connected: is not getting rpinted since the 
  websocket connection to the kafka server is not getting succeeded.</p>
  
  <p>Since STOMP is not directly supported for Kafka, we tried to sue SockJS.</p>
  
  <p>Can anyone please help us out to achieve this functionality.</p>