Document 224672

// Create a sessionful queue
var queueDescription = new QueueDescription("myqueue") {RequiresSession = true};
namespaceManager.CreateQueue(queueDescription);
// Create a MessageSession object to receive messages from a sessionful queue
var queueClient = messagingFactory.CreateQueueClient(queueDescription.Path, ReceiveMode.PeekLock);
messageSession = queueClient.AcceptMessageSession(TimeSpan.FromSeconds(30));
When duplicate detection is enabled on a queue or topic, the duplicate messages (same
MessageId) received in a timeframe < Duplicate Detection History Time Window are discarded.
// Create a queue that requires duplicate detection
var queueDescription = new QueueDescription("myqueue") { RequiresDuplicateDetection = true,
DuplicateDetectionHistoryTimeWindow = TimeSpan.FromHours(24) };
namespaceManager.CreateQueue(queueDescription);
// Create a queue that forwards messages to another queue
var queueDescription = new QueueDescription("sourcequeue") { ForwardTo = “destinationqueue" };
namespaceManager.CreateQueue(queueDescription);
// Disable a queue
queueDescription.Status = EntityStatus.Disabled;
// Update a queue
queueDescription = namespaceManager.UpdateQueue(queueDescription);
// Use the UserMetadata
queueDescription.UserMetadata = "This queue is used to receiver new orders.";
var messageList = new List<BrokeredMessage>();
for (var i = 0; i < 30; i++)
{
messageList.Add(new BrokeredMessage("Hello Word") {Label = “SendBatch", MessageId = i.ToString()});
}
var messageSender = messagingFactory.CreateMessageSender("myqueue");
messageSender.SendBatch(messageList);
var messageReceiver = messagingFactory.CreateMessageReceiver("myqueue");
var messageEnumerable = messageReceiver.ReceiveBatch(batchSize, TimeSpan.FromSeconds(timeout));
// Move a message to the deadletter queue
var messageReceiver = messagingFactory.CreateMessageReceiver("myqueue", ReceiveMode.PeekLock);
...
var brokeredMessage = messageReceiver.Receive();
brokeredMessage.Deadletter();
// Read messages from the deadletter queue of a queue
messageReceiver =
messagingFactory.CreateMessageReceiver(QueueClient.FormatDeadLetterPath(queueDescription.Path),
ReceiveMode.PeekLock);
var brokeredMessage messageReceiver.Receive();
// Defer a message
var messageReceiver = messagingFactory.CreateMessageReceiver("myqueue", ReceiveMode.PeekLock);
...
var brokeredMessage = messageReceiver.Receive();
brokeredMessage.Defer();
messageDeferProvider.Enqueue(inboundMessage.SequenceNumber);
// Read deferred messages
long sequenceNumber;
if (messageDeferProvider.Dequeue(out sequenceNumber))
{
var brokeredMessage = messageReceiver.Receive(sequenceNumber);
}
var messageSender = messagingFactory.CreateMessageSender("myqueue");
var messageList = new List<BrokeredMessage>();
using (var scope = new TransactionScope())
{
foreach (var message in messageList)
{
messageSender.Send(message);
}
scope.Complete();
}
var messageReceiver = messagingFactory.CreateMessageReceiver("myqueue", ReceiveMode.PeekLock);
using (var scope = new TransactionScope())
{
var message = messageReceiver.Receive();
message.Complete();
scope.Complete();
}
var topicDescription = new TopicDescription("mytopic");
topicDescription.EnableFilteringMessagesBeforePublishing = true;
public sealed class MessageCountDetails
{
public long ActiveMessageCount { get; set; }
public long DeadletterMessageCount { get; set; }
public long ScheduledMessageCount { get; set; }
public long TransferMessageCount { get; set; }
public long TransferDeadLetterMessageCount { get; set; }
}
// This interface defines a sessionless service contract.
[ServiceContract]
public interface IOrderService
{
[OperationContract(IsOneWay = true)]
[ReceiveContextEnabled(ManualControl = true)]
void ReceiveOrder(Order order);
}
// ServiceBus supports both IInputChannel and IInputSessionChannel.
// A sessionful service listening to a sessionful queue must have
// SessionMode.Required in its contract.
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IOrderServiceSessionful : IOrderService
{
}
static void Main(string[] args)
{
...
var channelFactory = new ChannelFactory<IOrderService>("orderEndpoint");
var clientChannel = channelFactory.CreateChannel();
var order = new Order() {ItemId = "001", Quantity = 10};
using (var scope = new OperationContextScope((IContextChannel)clientChannel))
{
// Use the BrokeredMessageProperty object to set the BrokeredMessage properties
var property = new BrokeredMessageProperty(){
Label = "OrderItem",
MessageId = Guid.NewGuid().ToString(),
ReplyTo = "sb://acme.servicebus.windows.net/invoicequeue"};
// Use the BrokeredMessageProperty object to define application-specific properties
property.Properties.Add("ShipCountry", "Italy");
property.Properties.Add("ShipCity", "Milan");
// Add BrokeredMessageProperty to the OutgoingMessageProperties bag provided
// by the current Operation Context
OperationContext.Current.OutgoingMessageProperties.Add(BrokeredMessageProperty.Name,
property);
clientChannel.SendOrder(order);
}
...
}
[ServiceBehavior]
public class OrderService : IOrderService
{
[OperationBehavior]
public void ReceiveOrder(Order order)
{
// Get the BrokeredMessageProperty from the current OperationContext
var incomingProperties = OperationContext.Current.IncomingMessageProperties;
var property = incomingProperties[BrokeredMessageProperty.Name] as BrokeredMessageProperty;
...
// Commit the receive operation
ReceiveContext receiveContext;
if (ReceiveContext.TryGet(incomingProperties, out receiveContext))
{
receiveContext.Complete(TimeSpan.FromSeconds(10.0d));
}
else
{
receiveContext.Abort(TimeSpan.FromSeconds(10.0d));
throw new InvalidOperationException(“...");
}
}
}
• Push notifications require a platform specific service
• Each platform (Windows, iOS, Android, …) has a different push notification service
• Different capabilities and protocols
• An e2e solution requires lots of back-end code
• Store and keep up to date the device information
• Implement platform-specific protocols
Registration at app launch
Client app
Platform
Notification
Service
Sending Notification
Maintenance
App back-end
Platform dependency
•
•
Different communication protocols to PNS’ (e.g. HTTP vs TCP, xml payload vs json payload)
Different presentation formats and capabilities (tiles vs toasts vs badges)
Routing
•
•
•
PNS’ provide a way to send a message to a device/channel
Usually notifications are targeted at users or interest groups (e.g. employees assigned to a customer account)
App back-end has to maintain a registry associating device handles to interest groups/users
Scale
•
•
App back-end has to store current handles for each device  high storage and VM costs
Broadcast to millions of devices with low latency requires parallelization (DB ad VM)
One-time set up
iOS app
Register
Send Notification
Windows Store
app
App back-end
APNs
Notification Hub
WNS
No platform-specific protocols
App back-end just communicates with the Notification Hub.
Avoid storing device information in the app back-end
Notification Hub maintains the registry of devices and the associations to
users/interest groups
Broadcast
Push notifications to millions of devices (across platforms) with a single call
var hub = new NotificationHub(“<hub name>", "<connection string>");
var channel = await
PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
await hub.RegisterNativeAsync(channel.Uri);
var hubClient = NotificationHubClient.CreateClientFromConnectionString("<connection string>", “<hub
name>");
var toast = @“<notification payload>";
hubClient.SendWindowsNativeNotificationAsync(toast);
http://code.msdn.microsoft.com/windowsazure/How-to-integrate-BizTalk-f0195690
http://code.msdn.microsoft.com/How-to-integrate-BizTalk-07fada58
http://msdn.microsoft.com/en-us/library/hh542796(v=VS.103).aspx
http://msdn.microsoft.com/en-us/library/hh709041(v=VS.103).aspx
http://code.msdn.microsoft.com/windowsazure/Service-Bus-Explorer-f2abca5a
http://code.msdn.microsoft.com/windowsazure/How-to-integrate-a-Mobile-8780500c
http://code.msdn.microsoft.com/windowsazure/How-to-integrate-a-Mobile-1ee6a5ea
http://code.msdn.microsoft.com/windowsazure/How-to-integrate-Mobile-6718aaf2
http://code.msdn.microsoft.com/windowsazure/How-to-integrate-Mobiles-77b25d12
http://code.msdn.microsoft.com/windowsazure/How-to-send-a-large-c36ab70e