static void registerMessageCodecs( final Vertx vertx, final JsonObject config, final boolean abortOnFailure) throws CodecRegistrationException { final JsonArray messageCodecs = config.getJsonArray(MESSAGE_CODECS_FIELD); if (messageCodecs != null) { for (final Object messageCodecClassNameObject : messageCodecs.getList()) { if (messageCodecClassNameObject instanceof String) { final String messageCodecClassName = (String) messageCodecClassNameObject; try { final MessageCodec<?, ?> messageCodec = (MessageCodec<?, ?>) Class.forName(messageCodecClassName).newInstance(); vertx.eventBus().registerCodec(messageCodec); } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) { log.warn("registerMessageCodecs", "start", new String[]{"message", "messageCodecClassName"}, "Failed to instantiate message codec", messageCodecClassName, e); if (abortOnFailure) { throw new CodecRegistrationException( String.format( "Failed to instantiate message codec %s", messageCodecClassName), e); } } } else { log.warn("registerMessageCodecs", "start", new String[]{"message", "messageCodecClassName"}, "Ignoring non-string message codec class name", messageCodecClassNameObject); if (abortOnFailure) { throw new CodecRegistrationException("Ignoring non-string message codec class name"); } } } } }
private <T> void registerDefaultCodec(Class<T> clazz, MessageCodec<T, ?> codec) { try { vertx.eventBus().registerDefaultCodec(clazz, codec); } catch (IllegalStateException iae) { // Codec is already registered. } }
private void registerMessageCodec(final ProtobufMessageCodec<A> codec) { try { eventBus.registerDefaultCodec(codec.getDefaultInstance().getClass(), (MessageCodec) codec); } catch (final IllegalStateException e) { log.logp(FINE, "ProtobufMessageProducer", "registerMessageCodec", "failed to register codec for request message", e.getCause()); } }
public void registerCodec(Vertx vertx, MessageCodec<Person, Person> codec) { vertx.eventBus().registerDefaultCodec(Person.class, codec); }
public void example10(EventBus eventBus, MessageCodec myCodec) { eventBus.registerCodec(myCodec); DeliveryOptions options = new DeliveryOptions().setCodecName(myCodec.name()); eventBus.send("orders", new MyPOJO(), options); }
public void example11(EventBus eventBus, MessageCodec myCodec) { eventBus.registerDefaultCodec(MyPOJO.class, myCodec); eventBus.send("orders", new MyPOJO()); }