本文整理汇总了C#中SubscriptionClient.Receive方法的典型用法代码示例。如果您正苦于以下问题:C# SubscriptionClient.Receive方法的具体用法?C# SubscriptionClient.Receive怎么用?C# SubscriptionClient.Receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SubscriptionClient
的用法示例。
在下文中一共展示了SubscriptionClient.Receive方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveAllMessagesFromSubscription
static void ReceiveAllMessagesFromSubscription(SubscriptionClient myTopicClient)
{
while (true)
{
var message = myTopicClient.Receive(TimeSpan.FromSeconds(5));
if (message != null)
{
Console.WriteLine("Message received. Id: {0} Body: {1}", message.MessageId, message.GetBody<string>());
}
else
{
Console.WriteLine("No more messages");
return;
}
}
}
示例2: Run
public override void Run()
{
string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
Client = SubscriptionClient.CreateFromConnectionString(connectionString, TopicName, "OrderProcessingSubscription");
BrokeredMessage message = null;
while (!IsStopped)
{
try
{
// Receive the message
BrokeredMessage receivedMessage = null;
receivedMessage = Client.Receive();
if (receivedMessage != null)
{
// Process the message
Trace.WriteLine("Processing", receivedMessage.SequenceNumber.ToString());
OnlineOrder order = receivedMessage.GetBody<OnlineOrder> ();
Trace.WriteLine(order.Customer + ": " + order.Product, "ProcessingMessage");
receivedMessage.Complete();
}
}
catch (MessagingException e)
{
if (!e.IsTransient)
{
Trace.WriteLine(e.Message);
throw;
}
Thread.Sleep(10000);
}
catch (OperationCanceledException e)
{
if (!IsStopped)
{
Trace.WriteLine(e.Message);
throw;
}
}
}
}
示例3: StartReceivingMessages
private void StartReceivingMessages(SubscriptionClient client, TextBox textBox)
{
var worker = new BackgroundWorker();
worker.DoWork += delegate(object sender, DoWorkEventArgs e)
{
while (true)
{
var brokeredMessage = client.Receive(TimeSpan.FromSeconds(1));
if (brokeredMessage != null)
{
var twitt = brokeredMessage.GetBody<Twitt>();
textBox.Text += string.Format("<{0}>{1}{2}", twitt.TimeStamp.ToString("dd/MM/yyyy HH:mm"), twitt.Content, Environment.NewLine);
}
}
};
worker.RunWorkerAsync();
}