本文整理汇总了C#中MessagingFactory.CreateTopicClient方法的典型用法代码示例。如果您正苦于以下问题:C# MessagingFactory.CreateTopicClient方法的具体用法?C# MessagingFactory.CreateTopicClient怎么用?C# MessagingFactory.CreateTopicClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagingFactory
的用法示例。
在下文中一共展示了MessagingFactory.CreateTopicClient方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: HeaterCommunication
public HeaterCommunication()
{
var topicNameSend = "businessrulestofieldgateway";
_topicNameReceive = "fieldgatewaytobusinessrules";
_namespaceMgr = NamespaceManager.CreateFromConnectionString(CloudConfigurationManager.GetSetting("ServiceBusConnectionString"));
_factory = MessagingFactory.CreateFromConnectionString(CloudConfigurationManager.GetSetting("ServiceBusConnectionString"));
_client = _factory.CreateTopicClient(topicNameSend);
}
示例3: TopicSender
/// <summary>
/// Initializes a new instance of the <see cref="TopicSender"/> class,
/// automatically creating the given topic if it does not exist.
/// </summary>
protected TopicSender(ServiceBusSettings settings, string topic, int maxNumberRetry, RetryStrategy retryStrategy)
{
this.settings = settings;
this.topic = topic;
this.retryStrategy = retryStrategy;
this.maxNumberRetry = maxNumberRetry;
this.messagingFactory = MessagingFactory.CreateFromConnectionString(settings.ConnectionString);
this.topicClient = messagingFactory.CreateTopicClient(this.topic);
this.retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(this.retryStrategy);
this.retryPolicy.Retrying += (s, e) =>
{
var handler = this.Retrying;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
Trace.TraceWarning("An error occurred in attempt number {1} to send a message: {0}", e.LastException.Message, e.CurrentRetryCount);
};
}
示例4: SetupAsync
public async Task SetupAsync(Type[] allMessageTypes, Type[] recievingMessageTypes)
{
_logger.Debug("Starting the setup of AzureServicebusTransport...");
_namespaceManager = NamespaceManager.CreateFromConnectionString(_configuration.GetConnectionString());
_messagingFactory = MessagingFactory.CreateFromConnectionString(_configuration.GetConnectionString());
_messageTypes = allMessageTypes;
var sendCommandTypes = _messageTypes
.Where(t => typeof (IBusCommand)
.IsAssignableFrom(t));
var sendEventTypes = _messageTypes
.Where(t => typeof(IBusEvent)
.IsAssignableFrom(t));
var recieveCommandTypes = recievingMessageTypes
.Where(t => typeof(IBusCommand)
.IsAssignableFrom(t));
var recieveEventTypes = recievingMessageTypes
.Where(t => typeof(IBusEvent)
.IsAssignableFrom(t));
if (_configuration.GetEnableTopicAndQueueCreation())
{
foreach (var type in sendCommandTypes)
{
var path = PathFactory.QueuePathFor(type);
if (!_namespaceManager.QueueExists(path))
await _namespaceManager.CreateQueueAsync(path);
var client = _messagingFactory.CreateQueueClient(path);
client.PrefetchCount = 10; //todo;: in config?
var eventDrivenMessagingOptions = new OnMessageOptions
{
AutoComplete = true, //todo: in config?
MaxConcurrentCalls = 10 //todo: in config?
};
eventDrivenMessagingOptions.ExceptionReceived += OnExceptionReceived;
client.OnMessageAsync(OnMessageRecieved, eventDrivenMessagingOptions);
if (!_queues.TryAdd(type, client))
{
_logger.Error("Could not add the queue with type: {0}", type.FullName);
}
}
foreach (var type in sendEventTypes)
{
var path = PathFactory.TopicPathFor(type);
if (!_namespaceManager.TopicExists(path))
_namespaceManager.CreateTopic(path);
var client = _messagingFactory.CreateTopicClient(path);
if (!_topics.TryAdd(type, client))
{
_logger.Error("Could not add the topic with type: {0}", type.FullName);
}
}
}
_logger.Debug("Setup of AzureServicebusTransport completed!");
throw new NotImplementedException();
}
示例5: Create
public TopicClient Create(string topic, MessagingFactory factory)
{
return factory.CreateTopicClient(topic);
}
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:4,代码来源:AzureServicebusTopicClientCreator.cs
示例6: SendMessagesToTopicAsync
async Task SendMessagesToTopicAsync(MessagingFactory messagingFactory)
{
// Create client for the topic.
var topicClient = messagingFactory.CreateTopicClient(TopicName);
// Create a message sender from the topic client.
Console.WriteLine("\nSending orders to topic.");
// Now we can start sending orders.
await Task.WhenAll(
SendOrder(topicClient, new Order()),
SendOrder(topicClient, new Order { Color = "blue", Quantity = 5, Priority = "low" }),
SendOrder(topicClient, new Order { Color = "red", Quantity = 10, Priority = "high" }),
SendOrder(topicClient, new Order { Color = "yellow", Quantity = 5, Priority = "low" }),
SendOrder(topicClient, new Order { Color = "blue", Quantity = 10, Priority = "low" }),
SendOrder(topicClient, new Order { Color = "blue", Quantity = 5, Priority = "high" }),
SendOrder(topicClient, new Order { Color = "blue", Quantity = 10, Priority = "low" }),
SendOrder(topicClient, new Order { Color = "red", Quantity = 5, Priority = "low" }),
SendOrder(topicClient, new Order { Color = "red", Quantity = 10, Priority = "low" }),
SendOrder(topicClient, new Order { Color = "red", Quantity = 5, Priority = "low" }),
SendOrder(topicClient, new Order { Color = "yellow", Quantity = 10, Priority = "high" }),
SendOrder(topicClient, new Order { Color = "yellow", Quantity = 5, Priority = "low" }),
SendOrder(topicClient, new Order { Color = "yellow", Quantity = 10, Priority = "low" })
);
Console.WriteLine("All messages sent.");
}
示例7: SendMessagesToTopic
static void SendMessagesToTopic(MessagingFactory messagingFactory)
{
// Create client for the topic.
TopicClient topicClient = messagingFactory.CreateTopicClient(Program.TopicName);
// Create a message sender from the topic client.
Console.WriteLine("\nSending orders to topic.");
// Now we can start sending orders.
SendOrder(topicClient, new Order());
SendOrder(topicClient, new Order() { Color = "blue", Quantity = 5, Priority = "low" });
SendOrder(topicClient, new Order() { Color = "red", Quantity = 10, Priority = "high" });
SendOrder(topicClient, new Order() { Color = "yellow", Quantity = 5, Priority = "low" });
SendOrder(topicClient, new Order() { Color = "blue", Quantity = 10, Priority = "low" });
SendOrder(topicClient, new Order() { Color = "blue", Quantity = 5, Priority = "high" });
SendOrder(topicClient, new Order() { Color = "blue", Quantity = 10, Priority = "low" });
SendOrder(topicClient, new Order() { Color = "red", Quantity = 5, Priority = "low" });
SendOrder(topicClient, new Order() { Color = "red", Quantity = 10, Priority = "low" });
SendOrder(topicClient, new Order() { Color = "red", Quantity = 5, Priority = "low" });
SendOrder(topicClient, new Order() { Color = "yellow", Quantity = 10, Priority = "high" });
SendOrder(topicClient, new Order() { Color = "yellow", Quantity = 5, Priority = "low" });
SendOrder(topicClient, new Order() { Color = "yellow", Quantity = 10, Priority = "low" });
Console.WriteLine("All messages sent.");
}
示例8: CreateTopicClient
//Criar o TopicClient a partir do uri do serviço, do tokenProvider e do TopicDescription
private static TopicClient CreateTopicClient(Uri serviceUri, TokenProvider tokenProvider, TopicDescription myTopic, out MessagingFactory factory)
{
factory = MessagingFactory.Create(serviceUri, tokenProvider);
return factory.CreateTopicClient(myTopic.Path);
}