本文整理汇总了C#中NamespaceManager.TopicExists方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceManager.TopicExists方法的具体用法?C# NamespaceManager.TopicExists怎么用?C# NamespaceManager.TopicExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceManager
的用法示例。
在下文中一共展示了NamespaceManager.TopicExists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: OnStart
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;
var connectionString = CloudConfigurationManager.GetSetting("topicConnectionString");
var topicName = CloudConfigurationManager.GetSetting("topicName");
_nsMgr = NamespaceManager.CreateFromConnectionString(connectionString);
if (!_nsMgr.TopicExists(topicName))
{
_nsMgr.CreateTopic(topicName);
}
if (!_nsMgr.SubscriptionExists(topicName, "audit"))
{
_nsMgr.CreateSubscription(topicName, "audit");
}
_client = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, "audit", ReceiveMode.ReceiveAndDelete);
var result = base.OnStart();
Trace.TraceInformation("NTM.Auditing has been started");
return result;
}
示例3: Main
static void Main(string[] args)
{
GetUserCredentials();
TokenProvider tokenProvider = null;
Uri serviceUri = null;
CreateTokenProviderAndServiceUri(out tokenProvider, out serviceUri);
NamespaceManager namespaceManager = new NamespaceManager(serviceUri, tokenProvider);
Console.WriteLine("Creating Topic 'IssueTrackingTopic'...");
if (namespaceManager.TopicExists("IssueTrackingTopic"))
namespaceManager.DeleteTopic("IssueTrackingTopic");
MessagingFactory factory = null;
TopicDescription myTopic = namespaceManager.CreateTopic(TopicName);
// Criar duas Subscrições
Console.WriteLine("Creating Subscriptions 'AuditSubscription' and 'AgentSubscription'...");
SubscriptionDescription myAuditSubscription = namespaceManager.CreateSubscription((myTopic.Path, "AuditSubscription");
SubscriptionDescription myAgentSubscription = namespaceManager.CreateSubscription(myTopic.Path, "AgentSubscription");
TopicClient myTopicClient = CreateTopicClient(serviceUri, tokenProvider, myTopic, out factory);
List<BrokeredMessage> messageList = new List<BrokeredMessage>();
messageList.Add(CreateIssueMessage("1", "First message information"));
messageList.Add(CreateIssueMessage("2", "Second message information"));
messageList.Add(CreateIssueMessage("3", "Third message information"));
Console.WriteLine("\nSending messages to topic...");
SendListOfMessages(messageList, myTopicClient);
Console.WriteLine("\nFinished sending messages, press ENTER to clean up and exit.");
myTopicClient.Close();
Console.ReadLine();
namespaceManager.DeleteTopic(TopicName);
}
示例4: Main
static void Main(string[] args)
{
Console.Write("Enter some subscription name: ");
string name = Console.ReadLine();
var serviceNamespace = "msswit2013relay";
var issuerName = "owner";
var issuerSecret = "IqyIwa7gNjBO89HT+3Vd1CcoBbyibvcv6Hd92J+FtPg=";
Uri uri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, string.Empty);
TokenProvider tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuerName, issuerSecret);
NamespaceManager namespaceManager = new NamespaceManager(uri, tokenProvider);
if (!namespaceManager.TopicExists("MyTopic"))
{
namespaceManager.CreateTopic(new TopicDescription("MyTopic"));
}
Console.WriteLine("topic ready");
if (!namespaceManager.SubscriptionExists("MyTopic", "subscription-" + name))
{
namespaceManager.CreateSubscription("MyTopic", "subscription-" + name);
}
Console.WriteLine("subscription ready");
MessagingFactory factory = MessagingFactory.Create(uri, tokenProvider);
MessageReceiver receiver = factory.CreateMessageReceiver("MyTopic/subscriptions/subscription-" + name);
while (true)
{
BrokeredMessage receivedMessage = receiver.Receive();
if (receivedMessage != null)
{
try
{
Console.WriteLine("label: {0}", receivedMessage.Label);
Console.WriteLine("login: {0}", receivedMessage.Properties["login"]);
Console.WriteLine("pass: {0}", receivedMessage.GetBody<ServiceBusTestMessage>().Password);
receivedMessage.Complete();
}
catch (Exception e)
{
receivedMessage.Abandon();
Console.WriteLine(e.Message);
}
}
else
{
Thread.Sleep(new TimeSpan(0, 0, 10));
}
}
}
示例5: ServiceBusMessageBus
public ServiceBusMessageBus(string connectionString, string topicName, ISerializer serializer = null) {
_topicName = topicName;
_serializer = serializer ?? new JsonNetSerializer();
_subscriptionName = "MessageBus";
_namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!_namespaceManager.TopicExists(_topicName))
_namespaceManager.CreateTopic(_topicName);
_topicClient = TopicClient.CreateFromConnectionString(connectionString, _topicName);
if (!_namespaceManager.SubscriptionExists(_topicName, _subscriptionName))
_namespaceManager.CreateSubscription(_topicName, _subscriptionName);
_subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, _topicName, _subscriptionName, ReceiveMode.ReceiveAndDelete);
_subscriptionClient.OnMessageAsync(OnMessageAsync, new OnMessageOptions { AutoComplete = true });
}
示例6: Bus
public Bus() {
connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
// Configure Topic Settings
var td = new TopicDescription(topicName);
td.MaxSizeInMegabytes = 5120;
td.DefaultMessageTimeToLive = new TimeSpan(0, 1, 0);
if (!namespaceManager.TopicExists(topicName)) {
namespaceManager.CreateTopic(topicName);
}
factory = MessagingFactory.CreateFromConnectionString(connectionString);
sender = factory.CreateMessageSender(topicName);
}
示例7: CoAppRepositoryDaemonMain
public CoAppRepositoryDaemonMain() {
connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
// Configure Topic Settings
var td1 = new TopicDescription(regenSiteTopic) {
MaxSizeInMegabytes = 5120,
DefaultMessageTimeToLive = new TimeSpan(0, 1, 0)
};
if (!namespaceManager.TopicExists(regenSiteTopic)) {
namespaceManager.CreateTopic(regenSiteTopic);
}
factory = MessagingFactory.CreateFromConnectionString(connectionString);
_running = true;
}
示例8: AzureServiceBusMessageQueue
public AzureServiceBusMessageQueue(string connectionString, string inputQueue)
{
try
{
log.Info("Initializing Azure Service Bus transport with logical input queue '{0}'", inputQueue);
namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
InputQueue = inputQueue;
log.Info("Ensuring that topic '{0}' exists", TopicName);
if (!namespaceManager.TopicExists(TopicName))
{
try
{
namespaceManager.CreateTopic(TopicName);
}
catch
{
// just assume the call failed because the topic already exists - if GetTopic below
// fails, then something must be wrong, and then we just want to fail immediately
}
}
topicDescription = namespaceManager.GetTopic(TopicName);
log.Info("Creating topic client");
topicClient = TopicClient.CreateFromConnectionString(connectionString, topicDescription.Path);
// if we're in one-way mode, just quit here
if (inputQueue == null) return;
GetOrCreateSubscription(InputQueue);
log.Info("Creating subscription client");
subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, TopicName, InputQueue, ReceiveMode.PeekLock);
}
catch (Exception e)
{
throw new ApplicationException(
string.Format(
"An error occurred while initializing Azure Service Bus with logical input queue '{0}'",
inputQueue), e);
}
}
示例9: 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, RetryStrategy retryStrategy)
{
this.settings = settings;
this.topic = topic;
this.tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
this.serviceUri = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);
// TODO: This could be injected.
this.retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(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);
};
var factory = MessagingFactory.Create(this.serviceUri, this.tokenProvider);
this.topicClient = factory.CreateTopicClient(this.topic);
var namespaceManager = new NamespaceManager(this.serviceUri, this.tokenProvider);
foreach (var topicSettings in settings.Topics)
{
if (!namespaceManager.TopicExists(topicSettings.Path))
{
namespaceManager.CreateTopic(topicSettings.Path);
}
foreach (var subscriptionSetting in topicSettings.Subscriptions)
{
if (!namespaceManager.SubscriptionExists(topicSettings.Path, subscriptionSetting.Name))
{
namespaceManager.CreateSubscription(topicSettings.Path, subscriptionSetting.Name);
}
}
}
}
示例10: SetupAzureServiceBus
private void SetupAzureServiceBus()
{
Composable.GetExport<IXLogger>().Debug("Azure ServiceBus Scaling - INIT");
_namespaceManager = NamespaceManager.CreateFromConnectionString(_connectionString);
if (!_namespaceManager.TopicExists(TopicPath))
{
Composable.GetExport<IXLogger>().Debug("Creating Topic for Azure Service Bus");
TopicDescription td = _namespaceManager.CreateTopic(TopicPath);
}
if (!_namespaceManager.SubscriptionExists(TopicPath, _sid))
{
_namespaceManager.CreateSubscription(TopicPath, _sid);
Composable.GetExport<IXLogger>().Debug("Creating Subscription for Azure Service Bus");
}
_topicClient = TopicClient.CreateFromConnectionString(_connectionString, TopicPath);
_subscriptionClient = SubscriptionClient.CreateFromConnectionString(_connectionString, TopicPath, _sid);
}
示例11: 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();
}
示例12: TopicExists
bool TopicExists(NamespaceManager namespaceClient, string topicpath)
{
var key = topicpath;
logger.InfoFormat("Checking cache for existence of the topic '{0}'", topicpath);
var exists = rememberTopicExistence.GetOrAdd(key, s =>
{
logger.InfoFormat("Checking namespace for existence of the topic '{0}'", topicpath);
return namespaceClient.TopicExists(key);
});
logger.InfoFormat("Determined that the topic '{0}' {1}", topicpath, exists ? "exists" : "does not exist");
return exists;
}