Skip to content

Commit 53c4ff3

Browse files
author
Madelung
committed
Producer Beispiel
1 parent 3824ddb commit 53c4ff3

File tree

29 files changed

+606
-0
lines changed

29 files changed

+606
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
31+
<attributes>
32+
<attribute name="maven.pomderived" value="true"/>
33+
</attributes>
34+
</classpathentry>
35+
<classpathentry kind="output" path="target/classes"/>
36+
</classpath>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>hardcoded-schema</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3+
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5+
org.eclipse.jdt.core.compiler.source=1.5
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"type":"record","name":"Pressure","namespace":"org.mitsubishi.pm1.fl.daa","fields":[{"name":"timestamp","type":"string","doc":"DAA Zeitstempel"},{"name":"currentPressureHeadbox","type":"double","doc":"PM1 Stoff//Druck_Stoffaufl_Ist [bar] ()"},{"name":"differencePressure5TG","type":"double","doc":"PM1 Dampf+Kondensat//Differenzdruck 5TG [bar] (6PDIC702-X)"}]}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.mitsubishi.kafkaproducer</groupId>
5+
<artifactId>hardcoded-schema</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<build>
8+
<plugins>
9+
<plugin>
10+
<!-- Set the Java target version to 1.8 -->
11+
<artifactId>maven-compiler-plugin</artifactId>
12+
<version>3.0</version>
13+
<configuration>
14+
<source>1.8</source>
15+
<target>1.8</target>
16+
</configuration>
17+
</plugin>
18+
</plugins>
19+
</build>
20+
<dependencies>
21+
<dependency>
22+
<groupId>io.confluent</groupId>
23+
<artifactId>kafka-avro-serializer</artifactId>
24+
<version>3.1.1</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.kafka</groupId>
28+
<artifactId>kafka_2.12</artifactId>
29+
<version>2.0.0</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.apache.avro</groupId>
33+
<artifactId>avro</artifactId>
34+
<version>1.8.2</version>
35+
</dependency>
36+
</dependencies>
37+
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.mitsubishi.kafkaproducer;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.util.Properties;
7+
import java.util.concurrent.ExecutionException;
8+
9+
import org.apache.avro.Schema;
10+
import org.apache.avro.generic.GenericData;
11+
import org.apache.avro.generic.GenericRecord;
12+
import org.apache.kafka.clients.producer.KafkaProducer;
13+
import org.apache.kafka.clients.producer.ProducerConfig;
14+
import org.apache.kafka.clients.producer.ProducerRecord;
15+
16+
import com.fasterxml.jackson.databind.ser.std.StringSerializer;
17+
18+
import io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig;
19+
import io.confluent.kafka.serializers.KafkaAvroSerializer;
20+
21+
public class Rüdiger {
22+
23+
private static final String TOPIC = "daa-pm1-pressure";
24+
25+
public static void main(final String[] args){
26+
27+
final Properties props = new Properties();
28+
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "tron:9092");
29+
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
30+
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class);
31+
props.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, "http://tron:8081");
32+
String key = "key1";
33+
KafkaProducer producer = new KafkaProducer(props);
34+
try {
35+
Schema schema = new Schema.Parser().parse(new File("./daa-pm1-pressure.2.json"));
36+
GenericRecord avroRecord = new GenericData.Record(schema);
37+
avroRecord.put("timestamp", "test");
38+
avroRecord.put("currentPressureHeadbox", 13.37);
39+
avroRecord.put("differencePressure5TG", 17.71);
40+
ProducerRecord<Object, Object> record = new ProducerRecord<Object, Object>(TOPIC, key, avroRecord);
41+
System.out.println(producer.send(record).get());
42+
} catch (IOException e) {
43+
// TODO Auto-generated catch block
44+
e.printStackTrace();
45+
} catch (InterruptedException e) {
46+
// TODO Auto-generated catch block
47+
e.printStackTrace();
48+
} catch (ExecutionException e) {
49+
// TODO Auto-generated catch block
50+
e.printStackTrace();
51+
}
52+
53+
System.out.printf("BLABLABLA %s", TOPIC);
54+
}
55+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"type":"record","name":"Pressure","namespace":"org.mitsubishi.pm1.fl.daa","fields":[{"name":"timestamp","type":"string","doc":"DAA Zeitstempel"},{"name":"currentPressureHeadbox","type":"double","doc":"PM1 Stoff//Druck_Stoffaufl_Ist [bar] ()"},{"name":"differencePressure5TG","type":"double","doc":"PM1 Dampf+Kondensat//Differenzdruck 5TG [bar] (6PDIC702-X)"}]}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Manifest-Version: 1.0
2+
Built-By: m.madelung
3+
Build-Jdk: 1.8.0_191
4+
Created-By: Maven Integration for Eclipse
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Generated by Maven Integration for Eclipse
2+
#Thu Nov 08 14:36:14 CET 2018
3+
version=0.0.1-SNAPSHOT
4+
groupId=org.mitsubishi.kafkaproducer
5+
m2e.projectName=hardcoded-schema
6+
m2e.projectLocation=C\:\\Users\\m.madelung\\HadoopWorkspace\\hardcoded-schema
7+
artifactId=hardcoded-schema

0 commit comments

Comments
 (0)