---
schema_version: "1"
id: 4b8d568f92ef43df943ea366197d8de41171e124200c45adb32140e77c3e0cf2
title: Subscribe to a Message Channel
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/message-channel/message-channel-subscribe.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/message-channel-subscribe.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 63c37531c623b29a929aac72b6c76256c4e1a7c456e6f97cffde34d05a63cdad
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Subscribe to a Message Channel

To subscribe to a message channel, create a handler method to run when it receives a message.


In this example, the `lmsSubscriberAuraComponent` from the [github.com/trailheadapps/lwc-recipes](https://github.com/trailheadapps/lwc-recipes) repo shows how to subscribe and unsubscribe from a message channel.

In this example, we define an Aura component called `myNewComponent` that contains the custom message channel, `SampleMessageChannel__c`. The `lightning:messageChannel` component's `onMessage` attribute calls the `handleChanged` method in the client-side controller.

By default, communication over a message channel can occur only between components in an active navigation tab, an active navigation item, or a utility item. Utility items are always active. A navigation tab or item is active when it’s selected. Navigation tabs and items include:

-   Standard navigation tabs
-   Console navigation workspace tabs
-   Console navigations subtabs
-   Console navigation items

To receive messages on a message channel from anywhere in the application, use `lightning:messageChannel`'s optional parameter, `scope`. Set `scope` to the value `"APPLICATION"`.

```nolang
<lightning:messageChannel type="messageChannel" onMessage="{!listener}" scope="APPLICATION"/>
```

The component `myNewComponent` detects a new message and updates the display value.

```nolang
<!-- myNewComponent.cmp -->
<aura:component>
    <aura:attribute name="recordValue" type="String"/>
    <lightning:formattedText value="{!v.recordValue}" />
    <lightning:messageChannel type="SampleMessageChannel__c"
         onMessage="{!c.handleChanged}"/>
</aura:component>

```

```javascript
// myNewComponentController.js
({
    handleChanged: function(cmp, message, helper) { 
     // Read the message argument to get the values in the message payload
    if (message != null && message.getParam("recordData") != null) {
        cmp.set("v.recordValue", message.getParam("recordData").value);
    }
  }
})

```

Write the handler in your component's client-side controller. The `handleChanged` method fires when there is a new message. It checks whether there is a payload in the message, and if so, assigns the new data to the `v.recordValue` attribute. The `lightning:formattedText` element updates to display the new value.

