/// <summary> /// Adds a Service Bus host using a connection string (Endpoint=...., etc.). /// </summary> /// <param name="configurator">The bus factory configurator</param> /// <param name="connectionString">The connection string in the proper format</param> /// <param name="configure">A callback to further configure the service bus</param> /// <returns>The service bus host</returns> public static IServiceBusHost Host(this IServiceBusBusFactoryConfigurator configurator, string connectionString, Action <IServiceBusHostConfigurator> configure) { // in case they pass a URI by mistake (it happens) if (Uri.IsWellFormedUriString(connectionString, UriKind.Absolute)) { var hostAddress = new Uri(connectionString); return(Host(configurator, hostAddress, configure)); } var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); var hostConfigurator = new ServiceBusHostConfigurator(namespaceManager.Address) { TokenProvider = namespaceManager.Settings.TokenProvider }; if (namespaceManager.Settings.OperationTimeout > TimeSpan.Zero) { hostConfigurator.OperationTimeout = namespaceManager.Settings.OperationTimeout; } configure(hostConfigurator); return(configurator.Host(hostConfigurator.Settings)); }
public static IEventDataReceiver CreateEventDataReceiver(this IBusFactorySelector selector, IBinder binder, Action <IWebJobReceiverConfigurator> configure) { if (binder == null) { throw new ArgumentNullException(nameof(binder)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var topologyConfiguration = new ServiceBusTopologyConfiguration(AzureBusFactory.MessageTopology); var busConfiguration = new ServiceBusBusConfiguration(topologyConfiguration); ServiceBusHostConfigurator hostConfigurator = new ServiceBusHostConfigurator(new Uri("sb://no-host-configured/")); var hostConfiguration = busConfiguration.CreateHostConfiguration(hostConfigurator.Settings); var endpointConfiguration = new BrokeredMessageReceiverServiceBusEndpointConfiguration(hostConfiguration, busConfiguration); var configurator = new WebJobEventDataReceiverSpecification(binder, endpointConfiguration); configure(configurator); return(configurator.Build()); }
/// <summary> /// Adds a Service Bus host using a connection string (Endpoint=...., etc.). /// </summary> /// <param name="configurator">The bus factory configurator</param> /// <param name="connectionString">The connection string in the proper format</param> /// <param name="configure">A callback to further configure the service bus</param> /// <returns>The service bus host</returns> public static IServiceBusHost Host(this IServiceBusBusFactoryConfigurator configurator, string connectionString, Action <IServiceBusHostConfigurator> configure) { // in case they pass a URI by mistake (it happens) try { var hostAddress = new Uri(connectionString); return(Host(configurator, hostAddress, configure)); } catch (UriFormatException) { } var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); var hostConfigurator = new ServiceBusHostConfigurator(namespaceManager.Address) { TokenProvider = namespaceManager.Settings.TokenProvider, OperationTimeout = namespaceManager.Settings.OperationTimeout }; configure(hostConfigurator); return(configurator.Host(hostConfigurator.Settings)); }
public static ManagementClient GetManagementClient() { var hostAddress = AzureServiceBusEndpointUriCreator.Create(ServiceNamespace); var accountSettings = new TestAzureServiceBusAccountSettings(); var keyName = accountSettings.KeyName; var accessKey = accountSettings.SharedAccessKey; var hostConfigurator = new ServiceBusHostConfigurator(hostAddress); hostConfigurator.SharedAccessSignature(s => { s.KeyName = keyName; s.SharedAccessKey = accessKey; s.TokenTimeToLive = accountSettings.TokenTimeToLive; s.TokenScope = accountSettings.TokenScope; }); var endpoint = new UriBuilder(hostAddress) { Path = "" }.Uri.ToString(); var managementClient = new ManagementClient(endpoint, hostConfigurator.Settings.TokenProvider); return(managementClient); }
public async Task Endpoint_should_include_namespace() { var connectionString = "Endpoint=sb://my-endpoint.servicebus.windows.net/someNamespace;SharedAccessKeyName=SomeKeyName;SharedAccessKey=SomeKey"; var configurator = new ServiceBusHostConfigurator(connectionString); Assert.That(configurator.Settings.ServiceUri.ToString(), Is.EqualTo("sb://my-endpoint.servicebus.windows.net/someNamespace")); }
public async Task Should_succeed_with_endpoint_at_the_end_without_semicolon() { var connectionString = "SharedAccessKeyName=SomeKeyName;SharedAccessKey=SomeKey;Endpoint=sb://my-endpoint.servicebus.windows.net"; var configurator = new ServiceBusHostConfigurator(connectionString); Assert.That(configurator.Settings.ServiceUri.ToString(), Is.EqualTo("sb://my-endpoint.servicebus.windows.net/")); }
/// <summary> /// Adds a service bus host using the MassTransit style URI host name /// </summary> /// <param name="configurator">The bus factory configurator</param> /// <param name="hostAddress">The host address, in MassTransit format (sb://namespace.servicebus.windows.net/scope)</param> /// <param name="configure">A callback to further configure the service bus</param> /// <returns>The service bus host</returns> public static IServiceBusHost Host(this IServiceBusBusFactoryConfigurator configurator, Uri hostAddress, Action <IServiceBusHostConfigurator> configure) { var hostConfigurator = new ServiceBusHostConfigurator(hostAddress); configure(hostConfigurator); return(configurator.Host(hostConfigurator.Settings)); }
/// <summary> /// Adds a service bus host using the MassTransit style URI host name /// </summary> /// <param name="configurator">The bus factory configurator</param> /// <param name="hostAddress"> /// The host address, in MassTransit format (sb://namespace.servicebus.windows.net/scope) /// </param> /// <param name="configure">A callback to further configure the service bus</param> /// <returns>The service bus host</returns> public static void Host(this IServiceBusBusFactoryConfigurator configurator, Uri hostAddress, Action <IServiceBusHostConfigurator> configure = null) { var hostConfigurator = new ServiceBusHostConfigurator(hostAddress); configure?.Invoke(hostConfigurator); configurator.Host(hostConfigurator.Settings); }
/// <summary> /// Adds a Service Bus host using a connection string (Endpoint=...., etc.). /// </summary> /// <param name="configurator">The bus factory configurator</param> /// <param name="connectionString">The connection string in the proper format</param> /// <param name="configure">A callback to further configure the service bus</param> /// <returns>The service bus host</returns> public static IServiceBusHost Host(this IServiceBusBusFactoryConfigurator configurator, string connectionString, Action <IServiceBusHostConfigurator> configure = null) { // in case they pass a URI by mistake (it happens) if (Uri.IsWellFormedUriString(connectionString, UriKind.Absolute)) { var hostAddress = new Uri(connectionString); return(Host(configurator, hostAddress, configure)); } var hostConfigurator = new ServiceBusHostConfigurator(connectionString); configure?.Invoke(hostConfigurator); return(configurator.Host(hostConfigurator.Settings)); }
ManagementClient CreateManagementClient() { var hostConfigurator = new ServiceBusHostConfigurator(HostAddress); hostConfigurator.SharedAccessSignature(s => { s.KeyName = SharedAccessKeyName; s.SharedAccessKey = SharedAccessKeyValue; s.TokenTimeToLive = TokenTimeToLive; s.TokenScope = TokenScope; }); var endpoint = new UriBuilder(HostAddress) { Path = "" }.Uri.ToString(); return(new ManagementClient(endpoint, hostConfigurator.Settings.TokenProvider)); }