---
schema_version: "1"
id: 865198d24e70a536f614d1a6ec5018e65285d627c187a465edf3d834cbb1cc47
title: Lightning Message Service Methods for Lightning Experience
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/service-cloud/api-cti/guides/sforce-api-cti-methods-lms.md
canonical_url: https://developer.salesforce.com/docs/service/api-cti/guide/sforce-api-cti-methods-lms.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5f0d6f4f629d0649cbc94bbabe275085d0e4d5ab51db797497935d90bf492012
products:
  - Open CTI Developer Guide
  - Service Cloud Developer Content
---

# Lightning Message Service Methods for Lightning Experience

## Usage

These three methods allow your CTI implementation to communicate with other Visualforce, Aura, and Lightning components that also use the Lightning Message Service. The `subscribe` method attaches a listener function to a specified Lightning Message Channel. The `publish` method lets you send a message on a Lightning Message Channel. The `unsubscribe` method lets you remove listener functions you added with the subscribe method.

These methods are available in API version 47.0 or later.

**note:** These methods can be used only with Lightning Experience. They can be used in iFrame and Visualforce components.

## Syntax

The `subscribe` method allows you to attach a listener function to a specified Lightning Message Channel. Lightning Message Service calls your listener function with the message that a component sends.

```javascript
var SAMPLEMC = "SAMPLEMC__c";
var SAMPLEMC_SUBSCRIPTION = null; 
sforce.opencti.subscribe({channelName: SAMPLEMC, listener: onPublishMessage, callback: subscribeSampleMCCallback}); 

```

## Arguments for `subscribe`

|Name|Type|Description|
|------|------|-------------|
|`channelName`|string|The name of the Message Channel that you can subscribe to.|
|`listener`|function|JavaScript method that’s called when a message is sent on the Message Channel.|
|`callback`|function|JavaScript method that’s executed when the API method call is completed.|


## Arguments for `unsubscribe`

|Name|Type|Description|
|------|------|-------------|
|`subscription`|object|The subscription from which you can remove the listener function.|
|`callback`|function|JavaScript method that’s executed when the API method call is completed.|


## Arguments for `publish`

|Name|Type|Description|
|------|------|-------------|
|`channelName`|string|The name of the Message Channel that you can subscribe to.|
|`message`|object|Serializable JSON object that is sent on the Message Channel.|
|`callback`|function|JavaScript method that’s executed when the API method call is completed.|


