title: SNMP-CAMEL-KAFKA
body: <p>I am looking for reference where I can get simple program to send a SNMP trap to Apache Kafka topic using Apache Camel.</p>
  
  <p>Please help me if someone can explain the it using simple java program.</p>
  
  <p>My RouteBuilder configuration</p>
  
  <pre><code>import org.apache.camel.builder.RouteBuilder;
  
  public class SimpleRouteBuilder extends RouteBuilder{
  
      @Override
      public void configure() throws Exception {
  
          String topicName = "topic=first_topic";
          String kafkaServer = "kafka:localhost:9092";
          String zooKeeperHost = "zookeeperHost=localhost&amp;zookeeperPort=2181";
          String serializerClass = "serializerClass=kafka.serializer.StringEncoder";
  
          String toKafka = new StringBuilder().append(kafkaServer).append("?").append(topicName).append("&amp;")
                  .append(zooKeeperHost).append("&amp;").append(serializerClass).toString();
      System.out.println(toKafka);
  
      from("snmp:127.0.0.1:161?protocol=udp&amp;type=POLL&amp;oids=1.3.6.1.2.1.1.5.0").split().tokenize("\n").to(toKafka);
      }
  }
  </code></pre>
  
  <p>Main Method</p>
  
  <pre><code>import org.apache.camel.CamelContext;
  import org.apache.camel.impl.DefaultCamelContext;
  import org.snmp4j.Snmp;
  
  public class MainApp {
  
  public static void main(String[] args) {
      SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder();
      CamelContext ctx = new DefaultCamelContext();
      try {
          ctx.addRoutes(routeBuilder);
          ctx.start();
          Thread.sleep(5 * 60 * 1000);
          ctx.stop();
      }
      catch (Exception e) {
          e.printStackTrace();
      }
  
  }
  }
  </code></pre>