Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertx IllegalArgumentException: No message codec for type - how to create a consumer for a custom type

I have a verticle that creates an event bus consumer as follows:

    public void start() {
        vertx.eventBus().consumer(ADDRESS_REQUEST, this::handleRequestMessage);

    }

    private void handleRequestMessage(Message<VWApiConversation> msg) {

       VWApiConversation conversation = msg.body();

    }

But when sending a message to this address :

 vertx.eventBus().send(VehicleStateCoordinatorVerticle.ADDRESS_REQUEST, conversation, deliveryOptions, res -> {

...

I get the error :

java.lang.IllegalArgumentException: No message codec for type: class com.vulog.vwgateway.model.VWApiConversation

Am I missing something?

like image 360
Orkun Ozen Avatar asked Oct 09 '18 08:10

Orkun Ozen


1 Answers

Vert.x supports serializing JVM primitives, Buffers, and JsonObjects by default. for other custom types you'll need to write your own MessageCodec.

here's some documentation that might be of help:

  • the official docs has a few notes about this. the section titled "Types of messages" will be of particular interest to you.
  • here is a sample MessageCodec implementation. (not shown in this snippet is registration of the codec via EventBus.registerCodec().)

for my taste i've always used JsonObject as the messaging medium (as my setups have enabled me to). seems like a hassle to write custom (de)serializers for every domain type.

like image 72
homerman Avatar answered Oct 20 '22 11:10

homerman