Cleanup Confluent schema registry sample code
* Use best practices * Use SL4J * Tidy formatting
This commit is contained in:
@@ -76,11 +76,11 @@ java -jar target/confluent-schema-registry-integration-producer2-4.0.0-SNAPSHOT.
|
||||
The producer apps each expose a REST endpoint which sends a sample Kafka event when invoked. Execute the following commands to send some sample data.
|
||||
[source,bash]
|
||||
----
|
||||
curl -X POST http://localhost:9009/messages
|
||||
curl -X POST http://localhost:9010/messages
|
||||
curl -X POST http://localhost:9009/messages
|
||||
curl -X POST http://localhost:9009/messages
|
||||
curl -X POST http://localhost:9010/messages
|
||||
curl -X POST http://localhost:9009/randomMessage
|
||||
curl -X POST http://localhost:9010/randomMessage
|
||||
curl -X POST http://localhost:9009/randomMessage
|
||||
curl -X POST http://localhost:9009/randomMessage
|
||||
curl -X POST http://localhost:9010/randomMessage
|
||||
----
|
||||
|
||||
===== View consumer output
|
||||
|
||||
@@ -3,24 +3,25 @@ package sample.consumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.example.Sensor;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(proxyBeanMethods = false)
|
||||
public class ConfluentAvroConsumerApplication {
|
||||
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
private final Logger logger = LoggerFactory.getLogger(ConfluentAvroConsumerApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ConfluentAvroConsumerApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Consumer<Sensor> process() {
|
||||
return input -> logger.info("input: " + input);
|
||||
Consumer<Sensor> process() {
|
||||
return input -> logger.info("input: {}", input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,14 +7,12 @@ spring:
|
||||
consumer:
|
||||
useNativeDecoding: true
|
||||
kafka:
|
||||
|
||||
# binder:
|
||||
# consumerProperties:
|
||||
# value:
|
||||
# subject:
|
||||
# name:
|
||||
# strategy: io.confluent.kafka.serializers.subject.RecordNameStrategy
|
||||
|
||||
bindings:
|
||||
process-in-0:
|
||||
consumer:
|
||||
|
||||
@@ -9,11 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.stream.function.StreamBridge;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(proxyBeanMethods = false)
|
||||
@RestController
|
||||
public class ConfluentAvroProducer1Application {
|
||||
|
||||
@@ -26,6 +25,12 @@ public class ConfluentAvroProducer1Application {
|
||||
SpringApplication.run(ConfluentAvroProducer1Application.class, args);
|
||||
}
|
||||
|
||||
@PostMapping("/randomMessage")
|
||||
public String sendRandomMessage() {
|
||||
streamBridge.send("supplier-out-0", randomSensor());
|
||||
return "ok, have fun with v1 payload!";
|
||||
}
|
||||
|
||||
private Sensor randomSensor() {
|
||||
Sensor sensor = new Sensor();
|
||||
sensor.setId(UUID.randomUUID() + "-v1");
|
||||
@@ -34,13 +39,6 @@ public class ConfluentAvroProducer1Application {
|
||||
sensor.setTemperature(random.nextFloat() * 50);
|
||||
return sensor;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/messages", method = RequestMethod.POST)
|
||||
public String sendMessage() {
|
||||
streamBridge.send("supplier-out-0", randomSensor());
|
||||
return "ok, have fun with v1 payload!";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@ spring:
|
||||
# subject:
|
||||
# name:
|
||||
# strategy: io.confluent.kafka.serializers.subject.RecordNameStrategy
|
||||
|
||||
bindings:
|
||||
supplier-out-0:
|
||||
producer:
|
||||
configuration:
|
||||
value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
|
||||
schema.registry.url: http://localhost:8081
|
||||
|
||||
server.port: 9009
|
||||
|
||||
@@ -9,11 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.stream.function.StreamBridge;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(proxyBeanMethods = false)
|
||||
@RestController
|
||||
public class ConfluentAvroProducer2Application {
|
||||
|
||||
@@ -26,6 +25,12 @@ public class ConfluentAvroProducer2Application {
|
||||
SpringApplication.run(ConfluentAvroProducer2Application.class, args);
|
||||
}
|
||||
|
||||
@PostMapping("/randomMessage")
|
||||
public String sendRandomMessage() {
|
||||
streamBridge.send("supplier-out-0", randomSensor());
|
||||
return "ok, have fun with v2 payload!";
|
||||
}
|
||||
|
||||
private Sensor randomSensor() {
|
||||
Sensor sensor = new Sensor();
|
||||
sensor.setId(UUID.randomUUID().toString() + "-v2");
|
||||
@@ -36,11 +41,5 @@ public class ConfluentAvroProducer2Application {
|
||||
sensor.setMagneticField(null);
|
||||
return sensor;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/messages", method = RequestMethod.POST)
|
||||
public String sendMessage() {
|
||||
streamBridge.send("supplier-out-0", randomSensor());
|
||||
return "ok, have fun with v2 payload!";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,17 +7,17 @@ spring:
|
||||
producer:
|
||||
useNativeEncoding: true
|
||||
kafka:
|
||||
# binder:
|
||||
# producerProperties:
|
||||
# value:
|
||||
# subject:
|
||||
# name:
|
||||
# strategy: io.confluent.kafka.serializers.subject.RecordNameStrategy
|
||||
|
||||
# binder:
|
||||
# producerProperties:
|
||||
# value:
|
||||
# subject:
|
||||
# name:
|
||||
# strategy: io.confluent.kafka.serializers.subject.RecordNameStrategy
|
||||
bindings:
|
||||
supplier-out-0:
|
||||
producer:
|
||||
configuration:
|
||||
value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
|
||||
schema.registry.url: http://localhost:8081
|
||||
|
||||
server.port: 9010
|
||||
|
||||
Reference in New Issue
Block a user