Skip to content

Commit f4f7b23

Browse files
committed
Merge branch '__rultor'
2 parents 77f0886 + f7a5911 commit f4f7b23

3 files changed

Lines changed: 96 additions & 97 deletions

File tree

README.md

Lines changed: 74 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,29 @@ To create Kafka Producer you can wrap original [KafkaProducer](https://kafka.apa
5858
KafkaProducer origin = ...;
5959
Producer<String, String> producer = new KfProducer<>(origin);
6060
```
61-
Or construct it with [ProducerSettings](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/ProducerSettings.java) or even with XML file:
61+
Or construct it with [KfFlexible](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/KfFlexible.java):
6262
```java
63-
ProducerSettings<String, User> settings = ...;
64-
Producer<String, User> producer = new KfProducer<>(settings);
65-
Producer<String, User> xml =
66-
new KfProducer(
67-
new XMLDocument(
68-
new File(
69-
"producer.xml"
70-
)
71-
)
72-
);
73-
```
74-
To create Kafka Producer Settings (Config):
75-
Using objects:
76-
```java
77-
ProducerSettings<String, String> settings =
78-
new KfProducerSettings<>(
79-
new KfProducerParams(
80-
new KfParams(
81-
new ValueSerializer("org.apache.kafka.common.serialization.StringSerializer"),
82-
new KeySerializer("org.apache.kafka.common.serialization.StringSerializer"),
83-
new BootstrapServers("localhost:9092")
63+
final Producer<String, String> producer =
64+
new KfProducer<>(
65+
new KfFlexible<>(
66+
new KfProducerParams(
67+
new KfParams(
68+
new BootstrapServers("localhost:9092"),
69+
new KeySerializer("org.apache.kafka.common.serialization.StringSerializer"),
70+
new ValueSerializer("org.apache.kafka.common.serialization.StringSerializer")
8471
)
72+
)
8573
)
86-
);
74+
);
8775
```
88-
Or using XML file:
76+
Or create it with XML file:
8977
```java
90-
ProducerSettings<String, String> settings =
91-
new KfProducerSettings<>(
92-
"producer.xml"
78+
final Producer<String, String> producer =
79+
new KfProducer<>(
80+
new KfXmlFlexible<String, String>("producer.xml") // file with producer config
81+
.producer()
9382
);
9483
```
95-
9684
btw, your [XML](https://en.wikipedia.org/wiki/XML#:~:text=Extensible%20Markup%20Language%20(XML)%20is,%2Dreadable%20and%20machine%2Dreadable.) file should be in the ```resources``` look like:
9785
```xml
9886
<producer>
@@ -104,29 +92,18 @@ btw, your [XML](https://en.wikipedia.org/wiki/XML#:~:text=Extensible%20Markup%20
10492

10593
To send a [message](#messages-api):
10694
```java
107-
try (
108-
final Producer<String, String> producer =
109-
new KfProducer<>(
110-
new KfProducerSettings<String, String>(
111-
new XMLDocument(
112-
new File(
113-
"params.xml"
114-
)
115-
)
116-
).producer()
117-
)
118-
) {
119-
producer.send(
120-
"key2012",
121-
new KfData<>(
122-
"newRest28",
123-
"orders",
124-
1
125-
)
126-
);
127-
} catch (Exception e) {
95+
try (final Producer<String, String> producer = ...) {
96+
producer.send(
97+
"key2012",
98+
new KfData<>(
99+
"newRest28",
100+
"orders",
101+
1
102+
)
103+
);
104+
} catch (Exception e) {
128105
throw new IllegalStateException(e);
129-
}
106+
}
130107
}
131108
```
132109

@@ -136,47 +113,29 @@ To create Kafka Consumer you can wrap original [KafkaConsumer](https://kafka.apa
136113
KafkaConsumer origin = ...;
137114
Consumer<String, String> producer = new KfConsumer<>(origin);
138115
```
139-
140-
Using XML:
116+
Using [KfFlexible](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/KfFlexible.java):
141117
```java
142-
Consumer<String, String> consumer =
143-
new KfConsumer<>(
144-
new XMLDocument(
145-
new File("consumer.xml")
118+
final Consumer<String, String> consumer =
119+
new KfConsumer<>(
120+
new KfFlexible<>(
121+
new KfConsumerParams(
122+
new KfParams(
123+
new BootstrapServers("localhost:9092"),
124+
new GroupId("1"),
125+
new KeyDeserializer("org.apache.kafka.common.serialization.StringDeserializer"),
126+
new ValueDeserializer("org.apache.kafka.common.serialization.StringDeserializer")
127+
)
128+
)
146129
)
147-
);
148-
149-
```
150-
Also, can be created with [ConsumerSettings](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/ConsumerSettings.java):
151-
```java
152-
ConsumerSettings<String, User> settings = ...;
153-
Consumer<String, User> consumer = new KfConsumer<>(settings);
154-
```
155-
156-
To create ConsumerSettings:
157-
```java
158-
ConsumerSettings<String, String> settings =
159-
new KfConsumerSettings<>(
160-
new KfConsumerParams(
161-
new KfParams(
162-
new BootstrapServers("localhost:9092"),
163-
new GroupId("1"),
164-
new KeyDeserializer("org.apache.kafka.common.serialization.StringDeserializer"),
165-
new ValueDeserializer("org.apache.kafka.common.serialization.StringDeserializer")
166-
)
167-
)
168-
);
130+
);
169131
```
170132

171-
XML File approach:
133+
And XML File approach:
172134
```java
173-
final ConsumerSettings<String, String> settings =
174-
new KfConsumerSettings<>(
175-
new XMLDocument(
176-
new File(
177-
"consumer.xml"
178-
)
179-
)
135+
final Consumer<String, String> consumer =
136+
new KfConsumer<>(
137+
new KfXmlFlexible<String, String>("consumer.xml")
138+
.consumer()
180139
);
181140
```
182141

@@ -191,17 +150,39 @@ Again, [XML](https://en.wikipedia.org/wiki/XML#:~:text=Extensible%20Markup%20Lan
191150
```
192151

193152
Consuming messages:
194-
TBD
153+
Firstly, you need to be subscribed on a particular topic and only then iterate over data in the topic:
154+
```java
155+
try (
156+
final Consumer<String, String> consumer =
157+
new KfConsumer<>(
158+
new KfFlexible<>(
159+
new KfConsumerParams(
160+
new KfParams(
161+
new BootstrapServers(this.severs),
162+
new GroupId("1"),
163+
new AutoOffsetResetConfig("earliest"),
164+
new KeyDeserializer("org.apache.kafka.common.serialization.StringDeserializer"),
165+
new ValueDeserializer("org.apache.kafka.common.serialization.StringDeserializer")
166+
)
167+
)
168+
)
169+
)
170+
) {
171+
consumer.subscribe(new ListOf<>("orders-saga-init")));
172+
List<Dataized<String>> result = consumer.iterate("orders-saga-init", Duration.ofSeconds(5L));
173+
}
174+
}
175+
```
195176

196177
## Config API
197178
| Kafka Property | eo-kafka API |
198179
|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
199-
| `bootstrap.servers` | [BootstrapServers](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/settings/BootstrapServers.java) |
200-
| `key.serializer` | [KeySerializer](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/settings/KeySerializer.java) |
201-
| `value.serializer` | [ValueSerializer](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/settings/ValueSerializer.java) |
202-
| `key.deserializer` | [KeyDeserializer](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/settings/KeyDeserializer.java) |
203-
| `value.deserializer` | [ValueDeserializer](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/settings/ValueDeserializer.java) |
204-
| `group.id` | [GroupId](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/settings/GroupId.java) |
180+
| `bootstrap.servers` | [BootstrapServers](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/BootstrapServers.java) |
181+
| `key.serializer` | [KeySerializer](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/KeySerializer.java) |
182+
| `value.serializer` | [ValueSerializer](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/ValueSerializer.java) |
183+
| `key.deserializer` | [KeyDeserializer](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/KeyDeserializer.java) |
184+
| `value.deserializer` | [ValueDeserializer](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/ValueDeserializer.java) |
185+
| `group.id` | [GroupId](https://github.com/eo-cqrs/eo-kafka/blob/master/src/main/java/io/github/eocqrs/kafka/parameters/GroupId.java) |
205186

206187
## How to Contribute
207188

src/main/java/io/github/eocqrs/kafka/parameters/KfFlexible.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
import org.apache.kafka.clients.consumer.KafkaConsumer;
88
import org.apache.kafka.clients.producer.KafkaProducer;
99

10-
/**
11-
* @todo #147:30m/DEV Update documentation
12-
* Add use-cases to README for KfFlexible.
13-
*/
1410
/**
1511
* KfFlexibleSettings allow you to add custom settings.
1612
*

src/test/java/io/github/eocqrs/kafka/consumer/KfConsumerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/*
2+
* Copyright (c) 2022 Aliaksei Bialiauski, EO-CQRS
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
123
package io.github.eocqrs.kafka.consumer;
224

325
import io.github.eocqrs.kafka.Consumer;

0 commit comments

Comments
 (0)