Unable to set custom message receiver in Jgroups configuration using axon JgroupsConnector

Hi Allard,

I am using axon with Distributed command bus which uses Jgroups for clustering and reliable messaging. I am fetching logs from Jgroups but i was only getting the message byte size in the logs where i wanted to get the actual message which is being sent from the channel so i found one solution for that which is to write own protocol and marshall/unmarshall the object to get the actual message string contents. This is the url of that mail chain,

Jgroups actual message content Logging

According to the documentation i have to set a Receiver while sending the message on to the channel ::
Jgroups writing custom protocol

So i set a custom receiver so that my class will be referred and the logging logic can be triggered using ::

JChannel channel;
channel.setReceiver(new ReceiverAdapter() {
public void receive(Message msg) {
LogMessage.ExampleHeader hdr = (LogMessage.ExampleHeader) msg.getHeader((short) 1900);
System.out.println("-- received " + msg + ", header is " + hdr);

and registering the class via ::

ClassConfigurator.add((short)1900, LogMessage.ExampleHeader.class);

where LogMessage is custom class extending protocol.

I am getting the following exception ::

java.lang.IllegalArgumentException: The given channel already has a receiver configured. Has the channel been reused with other Connectors?

I can see that axon is checking that any receiver is already registered or null in the JGroupsConnector class and then throwing an illegal argument exception ::

Assert.isTrue(channel.getReceiver() == null || channel.getReceiver() == messageReceiver,
"The given channel already has a receiver configured. "

  • “Has the channel been reused with other Connectors?”);

and this class has its own inner class as Reciever ::

private class MessageReceiver extends ReceiverAdapter

so it is throwing the exception as we have already set a receiver , Is there any way if we can set our own receiver so that custom logic can be triggered ?

Hi Anand,

in fact, there is a mechanism in place to prevent you from assigning your own message receiver before connecting the channel. This had to do with very weird error that you could get if a message receiver is assigned, but the JGroupsConnector doesn’t process all the incoming messages.
However, it should be possible to change the receiver after the connect() call. You will have to make sure that the exiting receive will always receive all calls. So the receiver you configure must delegate all invocations to the original one.
You can use channel.getReceiver() to receive the current one, and channel.setReceiver() to configure the new one.
It’s not a beautiful solution, but it may work around the problem you have.