use of org.eclipse.microprofile.reactive.messaging.Metadata in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class KafkaTopicInvokerTest method onEvent.
@Test
public void onEvent() {
ArgumentCaptor<Message<String>> captor = ArgumentCaptor.forClass(Message.class);
Emitter<String> emitter = mock(Emitter.class);
String event = "{\"key\": \"value\"}";
String topic = "myTestTopic";
ProcessorDTO processor = createProcessor();
KafkaTopicInvoker invoker = new KafkaTopicInvoker(emitter, processor, topic);
invoker.onEvent(event);
verify(emitter).send(captor.capture());
Message<String> sent = captor.getValue();
assertThat(sent.getPayload()).isEqualTo(event);
Metadata metadata = sent.getMetadata();
OutgoingKafkaRecordMetadata recordMetadata = metadata.get(OutgoingKafkaRecordMetadata.class).get();
assertThat(recordMetadata.getTopic()).isEqualTo(topic);
}
use of org.eclipse.microprofile.reactive.messaging.Metadata in project smallrye-reactive-messaging by smallrye.
the class ContextAwareMessage method of.
static <T> ContextAwareMessage<T> of(T payload) {
LocalContextMetadata contextMetadata = captureLocalContextMetadata();
Metadata metadata = contextMetadata == null ? Metadata.empty() : Metadata.of(contextMetadata);
return new ContextAwareMessage<T>() {
@Override
public T getPayload() {
return payload;
}
@Override
public Metadata getMetadata() {
return metadata;
}
};
}
use of org.eclipse.microprofile.reactive.messaging.Metadata in project smallrye-reactive-messaging by smallrye.
the class MetadataTest method testOf.
@Test
public void testOf() {
Metadata h1 = Metadata.of();
assertThat(h1).isEmpty();
MessageTest.MyMetadata<Integer> m = new MessageTest.MyMetadata<>(12);
Metadata h2 = Metadata.of(m);
assertThat(h2).hasSize(1).containsExactly(m);
AtomicBoolean m2 = new AtomicBoolean(true);
Metadata h3 = Metadata.of(m, m2);
assertThat(h3).hasSize(2).containsExactlyInAnyOrder(m, m2);
MessageTest.MyMetadata<Double> m3 = new MessageTest.MyMetadata<>(23.3);
assertThatThrownBy(() -> Metadata.of(m, m2, m3)).isInstanceOf(IllegalArgumentException.class);
Metadata h4 = Metadata.of(m).with(m2).with(m3);
assertThat(h4).hasSize(2).containsExactlyInAnyOrder(m2, m3);
}
use of org.eclipse.microprofile.reactive.messaging.Metadata in project smallrye-reactive-messaging by smallrye.
the class MetadataTest method testFrom.
@Test
public void testFrom() {
int v = 1;
String s = "hello";
Metadata metadata = Metadata.empty().with(v);
Metadata copy = Metadata.from(metadata).with(s).with(2);
assertThat(copy).hasSize(2).containsExactlyInAnyOrder(s, 2);
assertThat(metadata).hasSize(1).containsExactlyInAnyOrder(1);
}
use of org.eclipse.microprofile.reactive.messaging.Metadata in project smallrye-reactive-messaging by smallrye.
the class MetadataTest method testGetObject.
@Test
public void testGetObject() {
Person person = new Person();
person.name = "mark";
byte[] bytes = new byte[] { 1, 2, 3, 4 };
Metadata metadata = Metadata.of(person, bytes);
Message<String> message = Message.of("ignored", metadata);
Person p = message.getMetadata(Person.class).orElseThrow(() -> new AssertionError("Metadata expected"));
assertThat(p).isNotNull();
assertThat(p.name).isEqualTo("mark");
byte[] b = message.getMetadata(byte[].class).orElseThrow(() -> new AssertionError("Metadata expected"));
assertThat(b).isNotNull().hasSize(4).containsExactly(1, 2, 3, 4);
}
Aggregations