subscribe(filter, messageHandler, id, contextName)
Subscribes to the messaging service and forwards messages to subscribers based on a specified filter criteria.
Returns
The user-assigned or auto-generated subscription ID as a string.
Parameters
Name | Type | Description | Required |
filter | object | The object containing the filter criteria. | ✅ |
messageHandler | function | The callback function that needs to be invoked. | ✅ |
id | string | The user-assigned or auto-generated unique identifier of the subscriber to whom the messages can be forwarded. | ❌ |
contextName | string | The name of the context where the API is being called. | ❌ |
Usage example
In this example, the API subscribes to the messaging service and forwards the messages to subscribers based on the specified filter criteria.
Example usage - PCore.getMessagingServiceManager().subscribe({matcher: "interaction"}, message => {
// Perform message execution here
}));
Previous topic APIs in the MessagingServiceManager class Next topic unsubscribe(id)