Skip to content

Routing in the cluster

When a command is received by your code in Aeron Cluster, all it receives is:

1
2
3
4
5
6
public void onSessionMessage(ClientSession session, long timestamp,
                                DirectBuffer buffer, int offset, int length,
                                Header header)
{
    //do something
}

Inbound messages will need to demuxed from the data on the buffer. Exactly how this is done is dependent on how you've implemented the commands. In this example, we're using Eider, and Eider holds two identifiers to help. First, it holds the Eider group, which allows us to group messages into a single demuxer where it makes sense. Then, Eider stores the message type, which is used for the demuxing of the buffer data.

Master Demuxer

In the sample, the MasterDemuxer reads the Eider Group from the buffer, and then selects the correct final demuxer:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
@Override
public void onFragment(DirectBuffer buffer, int offset, int length,
                        Header head)
{
    short eiderGroupId = getEiderGroupId(buffer, offset);
    switch (eiderGroupId)
    {
        case RFQS:
            rfqDemuxer.onFragment(buffer, offset, length, header);
            break;
        case INSTRUMENTS:
            instrumentDemuxer.onFragment(buffer, offset, length, header);
            break;
        ...
        default:
            log.warn("unknown group");
    }
}
Back to top