/// <summary> /// Configures a change feed for specified table /// </summary> /// <typeparam name="TRowChangedData">The <see cref="IMessage"/> representing the state of a changed row in the table being watched</typeparam> /// <param name="connectionString">The connection string for the sql server with the database and table to watch for changes</param> /// <param name="databaseName">Optional. The database containing the table to watch. If not specified, Database or InitialCatalog of the connectionString will be used.</param> /// <param name="tableName">The name of the table to watch</param> /// <param name="optionsBuilder">An optional builder allowing more complex change feed configuration</param> /// <returns><see cref="IChatterBuilder"/></returns> public static IChatterBuilder AddSqlChangeFeed <TRowChangedData>(this IChatterBuilder builder, string connectionString, string databaseName, string tableName, Action <SqlChangeFeedOptionsBuilder> optionsBuilder = null) where TRowChangedData : class, IMessage, new() { var changeFeedOptions = builder.Services.AddSqlChangeFeedOptionsBuilder(connectionString, tableName, databaseName); optionsBuilder?.Invoke(changeFeedOptions); SqlChangeFeedOptions options = changeFeedOptions.Build(); builder.Services.AddIfNotRegistered <ISqlDependencyManager <TRowChangedData> >(ServiceLifetime.Scoped, sp => { return(new SqlDependencyManager <TRowChangedData>(options)); }); builder.AddSqlServiceBroker(ssbBuilder => { var receiver = string.IsNullOrWhiteSpace(options.ChangeFeedQueueName) ? $"{ChatterServiceBrokerConstants.ChatterQueuePrefix}{typeof(TRowChangedData).Name}" : options.ChangeFeedQueueName; var dlq = string.IsNullOrWhiteSpace(options.ChangeFeedDeadLetterServiceName) ? $"{ChatterServiceBrokerConstants.ChatterDeadLetterServicePrefix}{typeof(TRowChangedData).Name}" : options.ChangeFeedDeadLetterServiceName; ssbBuilder.AddSqlServiceBrokerOptions(options.ServiceBrokerOptions) .AddQueueReceiver <ProcessChangeFeedCommand <TRowChangedData> >(receiver, errorQueuePath: options.ReceiverOptions.ErrorQueuePath, transactionMode: options.ReceiverOptions.TransactionMode, deadLetterServicePath: dlq); }); if (options.ProcessChangeFeedCommandViaChatter) { builder.Services.Replace <IBrokeredMessageReceiver <ProcessChangeFeedCommand <TRowChangedData> >, ChangeFeedReceiver <ProcessChangeFeedCommand <TRowChangedData>, TRowChangedData> >(ServiceLifetime.Scoped); } return(builder); }
public UninstallChangeFeedScript(SqlChangeFeedOptions options, string uninstallationProcedureName, string conversationQueueName, string conversationServiceName, string conversationTriggerName, string installationProcedureName, string deadLetterQueueName, string deadLetterServiceName) : base(options?.ConnectionString) { if (string.IsNullOrWhiteSpace(uninstallationProcedureName)) { throw new ArgumentException($"'{nameof(uninstallationProcedureName)}' cannot be null or whitespace", nameof(uninstallationProcedureName)); } if (string.IsNullOrWhiteSpace(conversationQueueName)) { throw new ArgumentException($"'{nameof(conversationQueueName)}' cannot be null or whitespace", nameof(conversationQueueName)); } if (string.IsNullOrWhiteSpace(conversationServiceName)) { throw new ArgumentException($"'{nameof(conversationServiceName)}' cannot be null or whitespace", nameof(conversationServiceName)); } if (string.IsNullOrWhiteSpace(conversationTriggerName)) { throw new ArgumentException($"'{nameof(conversationTriggerName)}' cannot be null or whitespace", nameof(conversationTriggerName)); } if (string.IsNullOrWhiteSpace(installationProcedureName)) { throw new ArgumentException($"'{nameof(installationProcedureName)}' cannot be null or whitespace", nameof(installationProcedureName)); } _options = options ?? throw new ArgumentNullException(nameof(options)); _uninstallationProcedureName = uninstallationProcedureName; _conversationQueueName = conversationQueueName; _conversationServiceName = conversationServiceName; _conversationTriggerName = conversationTriggerName; _installationProcedureName = installationProcedureName; _deadLetterQueueName = deadLetterQueueName; _deadLetterServiceName = deadLetterServiceName; }
public SqlDependencyManager(SqlChangeFeedOptions options) => Options = options;