-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27e9a75
commit d66ee57
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
id("java") | ||
} | ||
|
||
group = "rs.iggy" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation(project(":sdk")) | ||
implementation("org.slf4j:slf4j-api:2.0.9") | ||
runtimeOnly("ch.qos.logback:logback-classic:1.4.12") | ||
} |
72 changes: 72 additions & 0 deletions
72
examples/simple-producer/src/main/java/rs/iggy/SimpleProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package rs.iggy; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import rs.iggy.clients.blocking.tcp.IggyTcpClient; | ||
import rs.iggy.identifier.StreamId; | ||
import rs.iggy.identifier.TopicId; | ||
import rs.iggy.message.BigIntegerMessageId; | ||
import rs.iggy.message.MessageToSend; | ||
import rs.iggy.message.Partitioning; | ||
import rs.iggy.message.PartitioningKind; | ||
import rs.iggy.stream.StreamDetails; | ||
import rs.iggy.topic.CompressionAlgorithm; | ||
import rs.iggy.topic.TopicDetails; | ||
import java.math.BigInteger; | ||
import java.util.Optional; | ||
import static java.util.Collections.singletonList; | ||
import static java.util.Optional.empty; | ||
|
||
public class SimpleProducer { | ||
private static final String STREAM_NAME = "dev01"; | ||
private static final StreamId STREAM_ID = StreamId.of(STREAM_NAME); | ||
private static final String TOPIC_NAME = "events"; | ||
private static final TopicId TOPIC_ID = TopicId.of(TOPIC_NAME); | ||
private static final Logger log = LoggerFactory.getLogger(SimpleProducer.class); | ||
|
||
public static void main(String[] args) { | ||
IggyTcpClient client = new IggyTcpClient("localhost", 8090); | ||
client.users().login("iggy", "iggy"); | ||
|
||
createStream(client); | ||
createTopic(client); | ||
|
||
int counter = 0; | ||
while (counter++ < 1000) { | ||
var text = "message from simple producer " + counter; | ||
var message = new MessageToSend(new BigIntegerMessageId(BigInteger.ZERO), text.getBytes(), empty()); | ||
client.messages() | ||
.sendMessages(STREAM_ID, | ||
TOPIC_ID, | ||
new Partitioning(PartitioningKind.Balanced, new byte[0]), | ||
singletonList(message)); | ||
log.debug("Message {} sent", counter); | ||
} | ||
|
||
} | ||
|
||
private static void createStream(IggyTcpClient client) { | ||
Optional<StreamDetails> stream = client.streams().getStream(STREAM_ID); | ||
if (stream.isPresent()) { | ||
return; | ||
} | ||
client.streams().createStream(empty(), STREAM_NAME); | ||
} | ||
|
||
private static void createTopic(IggyTcpClient client) { | ||
Optional<TopicDetails> topic = client.topics().getTopic(STREAM_ID, TOPIC_ID); | ||
if (topic.isPresent()) { | ||
return; | ||
} | ||
client.topics() | ||
.createTopic(STREAM_ID, | ||
empty(), | ||
1L, | ||
CompressionAlgorithm.none, | ||
BigInteger.ZERO, | ||
BigInteger.ZERO, | ||
empty(), | ||
TOPIC_NAME); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters