Interface ITopic
Contains properties and methods required for a topic. It is implemented by Topic.
Namespace:
Assembly: Alachisoft.NCache.Runtime.dll
Syntax
public interface ITopic : IDisposable
Properties
ExpirationTime
Default Expiry time of messsage for this topic. Its default value is TimeSpan.MaxValue.
Declaration
TimeSpan ExpirationTime { get; set; }
Property Value
Type | Description |
---|---|
TimeSpan |
IsClosed
Is topic closed or not?
Declaration
bool IsClosed { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Name
Topic's name
Declaration
string Name { get; }
Property Value
Type | Description |
---|---|
System.String |
OnTopicDeleted
Topic deletion events are delivered through this callback.
Declaration
TopicDeletedCallback OnTopicDeleted { set; }
Property Value
Type | Description |
---|---|
TopicDeletedCallback |
Remarks
You can use this event to perform the tasks when a topic is deleted. For more information on how to use this callback see the documentation for TopicDeletedCallback.
Methods
CreateSubscription(MessageReceivedCallback)
Subscribes for receiving messages of a particular topic.
Declaration
ITopicSubscription CreateSubscription(MessageReceivedCallback messageReceivedCallback)
Parameters
Type | Name | Description |
---|---|---|
MessageReceivedCallback | messageReceivedCallback | Message is delivered through this callback |
Returns
Type | Description |
---|---|
ITopicSubscription | Returns the created topic subscription |
Examples
The following example demonstrates how to create a subscription on topic.
First initialize cache.
Cache cache = NCache.InitializeCache("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);
Publish(Message, DeliveryOption, Boolean)
Method used to publish message on topic
Declaration
void Publish(Message message, DeliveryOption deliverOption, bool notifyDeliveryFailure = false)
Parameters
Type | Name | Description |
---|---|---|
Message | message | Message to be published |
DeliveryOption | deliverOption | Delivery Option |
System.Boolean | notifyDeliveryFailure | Is MessageDeliveryFailure event required for this message |
Examples
The following example demonstrates how to publish message on a topic.
First initialize cache.
Cache cache = NCache.InitializeCache("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 publish message on topic.
object payload = "mymessage";
Message message = new Message(payload); //creating message
topic.Publish(message, DeliveryOption.All);
Events
MessageDeliveryFailure
Subscribe for Message delivery failure events
Declaration
event MessageDeliveryFailureCallback MessageDeliveryFailure
Event Type
Type | Description |
---|---|
MessageDeliveryFailureCallback |
Remarks
You can use this event to perform the tasks when message delivery fails. For more information on how to use this callback see the documentation for MessageDeliveryFailureCallback.