Java Code Examples for org.eclipse.microprofile.reactive.messaging.Message#getMetadata()
The following examples show how to use
org.eclipse.microprofile.reactive.messaging.Message#getMetadata() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncomingCamelMetadataExample.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@Incoming("files") public CompletionStage<Void> consume(Message<GenericFile<File>> msg) { Optional<IncomingExchangeMetadata> metadata = msg.getMetadata(IncomingExchangeMetadata.class); if (metadata.isPresent()) { // Retrieve the camel exchange: Exchange exchange = metadata.get().getExchange(); } return msg.ack(); }
Example 2
Source File: MessageExamples.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
public void example1() { Message<String> message = Message.of("hello", Metadata.of(new MyMetadata())); // tag::message[] String payload = message.getPayload(); Optional<MyMetadata> metadata = message.getMetadata(MyMetadata.class); // end::message[] }
Example 3
Source File: OutgoingKafkaRecord.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <K, T> OutgoingKafkaRecord<K, T> from(Message<T> message) { OutgoingKafkaRecordMetadata<K> kafkaMetadata = message .getMetadata(OutgoingKafkaRecordMetadata.class) .orElse(new OutgoingKafkaRecordMetadata<>(null, null, -1, null, null)); return new OutgoingKafkaRecord<>(kafkaMetadata.getTopic(), kafkaMetadata.getKey(), message.getPayload(), kafkaMetadata.getTimestamp(), kafkaMetadata.getPartition(), kafkaMetadata.getHeaders(), message.getAck(), message.getNack(), message.getMetadata()); }
Example 4
Source File: KafkaPriceMessageConsumer.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes" }) @Incoming("prices") public CompletionStage<Void> consume(Message<Double> price) { // process your price. list.add(price.getPayload()); Optional<IncomingKafkaRecordMetadata> metadata = price.getMetadata(IncomingKafkaRecordMetadata.class); metadata.orElseThrow(() -> new IllegalArgumentException("Metadata are missing")); // Acknowledge the incoming message (commit the offset) return price.ack(); }
Example 5
Source File: MetadataWithMessageChainExamples.java From smallrye-reactive-messaging with Apache License 2.0 | 4 votes |
@Outgoing("sink") public CompletionStage<Void> consume(Message<Integer> in) { Optional<MyMetadata> metadata = in.getMetadata(MyMetadata.class); return in.ack(); }
Example 6
Source File: MetadataWithPayloadChainExamples.java From smallrye-reactive-messaging with Apache License 2.0 | 4 votes |
@Outgoing("sink") public CompletionStage<Void> consume(Message<Integer> in) { Optional<MyMetadata> metadata = in.getMetadata(MyMetadata.class); return in.ack(); }
Example 7
Source File: AmqpMessageConverter.java From smallrye-reactive-messaging with Apache License 2.0 | 4 votes |
static io.vertx.mutiny.amqp.AmqpMessage convertToAmqpMessage(Message<?> message, boolean durable, long ttl) { Object payload = message.getPayload(); Optional<OutgoingAmqpMetadata> metadata = message.getMetadata(OutgoingAmqpMetadata.class); AmqpMessageBuilder builder = io.vertx.mutiny.amqp.AmqpMessage.create(); if (durable) { builder.durable(true); } else { builder.durable(metadata.map(OutgoingAmqpMetadata::isDurable).orElse(false)); } if (ttl > 0) { builder.ttl(ttl); } else { long t = metadata.map(OutgoingAmqpMetadata::getTtl).orElse(-1L); if (t > 0) { builder.ttl(t); } } if (payload instanceof String) { builder.withBody((String) payload); } else if (payload instanceof Boolean) { builder.withBooleanAsBody((Boolean) payload); } else if (payload instanceof Buffer) { builder.withBufferAsBody((Buffer) payload); } else if (payload instanceof Byte) { builder.withByteAsBody((Byte) payload); } else if (payload instanceof Character) { builder.withCharAsBody((Character) payload); } else if (payload instanceof Double) { builder.withDoubleAsBody((Double) payload); } else if (payload instanceof Float) { builder.withFloatAsBody((Float) payload); } else if (payload instanceof Instant) { builder.withInstantAsBody((Instant) payload); } else if (payload instanceof Integer) { builder.withIntegerAsBody((Integer) payload); } else if (payload instanceof JsonArray) { builder.withJsonArrayAsBody((JsonArray) payload) .contentType(JSON_CONTENT_TYPE); } else if (payload instanceof JsonObject) { builder.withJsonObjectAsBody((JsonObject) payload) .contentType(JSON_CONTENT_TYPE); } else if (payload instanceof Long) { builder.withLongAsBody((Long) payload); } else if (payload instanceof Short) { builder.withShortAsBody((Short) payload); } else if (payload instanceof UUID) { builder.withUuidAsBody((UUID) payload); } else if (payload instanceof byte[]) { builder.withBufferAsBody(Buffer.buffer((byte[]) payload)); } else { builder.withBufferAsBody(new Buffer(Json.encodeToBuffer(payload))) .contentType(JSON_CONTENT_TYPE); } metadata.ifPresent(new Consumer<OutgoingAmqpMetadata>() { @Override public void accept(OutgoingAmqpMetadata meta) { if (meta.getAddress() != null) { builder.address(meta.getAddress()); } if (meta.getProperties() != null && !meta.getProperties().isEmpty()) { builder.applicationProperties(meta.getProperties()); } if (meta.getContentEncoding() != null) { builder.contentEncoding(meta.getContentEncoding()); } if (meta.getContentType() != null) { builder.contentType(meta.getContentType()); } if (meta.getCorrelationId() != null) { builder.correlationId(meta.getCorrelationId()); } if (meta.getId() != null) { builder.id(meta.getId()); } if (meta.getGroupId() != null) { builder.groupId(meta.getGroupId()); } if (meta.getPriority() >= 0) { builder.priority((short) meta.getPriority()); } if (meta.getSubject() != null) { builder.subject(meta.getSubject()); } } }); return builder.build(); }
Example 8
Source File: MetadataPropagationTest.java From smallrye-reactive-messaging with Apache License 2.0 | 4 votes |
@Incoming("output") public CompletionStage<Void> verify(Message<Integer> record) { received.add(record.getPayload()); metadata = record.getMetadata(); return CompletableFuture.completedFuture(null); }