public static Configure AppFabricMessageQueue(this Configure config) { var configSection = Configure.GetConfigSection<AppFabricQueueConfig>(); if (configSection == null) throw new ConfigurationErrorsException("No AppFabricQueueConfig configuration section found"); var credentials = TransportClientCredentialBase.CreateSharedSecretCredential(configSection.IssuerName, configSection.IssuerKey); var managementUri = ServiceBusEnvironment.CreateServiceUri("https", configSection.ServiceNamespace, string.Empty); var runtimeUri = ServiceBusEnvironment.CreateServiceUri("sb", configSection.ServiceNamespace, string.Empty); var namespaceClient = new ServiceBusNamespaceClient(managementUri, credentials); var factory = MessagingFactory.Create(runtimeUri, credentials); config.Configurer.RegisterSingleton<ServiceBusNamespaceClient>(namespaceClient); config.Configurer.RegisterSingleton<MessagingFactory>(factory); config.Configurer.ConfigureComponent<AppFabricQueue>(DependencyLifecycle.SingleInstance); return config; }
private void InitializeAppFabric(AzureAppFabricOptions options) { Debug.Assert(null != options); // 1: Create the right credentials MyManagementCredentials = TransportClientCredentialBase.CreateSharedSecretCredential(options.AppFabricOwnerName, options.AppFabricOwnerKey); // 2: create the uri for the servicebus ServiceUri = ServiceBusEnvironment.CreateServiceUri(options.ServiceBusScheme, options.ServiceBusNameSpace, string.Empty); // 3: Create the Uri NamespaceClient = new ServiceBusNamespaceClient(ServiceUri, MyManagementCredentials); }
/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { owner.Extensions.Demand <IRoleConfigurationSettingsExtension>(); IRoleConfigurationSettingsExtension roleConfigExtension = owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); this.serviceBusEndpoint = roleConfigExtension.GetServiceBusEndpoint(WellKnownEndpointName.InterRoleCommunication); this.retryPolicy = roleConfigExtension.CommunicationRetryPolicy; if (this.serviceBusEndpoint != null) { // Configure Service Bus credentials and entity URI. var credentials = TransportClientCredentialBase.CreateSharedSecretCredential(this.serviceBusEndpoint.IssuerName, this.serviceBusEndpoint.IssuerSecret); var address = ServiceBusEnvironment.CreateServiceUri(WellKnownProtocolScheme.ServiceBus, this.serviceBusEndpoint.ServiceNamespace, String.Empty); // Configure Service Bus messaging factory and namespace client which is required for subscription management. this.messagingFactory = MessagingFactory.Create(address, credentials); this.managementClient = new ServiceBusNamespaceClient(address, credentials); ConfigureTopicClient(); ConfigureSubscriptionClient(this.ircSubscription = ConfigureSubscription(String.Concat(SubscriptionNamePrefix, this.senderInstanceID))); // Configure event receive action. this.receiveAction = (() => { BrokeredMessage msg = null; this.retryPolicy.ExecuteAction(() => { // Make sure we are not told to stop receiving while we are retrying. if (!cts.IsCancellationRequested) { if (EventReceiver.TryReceive(Settings.EventWaitTimeout, out msg)) { try { // Make sure we are not told to stop receiving while we were waiting for a new message. if (!cts.IsCancellationRequested) { // Extract the event data from brokered message. InterRoleCommunicationEvent e = msg.GetBody <InterRoleCommunicationEvent>(); // Notify all registered subscribers. NotifySubscribers(e); // Mark brokered message as complete. msg.Complete(this.retryPolicy); } else { msg.Defer(this.retryPolicy); } } catch (Exception ex) { // Abandons a brokered message and unlocks the message. msg.Abandon(this.retryPolicy); // Log an error. TraceManager.ServiceComponent.TraceError(ex); } } } }); }); // Configure event receive complete action. this.endReceive = ((ar) => { this.receiveAction.EndInvoke(ar); if (!cts.IsCancellationRequested) { this.receiveHandle = this.receiveAction.BeginInvoke(this.endReceive, null); } }); // Configure event send action. this.sendAction = ((e) => { this.retryPolicy.ExecuteAction(() => { EventSender.Send(e); }); }); // Configure event send complete action. this.endSend = ((ar) => { sendAction.EndInvoke(ar); }); } else { throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.SpecifiedServiceBusEndpointNotFound, WellKnownEndpointName.InterRoleCommunication, ServiceBusConfigurationSettings.SectionName)); } }
public AppFabricQueue(MessagingFactory factory, ServiceBusNamespaceClient namespaceClient) { this.factory = factory; this.namespaceClient = namespaceClient; }