Search in sources :

Example 1 with PersonCodec

use of io.smallrye.reactive.messaging.eventbus.codec.PersonCodec in project smallrye-reactive-messaging by smallrye.

the class EventBusSinkTest method testCodec.

@Test
@SuppressWarnings("unchecked")
public void testCodec() {
    String topic = UUID.randomUUID().toString();
    List<Person> persons = new ArrayList<>();
    vertx.eventBus().<Person>consumer(topic, m -> persons.add(m.body()));
    vertx.eventBus().getDelegate().registerCodec(new PersonCodec());
    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    config.put("codec", "PersonCodec");
    EventBusSink sink = new EventBusSink(vertx, new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));
    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10).map(i -> new Person().setName("name").setAge(i)).map(Message::of).subscribe((Subscriber<Message<?>>) subscriber.build());
    await().until(() -> persons.size() == 10);
    assertThat(persons.size()).isEqualTo(10);
}
Also used : Message(org.eclipse.microprofile.reactive.messaging.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) Person(io.smallrye.reactive.messaging.eventbus.codec.Person) PersonCodec(io.smallrye.reactive.messaging.eventbus.codec.PersonCodec) Test(org.junit.jupiter.api.Test)

Aggregations

Person (io.smallrye.reactive.messaging.eventbus.codec.Person)1 PersonCodec (io.smallrye.reactive.messaging.eventbus.codec.PersonCodec)1 MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Message (org.eclipse.microprofile.reactive.messaging.Message)1 Test (org.junit.jupiter.api.Test)1