Method PublishBulk
PublishBulk(IEnumerable<Tuple<Message, DeliveryOption>>, Boolean)
This method is used to Publish messages in bulk in the cache with specified DeliveryOption. And the option to notify the publisher if the message has failed to deliver because of expiration, eviction or internal system issue.
Declaration
IDictionary<Message, Exception> PublishBulk(IEnumerable<Tuple<Message, DeliveryOption>> messages, bool notifyDeliveryFailure = false)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Tuple<Message, DeliveryOption>> | messages | Tuple of Message and DeliveryOption |
System.Boolean | notifyDeliveryFailure | Set this to true to notify if message is not delivered to any subscriber |
Returns
Type | Description |
---|---|
IDictionary<Message, Exception> |
Examples
The following example demonstrates how to publish message on a topic. First initialize cache.
ICache cache = CacheManager.GetCache("demoClusteredCache");
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 multiple Message and DeliveryOption Tuples and store in a Collection.
List<Tuple<Message, DeliveryOption>> messagesList = new List<Tuple<Message, DeliveryOption>>();
for(int i = 0; i < 10; i++) {
object payload = "mymessage" + i;
Message message = new Message(payload); //creating message
messagesList.Add(new Tuple<Message,DeliveryOption>(message,DeliveryOption.Any));
}
Now, Send the list for publishing and set the notifyDeliveryFailure according to your requirement.
topic.PublishBulk(messagesList, false); // here, no notifications for delivery failures will be received.