Message Channel
lightning:messageChannel
This component allows you to subscribe and publish messages via the Lightning Message Service. lightning:messageChannel must be an immediate child of the aura:component tag of its parent.
For Aura components only. For LWC development, use lightning/messageService.
lightning:messageChannel provides access to the Lightning Message Service API. Lightning Message Service lets you publish and subscribe to messages across the DOM and between Aura, Visualforce, and Lightning Web Components. The lightning:messageChannel component works in Lightning Experience.
To use lightning:messageChannel, add it to your Aura component. The component has a required type attribute. The type is the name of the LightningMessageChannel that the lightning:messageChannel component references. To reference a custom instance of the LightningMessageChannel metadata type, use the __c suffix. Note that this is not a custom object, it just uses the same suffix. Here, we reference SampleMessage__c. Check out Create a Message Channel to learn more.
This example shows how to publish a message to the SampleMessageChannel__c channel when a button is clicked. To access the publish method from your component, assign an aura:id to lightning:messageChannel.
Pass in a payload in your client-side controller.
This example shows how to subscribe to a message channel by creating a handler method that runs when messages are published on the SampleMessageChannel__c message channel.
Subscriber components are responsible for updating the view in their onMessage handler each time they receive a new message. Components that call $A.enqueueAction in their onMessage handler must wrap it with $A.getCallback if the callback on the enqueued action is meant to trigger a re-render.