Skip to content

Commit 4e094c8

Browse files
author
h1alexbel
committed
#304 readme
1 parent 2e779e8 commit 4e094c8

1 file changed

Lines changed: 72 additions & 19 deletions

File tree

README.md

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,45 @@ dependencies {
6464
```
6565

6666
## Messages API
67-
To create Kafka Message:
67+
To create Kafka Message with **Topic**, **Key** and **Value**:
6868
```java
69-
Data<String> string =
70-
new KfData<>(
71-
"string-data", //data
72-
"strings", //topic
73-
1 //partition
69+
final Message<String, String> msg = new Tkv<>("test.topic", "test-k", "test-v");
70+
```
71+
72+
Creation Kafka Message with **Partition**:
73+
```java
74+
final Message<String, String> msg =
75+
new WithPartition<>(
76+
0,
77+
new Tkv<>(
78+
"test.topic",
79+
"test-k",
80+
"test-v"
81+
)
7482
);
7583
```
7684

85+
Creation Kafka Message with **Timestamp**:
86+
```java
87+
final Message<String, String> msg =
88+
new Timestamped<>(
89+
tmstmp,
90+
new WithPartition<>(
91+
partition,
92+
new Tkv<>(
93+
topic,
94+
key,
95+
value
96+
)
97+
)
98+
);
99+
```
100+
77101
## Producer API
78102
To create Kafka Producer you can wrap original [KafkaProducer](https://kafka.apache.org/23/javadoc/index.html?org/apache/kafka/clients/producer/KafkaProducer.html):
79103
```java
80-
KafkaProducer origin = ...;
81-
Producer<String, String> producer = new KfProducer<>(origin);
104+
final KafkaProducer origin = ...;
105+
final Producer<String, String> producer = new KfProducer<>(origin);
82106
```
83107
Or construct it with [KfFlexible](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/KfFlexible.java):
84108
```java
@@ -115,13 +139,15 @@ To send a [message](#messages-api):
115139
```java
116140
try (final Producer<String, String> producer = ...) {
117141
producer.send(
118-
"key2012",
119-
new KfData<>(
120-
"newRest28",
121-
"orders",
122-
1
142+
new WithPartition<>(
143+
0,
144+
new Tkv<>(
145+
"xyz.topic",
146+
"key",
147+
"message"
123148
)
124-
);
149+
)
150+
);
125151
} catch (Exception e) {
126152
throw new IllegalStateException(e);
127153
}
@@ -151,8 +177,8 @@ final Producer<String, String> producer =
151177
## Consumer API
152178
To create Kafka Consumer you can wrap original [KafkaConsumer](https://kafka.apache.org/23/javadoc/index.html?org/apache/kafka/clients/consumer/KafkaConsumer.html):
153179
```java
154-
KafkaConsumer origin = ...;
155-
Consumer<String, String> producer = new KfConsumer<>(origin);
180+
final KafkaConsumer origin = ...;
181+
final Consumer<String, String> producer = new KfConsumer<>(origin);
156182
```
157183
Using [KfFlexible](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/KfFlexible.java):
158184
```java
@@ -311,9 +337,36 @@ final Consumer<Object, String> consumer =
311337
);
312338
final Producer<String, String> producer =
313339
new FkProducer<>(UUID.randomUUID(), this.broker);
314-
producer.send("test1", new KfData<>("test-data-1", topic, 0));
315-
producer.send("test2", new KfData<>("test-data-2", topic, 0));
316-
producer.send("test3", new KfData<>("test-data-3", topic, 0));
340+
producer.send(
341+
new WithPartition<>(
342+
0,
343+
new Tkv<>(
344+
topic,
345+
"test1",
346+
"test-data-1"
347+
)
348+
)
349+
);
350+
producer.send(
351+
new WithPartition<>(
352+
0,
353+
new Tkv<>(
354+
topic,
355+
"test2",
356+
"test-data-2"
357+
)
358+
)
359+
);
360+
producer.send(
361+
new WithPartition<>(
362+
0,
363+
new Tkv<>(
364+
topic,
365+
"test-data-3",
366+
"test3"
367+
)
368+
)
369+
);
317370
final ConsumerRecords<Object, String> records =
318371
consumer.records(topic, Duration.ofSeconds(1L));
319372
final List<String> datasets = new ListOf<>();

0 commit comments

Comments
 (0)