use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class EnvironmentUsage method createStreamWithRetention.
void createStreamWithRetention() {
Environment environment = Environment.builder().build();
// tag::stream-creation-retention[]
environment.streamCreator().stream("my-stream").maxLengthBytes(// <1>
ByteCapacity.GB(10)).maxSegmentSizeBytes(// <2>
ByteCapacity.MB(500)).create();
// end::stream-creation-retention[]
}
use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class SanityCheck method main.
public static void main(String[] args) {
Environment env = null;
String s = "sanity-check-stream";
try {
LOGGER.info("connecting");
env = Environment.builder().build();
LOGGER.info("connected");
env.streamCreator().stream(s).create();
LOGGER.info("test stream created");
CountDownLatch publishLatch = new CountDownLatch(1);
Producer producer = env.producerBuilder().stream(s).build();
LOGGER.info("producer created");
producer.send(producer.messageBuilder().addData("".getBytes(StandardCharsets.UTF_8)).build(), confirmationStatus -> publishLatch.countDown());
LOGGER.info("waiting for publish confirm");
boolean done = publishLatch.await(5, TimeUnit.SECONDS);
if (!done) {
throw new IllegalStateException("Did not receive publish confirm");
}
LOGGER.info("got publish confirm");
CountDownLatch consumeLatch = new CountDownLatch(1);
env.consumerBuilder().stream(s).offset(OffsetSpecification.first()).messageHandler((context, message) -> consumeLatch.countDown()).build();
LOGGER.info("created consumer, waiting for message");
done = consumeLatch.await(5, TimeUnit.SECONDS);
if (!done) {
throw new IllegalStateException("Did not receive message");
}
LOGGER.info("got message");
LOGGER.info("Test succeeded with Stream Client {}", Environment.class.getPackage().getImplementationVersion());
System.exit(0);
} catch (Exception e) {
LOGGER.info("Test failed with Stream Client {}", Environment.class.getPackage().getImplementationVersion(), e);
System.exit(1);
} finally {
if (env != null) {
env.deleteStream(s);
env.close();
}
}
}
use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class ProducerUsage method producerCreation.
void producerCreation() throws Exception {
Environment environment = Environment.builder().build();
// tag::producer-creation[]
Producer producer = // <1>
environment.producerBuilder().stream(// <2>
"my-stream").build();
// ...
// <4>
producer.close();
// end::producer-creation[]
}
use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class ProducerUsage method producerWithNameQueryLastPublishingId.
void producerWithNameQueryLastPublishingId() {
Environment environment = Environment.builder().build();
// tag::producer-queries-last-publishing-id[]
Producer producer = environment.producerBuilder().name(// <1>
"my-app-producer").confirmTimeout(// <2>
Duration.ZERO).stream("my-stream").build();
// <3>
long nextPublishingId = producer.getLastPublishingId() + 1;
while (moreContent(nextPublishingId)) {
// <4>
byte[] content = getContent(nextPublishingId);
Message message = producer.messageBuilder().publishingId(// <5>
nextPublishingId).addData(content).build();
producer.send(message, confirmationStatus -> {
});
nextPublishingId++;
}
// end::producer-queries-last-publishing-id[]
}
use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class ProducerUsage method producerComplexMessage.
void producerComplexMessage() {
Environment environment = Environment.builder().build();
Producer producer = environment.producerBuilder().stream("my-stream").build();
// tag::producer-publish-complex-message[]
Message message = // <1>
producer.messageBuilder().properties().messageId(UUID.randomUUID()).correlationId(UUID.randomUUID()).contentType("text/plain").messageBuilder().addData(// <4>
"hello".getBytes(StandardCharsets.UTF_8)).build();
// <6>
producer.send(message, confirmationStatus -> {
});
// end::producer-publish-complex-message[]
}
Aggregations