vendredi 2 avril 2021

Using method reader and writter in Chronicle Queue

Hi guys iIam facing a difficulty on a personal project that I use Chronicle Queue for Journalling. I have two types of message to read and write from the queue itself. My problem is that I am using the strategy of using method reader and writter to do it, but I need to had two different names for the methods to do the operations with the Chronicle Queue. When I try to read using a method reader passing two implementations of the interfaces with methods with same name, only the first one is looked up from Chronicle Abstraction. I want a way to maintain only one method name to read and write different messages from Chronicle Queue

Bellow I will share this problem to be more clear:

interface Message1Listener{
    void message(Message1 message);
}

interface Message2Listener{
    void message(Message2 message);
}

public class Messag1 extends SelfDescribingMarshallable{
    ByteBuffer text;
    
    public Message1(ByteBuffer text){
        this.text = text;
    }
}

public class Messag2 extends SelfDescribingMarshallable{
    ByteBuffer email;
    int uniqueKey;

    public Message1(ByteBuffer email, int uniqueKey){
        this.email = email;
        this.uniqueKey = uniqueKey;
    }
}

public Message1Processor implements Message1Listener{
    public void message(Message1 message){
        //do something with message
    }
}

public Message2Processor implements Message2Listener{
    public void message(Message2 message){
        //do something with message
    }
}

//write the messages
Message1Listener writer1 = queue.acquireAppender().methodWriter(Message1Listener.class);
Message2Listener writer2 = queue.acquireAppender().methodWriter(Message2Listener.class);

//read the messages
MethodReader reader = queue.createTailer().methodReader(new Message1Processor(), new Message2Processor());

Aucun commentaire:

Enregistrer un commentaire