Search in sources :

Example 6 with Environment

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

the class StreamEnvironmentTest method locatorShouldReconnectIfConnectionIsLost.

@Test
@TestUtils.DisabledIfRabbitMqCtlNotSet
void locatorShouldReconnectIfConnectionIsLost(TestInfo info) throws Exception {
    try (Environment environment = environmentBuilder.recoveryBackOffDelayPolicy(BackOffDelayPolicy.fixed(Duration.ofSeconds(1))).build()) {
        String s = streamName(info);
        environment.streamCreator().stream(s).create();
        environment.deleteStream(s);
        Host.killConnection("rabbitmq-stream-locator-0");
        environment.streamCreator().stream(s).create();
        try {
            Producer producer = environment.producerBuilder().stream(s).build();
            Consumer consumer = environment.consumerBuilder().stream(s).build();
            producer.close();
            consumer.close();
        } finally {
            environment.deleteStream(s);
        }
    }
}
Also used : Producer(com.rabbitmq.stream.Producer) Consumer(com.rabbitmq.stream.Consumer) Environment(com.rabbitmq.stream.Environment) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with Environment

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

the class StreamEnvironmentTest method createDelete.

@Test
void createDelete(TestInfo info) {
    try (Environment environment = environmentBuilder.build();
        Client client = new Client()) {
        String s = streamName(info);
        environment.streamCreator().stream(s).create();
        Client.StreamMetadata metadata = client.metadata(s).get(s);
        assertThat(metadata.isResponseOk()).isTrue();
        environment.deleteStream(s);
        metadata = client.metadata(s).get(s);
        assertThat(metadata.isResponseOk()).isFalse();
        assertThat(metadata.getResponseCode()).isEqualTo(Constants.RESPONSE_CODE_STREAM_DOES_NOT_EXIST);
    }
}
Also used : Environment(com.rabbitmq.stream.Environment) StreamMetadata(com.rabbitmq.stream.impl.Client.StreamMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with Environment

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

the class EnvironmentUsage method environmentCreation.

void environmentCreation() throws Exception {
    // tag::environment-creation[]
    // <1>
    Environment environment = Environment.builder().build();
    // ...
    // <2>
    environment.close();
// end::environment-creation[]
}
Also used : Environment(com.rabbitmq.stream.Environment)

Example 9 with Environment

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

the class EnvironmentUsage method createStreamWithTimeBasedRetention.

void createStreamWithTimeBasedRetention() {
    Environment environment = Environment.builder().build();
    // tag::stream-creation-time-based-retention[]
    environment.streamCreator().stream("my-stream").maxAge(// <1>
    Duration.ofHours(6)).maxSegmentSizeBytes(// <2>
    ByteCapacity.MB(500)).create();
// end::stream-creation-time-based-retention[]
}
Also used : Environment(com.rabbitmq.stream.Environment)

Example 10 with Environment

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

the class EnvironmentUsage method createStream.

void createStream() {
    Environment environment = Environment.builder().build();
    // tag::stream-creation[]
    // <1>
    environment.streamCreator().stream("my-stream").create();
// end::stream-creation[]
}
Also used : 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