Custom channels are useful when there are multiple subscribers and each subscriber
receives change events for a different set of objects.
Instead of subscribing to the default ChangeEvents channel,your app can create and subscribe to a custom channel
that receives only the events for the objects you're interested in.
you can create one or more custom channels to group change events on the channel
that your app subscribe to.
In addition to grouping change events, you can use a custom channel with event
enrichment to isolate sending enriched fields in change events on a specific channel.
How to create Custom Channel?
We can use tooling or Metadata Api to create a PlatfromEventChannel which represents a
custom channel.
Afterthat, we can create PlatformEventChannelMember to have multiple objects events associated to that channel.
we will provide the enriched fields in the JSON request body.
Custom channels allow you to group multiple events together, as well as work with filters and field enrichment.
Custom channels help you scale operations with event filtering and change event field enrichment.
ex :
1.create a custom channel
<INSTANCE_URL>/services/data/v57.0/tooling/sobjects/PlatformEventChannel
Use the following JSON for the request body.
{
"FullName": "Accounts_and_Contacts_CDC__chn",
"Metadata": {
"channelType": "data",
"label": "Custom Channel for Accounts and Contacts"
}
}
Note :
--> FullName is the API name of the custom channel. It must end with __chn.
--> channeType sets the type of members that the channel supports.
Its value is either data for Change Data Capture events or event for platform events.
2.Once you’ve declared a custom channel, you can add members to it by calling this endpoint
<INSTANCE_URL>/services/data/v57.0/tooling/sobjects/PlatformEventChannelMember
Use the following JSON for the request body.
{
"FullName": "Accounts_and_Contacts_CDC_chn_AccountChangeEvent",
"Metadata": {
"eventChannel": "Accounts_and_Contacts_CDC__chn",
"selectedEntity": "AccountChangeEvent"
}
}
Note :
--> FullName is the API name of the custom channel member. You are free to name it the way you want,
but a convention is to concatenate the channel API name with the selected entity name.
Note that this field does not allow double underscores, so you must modify the channel API name suffix to simply _chn instead of __chn.
--> eventChannel maps to the channel API name (the value of the FullName attribute of the previous request).
--> selectedEntity maps to a platform event or change event API name. In this example,
AccountChangeEvent is the standard change event for the Account object.