本文整理汇总了C#中MessagingFactory.CreateSubscriptionClient方法的典型用法代码示例。如果您正苦于以下问题:C# MessagingFactory.CreateSubscriptionClient方法的具体用法?C# MessagingFactory.CreateSubscriptionClient怎么用?C# MessagingFactory.CreateSubscriptionClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagingFactory
的用法示例。
在下文中一共展示了MessagingFactory.CreateSubscriptionClient方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public async void Init(MessageReceived messageReceivedHandler) {
this.random = new Random();
//ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect;
// Tcp mode does not work when I run in a VM (VirtualBox) and the host
// is using a wireless connection. Hard coding to Http.
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
this.factory = MessagingFactory.CreateFromConnectionString(connectionString);
this.namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.TopicExists(topicName)) {
namespaceManager.CreateTopic(topicName);
}
this.subscriptionName = Guid.NewGuid().ToString();
// Not needed really, it's a GUID...
if (!namespaceManager.SubscriptionExists(topicName, subscriptionName)) {
namespaceManager.CreateSubscription(topicName, subscriptionName);
}
this.topicClient = factory.CreateTopicClient(topicName);
this.subClient = factory.CreateSubscriptionClient(topicName, subscriptionName);
while (true) {
await ReceiveMessageTaskAsync(messageReceivedHandler);
}
}
示例2: ReceiveAllMessageFromSubscription
static void ReceiveAllMessageFromSubscription(MessagingFactory messagingFactory, string subsName)
{
int receivedMessages = 0;
// Create subscription client.
SubscriptionClient subsClient =
messagingFactory.CreateSubscriptionClient(Conts.TopicName, subsName, ReceiveMode.ReceiveAndDelete);
// Create a receiver from the subscription client and receive all messages.
Console.WriteLine("\nReceiving messages from subscription {0}.", subsName);
while (true)
{
BrokeredMessage receivedMessage;
receivedMessage = subsClient.Receive(TimeSpan.FromSeconds(1));
if (receivedMessage != null)
{
Console.WriteLine();
DateTime dob = ((DateTime)receivedMessage.Properties["DOB"]);
Console.WriteLine("Id = {1} DOB = {0}", receivedMessage.MessageId, dob);
receivedMessage.Dispose();
receivedMessages++;
}
else
{
// No more messages to receive.
break;
}
}
Console.WriteLine("Received {0} messages from subscription {1}.", receivedMessages, subsClient.Name);
}
示例3: ReceiveAllMessageFromSubscription
async Task ReceiveAllMessageFromSubscription(MessagingFactory messagingFactory, string subsName)
{
var receivedMessages = 0;
// Create subscription client.
var subscriptionClient =
messagingFactory.CreateSubscriptionClient(TopicName, subsName, ReceiveMode.ReceiveAndDelete);
// Create a receiver from the subscription client and receive all messages.
Console.WriteLine("\nReceiving messages from subscription {0}.", subsName);
while (true)
{
var receivedMessage = await subscriptionClient.ReceiveAsync(TimeSpan.Zero);
if (receivedMessage != null)
{
foreach (var prop in receivedMessage.Properties)
{
Console.Write("{0}={1},", prop.Key, prop.Value);
}
Console.WriteLine("CorrelationId={0}", receivedMessage.CorrelationId);
receivedMessage.Dispose();
receivedMessages++;
}
else
{
// No more messages to receive.
break;
}
}
Console.WriteLine("Received {0} messages from subscription {1}.", receivedMessages, subscriptionClient.Name);
}
示例4: Create
public SubscriptionClient Create(SubscriptionDescription description, MessagingFactory factory)
{
var subscriptionClient = factory.CreateSubscriptionClient(description.TopicPath, description.Name, ShouldRetry() ? ReceiveMode.PeekLock : ReceiveMode.ReceiveAndDelete);
subscriptionClient.PrefetchCount = BatchSize;
return subscriptionClient;
}
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:6,代码来源:AzureServicebusSubscriptionClientCreator.cs
示例5: CreateTopicSubscriptionClient
private static SubscriptionClient CreateTopicSubscriptionClient(Uri serviceUri, TokenProvider tokenProvider, string subscriptionName, ref MessagingFactory factory)
{
if (factory == null)
factory = MessagingFactory.Create(serviceUri, tokenProvider);
return factory.CreateSubscriptionClient(TopicName, subscriptionName);
}