public async static Task <TopicClient> EnsureTopicAsync(this MessagingFactory factory, TopicDescription topicDescription) { await new NamespaceManager(factory.Address, factory.GetSettings().TokenProvider) .TryCreateEntity( mgr => TopicCreateAsync(mgr, topicDescription), mgr => TopicShouldExistAsync(mgr, topicDescription)).ConfigureAwait(false); return(factory.CreateTopicClient(topicDescription.Path)); }
public async static Task <QueueClient> EnsureQueueAsync(this MessagingFactory factory, QueueDescription queueDescription, ReceiveMode mode = ReceiveMode.PeekLock) { await new NamespaceManager(factory.Address, factory.GetSettings().TokenProvider) .TryCreateEntity( mgr => QueueCreateAsync(mgr, queueDescription), mgr => QueueShouldExistAsync(mgr, queueDescription)).ConfigureAwait(false); return(factory.CreateQueueClient(queueDescription.Path, mode)); }
public async static Task <SubscriptionClient> EnsureSubscriptionAsync(this MessagingFactory factory, SubscriptionDescription subscriptionDescription, ReceiveMode mode = ReceiveMode.PeekLock) { await new NamespaceManager(factory.Address, factory.GetSettings().TokenProvider) .TryCreateEntity( mgr => SubscriptionCreateAsync(mgr, subscriptionDescription), mgr => SubscriptionShouldExistAsync(mgr, subscriptionDescription)).ConfigureAwait(false); return(factory.CreateSubscriptionClient(subscriptionDescription.TopicPath, subscriptionDescription.Name, mode)); }
public override MessagingFactory CreateMessagingFactory(string entityPath, string connectionStringName = null) { // demonstrate that the MessagingFactory can be customized // per queue/topic string connectionString = GetConnectionString(connectionStringName); MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString); MessagingFactorySettings settings = factory.GetSettings(); settings.OperationTimeout = TimeSpan.FromSeconds(15); return(MessagingFactory.Create(factory.Address, settings)); }
public async override Task <MessagingFactory> CreateMessagingFactoryAsync(string entityPath) { // demonstrate that the MessagingFactory can be customized // per queue/topic MessagingFactory factory = MessagingFactory.CreateFromConnectionString(_config.ConnectionString); MessagingFactorySettings settings = factory.GetSettings(); settings.OperationTimeout = TimeSpan.FromSeconds(15); factory = await MessagingFactory.CreateAsync(factory.Address, settings); return(factory); }
public ServiceBusListener(SubscriptionInfo subscriptionInfo) { // keep a record of the callback URI and workflowId callbackUrl = subscriptionInfo.logicAppInfo.CallbackUrl; workflowId = subscriptionInfo.logicAppInfo.WorkflowId; // initialise logMessageStub to standardise the tracing output logMessageStub = String.Format("{0} ({1}), ", subscriptionInfo.logicAppInfo.Name, Guid.NewGuid().ToString()); if (subscriptionInfo.triggerConfig.QueueName != null && subscriptionInfo.triggerConfig.QueueName.Length > 1) { logMessageStub += String.Format("queue={0}", subscriptionInfo.triggerConfig.QueueName); } else { logMessageStub += String.Format("topic={0}, subscription={1}", subscriptionInfo.triggerConfig.TopicName, subscriptionInfo.triggerConfig.SubscriptionName); } // initialise the messaging factory, using either the provided connection string, or the one in config string connectionString = String.Empty; if (String.IsNullOrEmpty(subscriptionInfo.triggerConfig.ServiceBusConnectionString)) { connectionString = ConfigurationManager.AppSettings["MyServiceBusConnectionString"]; Trace.WriteLine(String.Format("{0}: {1} Service Bus connection string retrieved via configuration manager, workflow id: {2}", logMessageStub, DateTime.Now.ToString("yyyyMMdd HHmmss"), workflowId)); } else { connectionString = subscriptionInfo.triggerConfig.ServiceBusConnectionString; Trace.WriteLine(String.Format("{0}: {1} Service Bus connection string supplied via subscription request, workflow id: {2}", logMessageStub, DateTime.Now.ToString("yyyyMMdd HHmmss"), workflowId)); } if (String.IsNullOrEmpty(connectionString)) { throw new Exception("No service bus connection string supplied or available in configuration"); } else { try { // add the OperationTimeout attribute if not already part of the connection string if (!connectionString.Contains("OperationTimeout=")) { int operationTimeoutMinutes = 60; int.TryParse(ConfigurationManager.AppSettings["ServiceBusOperationTimeoutMinutes"], out operationTimeoutMinutes); TimeSpan operationTimeout = new TimeSpan(0, operationTimeoutMinutes, 0); connectionString += ";OperationTimeout=" + operationTimeout.ToString(); } // create the messaging factory messagingFactory = MessagingFactory.CreateFromConnectionString(connectionString); Trace.WriteLine(String.Format("{0}: {1} Messaging factory created with timeout of {2} minutes, workflow id: {3}", logMessageStub, DateTime.Now.ToString("yyyyMMdd HHmmss"), messagingFactory.GetSettings().OperationTimeout.TotalMinutes, workflowId)); } catch (Exception ex) { Trace.WriteLine(String.Format("{0}: {1} Error encountered connecting to Azure Service Bus. Connection string: {2}. Error details: {3}", logMessageStub, DateTime.Now.ToString("yyyyMMdd HHmmss"), connectionString, ex.ToString())); throw ex; } } }
private static bool FactoryEquals(MessagingFactory factory1, MessagingFactory factory2) { bool flag; bool flag1; bool flag2; bool flag3; bool flag4; MessagingFactorySettings settings = factory1.GetSettings(); SharedSecretTokenProvider tokenProvider = settings.TokenProvider as SharedSecretTokenProvider; SharedAccessSignatureTokenProvider sharedAccessSignatureTokenProvider = settings.TokenProvider as SharedAccessSignatureTokenProvider; WindowsTokenProvider windowsTokenProvider = settings.TokenProvider as WindowsTokenProvider; OAuthTokenProvider oAuthTokenProvider = settings.TokenProvider as OAuthTokenProvider; MessagingFactorySettings messagingFactorySetting = factory2.GetSettings(); SharedSecretTokenProvider sharedSecretTokenProvider = messagingFactorySetting.TokenProvider as SharedSecretTokenProvider; SharedAccessSignatureTokenProvider tokenProvider1 = messagingFactorySetting.TokenProvider as SharedAccessSignatureTokenProvider; WindowsTokenProvider windowsTokenProvider1 = messagingFactorySetting.TokenProvider as WindowsTokenProvider; OAuthTokenProvider oAuthTokenProvider1 = messagingFactorySetting.TokenProvider as OAuthTokenProvider; if (settings.OperationTimeout != messagingFactorySetting.OperationTimeout) { return(false); } if (settings.TransportType != messagingFactorySetting.TransportType) { return(false); } if (tokenProvider != null || sharedSecretTokenProvider != null) { flag = (tokenProvider == null ? false : sharedSecretTokenProvider != null); } else { flag = true; } bool flag5 = flag; if (windowsTokenProvider != null || windowsTokenProvider1 != null) { flag1 = (windowsTokenProvider == null ? false : windowsTokenProvider1 != null); } else { flag1 = true; } bool flag6 = flag1; if (oAuthTokenProvider != null || oAuthTokenProvider1 != null) { flag2 = (oAuthTokenProvider == null ? false : oAuthTokenProvider1 != null); } else { flag2 = true; } bool flag7 = flag2; if (sharedAccessSignatureTokenProvider != null || tokenProvider1 != null) { flag3 = (sharedAccessSignatureTokenProvider == null ? false : tokenProvider1 != null); } else { flag3 = true; } bool flag8 = flag3; if (!flag5 || !flag6 || !flag7 || !flag8) { return(false); } if (tokenProvider != null && sharedSecretTokenProvider != null && (tokenProvider.IssuerName != sharedSecretTokenProvider.IssuerName || !tokenProvider.IssuerSecret.SequenceEqual <byte>(sharedSecretTokenProvider.IssuerSecret) || tokenProvider.IsWebTokenSupported != sharedSecretTokenProvider.IsWebTokenSupported)) { return(false); } if (sharedAccessSignatureTokenProvider != null && tokenProvider1 != null) { if (sharedAccessSignatureTokenProvider.encodedSharedAccessKey != null || tokenProvider1.encodedSharedAccessKey != null) { flag4 = (sharedAccessSignatureTokenProvider.encodedSharedAccessKey == null ? false : tokenProvider1.encodedSharedAccessKey != null); } else { flag4 = true; } bool flag9 = flag4; if (sharedAccessSignatureTokenProvider.keyName != tokenProvider1.keyName || sharedAccessSignatureTokenProvider.tokenTimeToLive != tokenProvider1.tokenTimeToLive || !flag9) { return(false); } if (sharedAccessSignatureTokenProvider.encodedSharedAccessKey != null && tokenProvider1.encodedSharedAccessKey != null) { if ((int)sharedAccessSignatureTokenProvider.encodedSharedAccessKey.Length != (int)tokenProvider1.encodedSharedAccessKey.Length) { return(false); } if (!sharedAccessSignatureTokenProvider.encodedSharedAccessKey.SequenceEqual <byte>(tokenProvider1.encodedSharedAccessKey)) { return(false); } } } if (oAuthTokenProvider != null && oAuthTokenProvider1 != null && oAuthTokenProvider.IsWebTokenSupported != oAuthTokenProvider1.IsWebTokenSupported) { return(false); } if (windowsTokenProvider != null && windowsTokenProvider1 != null) { if (windowsTokenProvider.IsWebTokenSupported != windowsTokenProvider1.IsWebTokenSupported || windowsTokenProvider.stsUris.Count != windowsTokenProvider1.stsUris.Count) { return(false); } if (windowsTokenProvider.stsUris.Where <Uri>((Uri t, int i) => t != windowsTokenProvider1.stsUris[i]).Any <Uri>()) { return(false); } if (windowsTokenProvider.credential == null && windowsTokenProvider1.credential != null || windowsTokenProvider.credential != null && windowsTokenProvider1.credential == null) { return(false); } if (windowsTokenProvider.credential != null && windowsTokenProvider1.credential != null && (!windowsTokenProvider.credential.Domain.Equals(windowsTokenProvider1.credential.Domain, StringComparison.OrdinalIgnoreCase) || !windowsTokenProvider.credential.UserName.Equals(windowsTokenProvider1.credential.UserName, StringComparison.OrdinalIgnoreCase) || !windowsTokenProvider.credential.Password.Equals(windowsTokenProvider1.credential.Password))) { return(false); } } return(factory1.Address == factory2.Address); }