Search in sources :

Example 21 with Environment

use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.

the class ProducerUsage method producerSubEntryBatchingCompression.

void producerSubEntryBatchingCompression() {
    Environment environment = Environment.builder().build();
    // tag::producer-sub-entry-batching-and-compression[]
    Producer producer = environment.producerBuilder().stream("my-stream").batchSize(// <1>
    100).subEntrySize(// <2>
    10).compression(// <3>
    Compression.ZSTD).build();
// end::producer-sub-entry-batching-and-compression[]
}
Also used : Producer(com.rabbitmq.stream.Producer) Environment(com.rabbitmq.stream.Environment)

Example 22 with Environment

use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.

the class ProducerUsage method producerSubEntryBatching.

void producerSubEntryBatching() {
    Environment environment = Environment.builder().build();
    // tag::producer-sub-entry-batching[]
    Producer producer = environment.producerBuilder().stream("my-stream").batchSize(// <1>
    100).subEntrySize(// <2>
    10).build();
// end::producer-sub-entry-batching[]
}
Also used : Producer(com.rabbitmq.stream.Producer) Environment(com.rabbitmq.stream.Environment)

Example 23 with Environment

use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.

the class ProducerUsage method producerPublish.

void producerPublish() {
    Environment environment = Environment.builder().build();
    Producer producer = environment.producerBuilder().stream("my-stream").build();
    // tag::producer-publish[]
    // <1>
    byte[] messagePayload = "hello".getBytes(StandardCharsets.UTF_8);
    producer.send(// <2>
    producer.messageBuilder().addData(messagePayload).build(), confirmationStatus -> {
        // <3>
        if (confirmationStatus.isConfirmed()) {
        // the message made it to the broker
        } else {
        // the message did not make it to the broker
        }
    });
// end::producer-publish[]
}
Also used : Producer(com.rabbitmq.stream.Producer) Environment(com.rabbitmq.stream.Environment)

Example 24 with Environment

use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.

the class SuperStreamUsage method producerSimple.

void producerSimple() {
    Environment environment = Environment.builder().build();
    // tag::producer-simple[]
    Producer producer = environment.producerBuilder().stream(// <1>
    "invoices").routing(// <2>
    message -> message.getProperties().getMessageIdAsString()).producerBuilder().build();
    // ...
    // <4>
    producer.close();
// end::producer-simple[]
}
Also used : Producer(com.rabbitmq.stream.Producer) Environment(com.rabbitmq.stream.Environment)

Example 25 with Environment

use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.

the class SuperStreamUsage method producerKeyRoutingStrategy.

void producerKeyRoutingStrategy() {
    Environment environment = Environment.builder().build();
    // tag::producer-key-routing-strategy[]
    Producer producer = environment.producerBuilder().stream("invoices").routing(// <1>
    msg -> msg.getApplicationProperties().get("region").toString()).key().producerBuilder().build();
// end::producer-key-routing-strategy[]
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) MessageHandler(com.rabbitmq.stream.MessageHandler) List(java.util.List) Message(com.rabbitmq.stream.Message) Environment(com.rabbitmq.stream.Environment) Consumer(com.rabbitmq.stream.Consumer) Producer(com.rabbitmq.stream.Producer) Collections(java.util.Collections) RoutingStrategy(com.rabbitmq.stream.RoutingStrategy) Producer(com.rabbitmq.stream.Producer) Environment(com.rabbitmq.stream.Environment)

Aggregations

Environment (com.rabbitmq.stream.Environment)35 Producer (com.rabbitmq.stream.Producer)20 Test (org.junit.jupiter.api.Test)13 Consumer (com.rabbitmq.stream.Consumer)12 Message (com.rabbitmq.stream.Message)12 Address (com.rabbitmq.stream.Address)10 Collections (java.util.Collections)10 OffsetSpecification (com.rabbitmq.stream.OffsetSpecification)9 List (java.util.List)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 ConsumerBuilder (com.rabbitmq.stream.ConsumerBuilder)7 StreamException (com.rabbitmq.stream.StreamException)7 Duration (java.time.Duration)7 ChannelCustomizer (com.rabbitmq.stream.ChannelCustomizer)6 ConfirmationHandler (com.rabbitmq.stream.ConfirmationHandler)6 ProducerBuilder (com.rabbitmq.stream.ProducerBuilder)6 StreamCreator (com.rabbitmq.stream.StreamCreator)6 SslHandler (io.netty.handler.ssl.SslHandler)6 StandardCharsets (java.nio.charset.StandardCharsets)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6