服务层 - Orch
Finally, to facilitate the use of the individual services, SONiC has further encapsulated the communication layer by providing a base class for each service: [Orch](https://github.com/sonic-net/sonic-swss/blob/master/src/orchagent/orch. hcommon/consumertatetable.h).
Thanks to these above encapsulations, the encapsulation of message communication in Orch is relatively simple, and the main class diagram is as follows:
As you can see, Orch mainly encapsulates SubscriberStateTable
and ConsumerStateTable
to simplify and unify the subscription of messages. The core code is very simple, which is to create different Consumers according to different database types, as follows:
void Orch::addConsumer(DBConnector *db, string tableName, int pri)
{
if (db->getDbId() == CONFIG_DB || db->getDbId() == STATE_DB || db->getDbId() == CHASSIS_APP_DB) {
addExecutor(
new Consumer(
new SubscriberStateTable(db, tableName, TableConsumable::DEFAULT_POP_BATCH_SIZE, pri),
this,
tableName));
} else {
addExecutor(
new Consumer(
new ConsumerStateTable(db, tableName, gBatchSize, pri),
this,
tableName));
}
}