Für PUT anstelle von POST wird eine `FooMessage` als `foo` verschickt
[demos/kafka/training] / src / main / java / de / juplo / kafka / RestProducer.java
index 6c852ce..70b327a 100644 (file)
@@ -42,6 +42,7 @@ public class RestProducer
     props.put("value.serializer", JsonSerializer.class.getName());
     props.put(JsonSerializer.TYPE_MAPPINGS,
         "message:" + ClientMessage.class.getName() + "," +
+        "foo:" + FooMessage.class.getName() + "," +
         "greeting:" + Greeting.class.getName());
 
     this.producer = new KafkaProducer<>(props);
@@ -52,6 +53,7 @@ public class RestProducer
       @PathVariable String key,
       @RequestBody String value)
   {
+    key = key.trim();
     final ProducerRecord<String, Object> record = new ProducerRecord<>(
         topic,  // Topic
         key,    // Key
@@ -61,10 +63,24 @@ public class RestProducer
     return send(record);
   }
 
+  @PutMapping(path = "{key}")
+  public DeferredResult<ProduceResult> message(@PathVariable String key)
+  {
+    key = key.trim();
+    final ProducerRecord<String, Object> record = new ProducerRecord<>(
+        topic,  // Topic
+        key,    // Key
+        new FooMessage(key, System.currentTimeMillis()) // Value
+    );
+
+    return send(record);
+  }
+
   @PostMapping(path = "/")
   public DeferredResult<ProduceResult> greeting(
       @RequestBody String name)
   {
+    name = name.trim();
     final ProducerRecord<String, Object> record = new ProducerRecord<>(
         topic,  // Topic
         name,    // Key