io.vertx.core.eventbus.MessageCodec Java Examples

The following examples show how to use io.vertx.core.eventbus.MessageCodec. 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: VertxRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void registerCodecs(Map<Class<?>, Class<?>> codecByClass) {
    EventBus eventBus = vertx.eventBus();
    for (Map.Entry<Class<?>, Class<?>> codecEntry : codecByClass.entrySet()) {
        Class<?> target = codecEntry.getKey();
        Class<?> codec = codecEntry.getValue();
        try {
            if (MessageCodec.class.isAssignableFrom(codec)) {
                MessageCodec messageCodec = (MessageCodec) codec.newInstance();
                eventBus.registerDefaultCodec(target, messageCodec);
            } else {
                LOGGER.error(String.format("The codec %s does not inherit from MessageCodec ", target.toString()));
            }
        } catch (InstantiationException | IllegalAccessException e) {
            LOGGER.error("Cannot instantiate the MessageCodec " + target.toString(), e);
        }
    }
}
 
Example #2
Source File: Examples.java    From vertx-camel-bridge with Apache License 2.0 3 votes vote down vote up
public void registerCodec(Vertx vertx, MessageCodec<Person, Person> codec) {
  vertx.eventBus().registerDefaultCodec(Person.class, codec);
}