use of com.rabbitmq.stream.Message in project rabbitmq-stream-java-client by rabbitmq.
the class ProducerUsage method producerWithName.
void producerWithName() {
Environment environment = Environment.builder().build();
// tag::producer-with-name[]
Producer producer = environment.producerBuilder().name(// <1>
"my-app-producer").confirmTimeout(// <2>
Duration.ZERO).stream("my-stream").build();
// end::producer-with-name[]
// tag::message-with-publishing-id[]
Message message = producer.messageBuilder().publishingId(// <1>
1).addData("hello".getBytes(StandardCharsets.UTF_8)).build();
producer.send(message, confirmationStatus -> {
});
// end::message-with-publishing-id[]
}
use of com.rabbitmq.stream.Message in project rabbitmq-stream-java-client by rabbitmq.
the class SuperStreamUsage method producerCustomHashFunction.
void producerCustomHashFunction() {
Environment environment = Environment.builder().build();
// tag::producer-custom-hash-function[]
Producer producer = environment.producerBuilder().stream("invoices").routing(message -> message.getProperties().getMessageIdAsString()).hash(// <1>
rk -> rk.hashCode()).producerBuilder().build();
// end::producer-custom-hash-function[]
}
use of com.rabbitmq.stream.Message in project rabbitmq-stream-java-client by rabbitmq.
the class Client method publish.
public List<Long> publish(byte publisherId, List<Message> messages, OutboundEntityMappingCallback mappingCallback, ToLongFunction<Object> publishSequenceFunction) {
List<Object> encodedMessages = new ArrayList<>(messages.size());
for (Message message : messages) {
Codec.EncodedMessage encodedMessage = codec.encode(message);
checkMessageFitsInFrame(encodedMessage);
OriginalAndEncodedOutboundEntity wrapper = new OriginalAndEncodedOutboundEntity(message, encodedMessage);
encodedMessages.add(wrapper);
}
return publishInternal(this.channel, publisherId, encodedMessages, new OriginalEncodedEntityOutboundEntityWriteCallback(mappingCallback, OUTBOUND_MESSAGE_WRITE_CALLBACK), publishSequenceFunction);
}
use of com.rabbitmq.stream.Message in project rabbitmq-stream-java-client by rabbitmq.
the class Client method publishBatches.
public List<Long> publishBatches(byte publisherId, List<MessageBatch> messageBatches, ToLongFunction<Object> publishSequenceFunction) {
List<Object> encodedMessageBatches = new ArrayList<>(messageBatches.size());
for (MessageBatch batch : messageBatches) {
EncodedMessageBatch encodedMessageBatch = createEncodedMessageBatch(batch.compression, batch.messages.size());
for (Message message : batch.messages) {
Codec.EncodedMessage encodedMessage = codec.encode(message);
checkMessageFitsInFrame(encodedMessage);
encodedMessageBatch.add(encodedMessage);
}
encodedMessageBatch.close();
checkMessageBatchFitsInFrame(encodedMessageBatch);
encodedMessageBatches.add(encodedMessageBatch);
}
return publishInternal(this.channel, publisherId, encodedMessageBatches, OUTBOUND_MESSAGE_BATCH_WRITE_CALLBACK, publishSequenceFunction);
}
use of com.rabbitmq.stream.Message 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[]
}
Aggregations