TopicListener

TopicListener

# new TopicListener(onTopicDeleted, onMessageDeliveryFailure)

In case a topic is deleted, it is a forceful deletion and deletes all messages and related meta-info form the cache. Hence, the subscriber and publisher must be notified of this deletion through TopicDeleteCallback method for notifying application about topic deletion.

Parameters:
Name Type Default Description
onTopicDeleted function

callback method for topic delete event

onMessageDeliveryFailure function null

callback method for message delivery failure event

Example
const ncache  = require('ncache-client');

function onTopicDeleted(sender, args) {
 //...
}

function onMessageDeliveryFailure(sender, args) {
   //..
}

//Initialize the Cache Cluster 
let cache = await ncache.CacheManager.getCache("demoCache");

//Get messaging service from cache.
let messagingService = await cache.getMessagingService();

//Create topic from messaging service .
let createdTopic = await messagingService.createTopic("mytopic");

//Register for topic deletion events or message delivery failure.
let topicListener = new ncache.TopicListener(onTopicDeleted, onMessageDeliveryFailure);
await createdTopic.addTopicDeletedListener(topicListener);
await createdTopic.addMessageDeliveryFailureListener(topicListener);