use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class SuperStreamUsage method consumerSimple.
void consumerSimple() {
Environment environment = Environment.builder().build();
// tag::consumer-simple[]
Consumer consumer = environment.consumerBuilder().superStream(// <1>
"invoices").messageHandler((context, message) -> {
// message processing
}).build();
// ...
// <2>
consumer.close();
// end::consumer-simple[]
}
use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class SuperStreamUsage method producerCustomRoutingStrategy.
void producerCustomRoutingStrategy() {
Environment environment = Environment.builder().build();
// tag::producer-custom-routing-strategy[]
AtomicLong messageCount = new AtomicLong(0);
RoutingStrategy routingStrategy = (message, metadata) -> {
List<String> partitions = metadata.partitions();
String stream = partitions.get((int) messageCount.getAndIncrement() % partitions.size());
return Collections.singletonList(stream);
};
Producer producer = environment.producerBuilder().stream("invoices").routing(// <1>
null).strategy(// <2>
routingStrategy).producerBuilder().build();
// end::producer-custom-routing-strategy[]
}
use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class EnvironmentUsage method deleteStream.
void deleteStream() {
Environment environment = Environment.builder().build();
// tag::stream-deletion[]
// <1>
environment.deleteStream("my-stream");
// end::stream-deletion[]
}
use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class EnvironmentUsage method environmentCreationWithTls.
void environmentCreationWithTls() throws Exception {
// tag::environment-creation-with-tls[]
X509Certificate certificate;
try (FileInputStream inputStream = new FileInputStream("/path/to/ca_certificate.pem")) {
CertificateFactory fact = CertificateFactory.getInstance("X.509");
// <1>
certificate = (X509Certificate) fact.generateCertificate(inputStream);
}
SslContext sslContext = SslContextBuilder.forClient().trustManager(// <2>
certificate).build();
Environment environment = Environment.builder().uri(// <3>
"rabbitmq-stream+tls://guest:guest@localhost:5551/%2f").tls().sslContext(// <4>
sslContext).environmentBuilder().build();
// end::environment-creation-with-tls[]
}
use of com.rabbitmq.stream.Environment in project rabbitmq-stream-java-client by rabbitmq.
the class EnvironmentUsage method addressResolver.
void addressResolver() throws Exception {
// tag::address-resolver[]
// <1>
Address entryPoint = new Address("my-load-balancer", 5552);
Environment environment = Environment.builder().host(// <2>
entryPoint.host()).port(// <2>
entryPoint.port()).addressResolver(// <3>
address -> entryPoint).build();
// end::address-resolver[]
}
Aggregations