Method CreateSubscription
CreateSubscription(MessageReceivedCallback, DeliveryMode)
This method is used to register against topic on cache if topic exists, otherwise throw exception.
Declaration
ITopicSubscription CreateSubscription(MessageReceivedCallback messageReceivedCallback, DeliveryMode deliveryMode = DeliveryMode.Sync)
Parameters
Type | Name | Description |
---|---|---|
MessageReceivedCallback | messageReceivedCallback | Message is delivered through this callback |
DeliveryMode | deliveryMode | An optional parameter which specifies whether to deliver messages to register subscribers synchronously or asynchronously.Default value of this parameter is Sync |
Returns
Type | Description |
---|---|
ITopicSubscription | Returns the created topic subscription |
Examples
The following example demonstrates how to create a subscription on topic.
First initialize cache.
ICache cache = CacheManager.GetCache("myCache");
Then get messaging service from cache.
IMessagingService messagingService=cache.MessagingService;
Then get topic from messagingService
ITopic topic=messagingService.GetTopic("mytopic");
if(topic==null) //If topic not exists create it.
{
topic=messagingService.CreateTopic("mytopic");
}
Then create subscription
void MessageReceivedCallback(object sender, MessageEventArgs args)
{
}
topic.CreateSubscription(MessageReceivedCallback);