Creating Pub/Sub messages
NCache provides the Message
class which implements the IMessage
interface to
create a message.
In order to utilize messaging APIs, include the following namespaces in your application:
Alachisoft.NCache.Web.Caching
Alachisoft.NCache.Runtime.Caching
Members | Description |
---|---|
MessageId |
Auto generated ID for the message, as same messages can be stored on different topics. |
ExpirationTime |
ExpirationTime of TimeSpan type after which the message is expired from the topic. This can also accept null value, which will ensure that the message is not expired from the topic. In case of no expiration time specified, null is considered as default. |
Payload |
The actual data object of interest for subscribers, for example, Order . |
NoExpiration |
Specifies TimeSpan.MaxValue for the message, so that it is not expired. |
CreationTime |
Creation time in DateTime for the message. |
//Payload containing OrderId to be sent in message
Order payload = new Order();
payload.OrderID = 10248;
payload.OrderDate = new DateTime(2015,07,04);
payload.ShipName = "Vins et alcools Chevalier";
payload.ShipAddress = "59 rue de l'Abbaye";
payload.ShipCity = "Reims";
payload.ShipCountry = "France";
//Create message with payload and expiration time set to 150 seconds
Message message = new Message(payload);
message.ExpirationTime = new TimeSpan(0, 0, 150);