Search in sources :

Example 1 with Metadata

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);
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) OutgoingKafkaRecordMetadata(io.smallrye.reactive.messaging.kafka.api.OutgoingKafkaRecordMetadata) Metadata(org.eclipse.microprofile.reactive.messaging.Metadata) OutgoingKafkaRecordMetadata(io.smallrye.reactive.messaging.kafka.api.OutgoingKafkaRecordMetadata) Test(org.junit.jupiter.api.Test)

Example 2 with Metadata

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;
        }
    };
}
Also used : Metadata(org.eclipse.microprofile.reactive.messaging.Metadata)

Example 3 with 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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Metadata(org.eclipse.microprofile.reactive.messaging.Metadata) Test(org.junit.jupiter.api.Test)

Example 4 with Metadata

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);
}
Also used : Metadata(org.eclipse.microprofile.reactive.messaging.Metadata) Test(org.junit.jupiter.api.Test)

Example 5 with Metadata

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);
}
Also used : Metadata(org.eclipse.microprofile.reactive.messaging.Metadata) Test(org.junit.jupiter.api.Test)

Aggregations

Metadata (org.eclipse.microprofile.reactive.messaging.Metadata)9 Test (org.junit.jupiter.api.Test)8 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)1 OutgoingKafkaRecordMetadata (io.smallrye.reactive.messaging.kafka.api.OutgoingKafkaRecordMetadata)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Message (org.eclipse.microprofile.reactive.messaging.Message)1