예제 #1
0
 public OutboxFifoReceiver(SampleAppConfig configSettings)
 {
     //We need a Message Receiver to pickup the Messages that are Published!
     // NOTE: Since our payloads are simple strings we use 'string' payload type!
     ServiceBusFifoReceiver = new DefaultFifoAzureServiceBusReceiver <TPayload>(
         configSettings.AzureServiceBusConnectionString,
         configSettings.AzureServiceBusTopic,
         configSettings.AzureServiceBusSubscription
         );
 }
        public static async Task Run([TimerTrigger("%TransactionalOutboxAgentCronSchedule%")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"Transactional Outbox Agent initiating process at: {DateTime.Now}");
            var configSettings = new SampleAppConfig();

            var azureServiceBusPublisher = new DefaultAzureServiceBusOutboxPublisher(
                configSettings.AzureServiceBusConnectionString,
                new AzureServiceBusPublishingOptions()
            {
                SenderApplicationName = $"{typeof(TransactionalOutboxAgentFunction).Assembly.GetName().Name}.{nameof(TransactionalOutboxAgentFunction)}",
                LogDebugCallback      = (s) => log.LogDebug(s),
                ErrorHandlerCallback  = (e) => log.LogError(e, "Unexpected Exception occurred while Processing the Transactional Outbox.")
            }
                );

            var outboxProcessingOptions = new OutboxProcessingOptions()
            {
                //ItemProcessingBatchSize = 200, //Only process the top X items to keep this function responsive!
                FifoEnforcedPublishingEnabled = true, //The Service Bus Topic is Session Enabled so we must processes it with FIFO Processing Enabled!
                LogDebugCallback      = (m) => log.LogDebug(m),
                ErrorHandlerCallback  = (e) => log.LogError(e, "Transactional Outbox Processing Exception"),
                MaxPublishingAttempts = configSettings.OutboxMaxPublishingRetryAttempts,
                TimeSpanToLive        = configSettings.OutboxMaxTimeToLiveTimeSpan
            };

            //************************************************************
            //*** Execute processing of the Transactional Outbox...
            //************************************************************
            await using var sqlConnection = new SqlConnection(configSettings.SqlConnectionString);
            await sqlConnection.OpenAsync().ConfigureAwait(false);

            await sqlConnection
            .ProcessPendingOutboxItemsAsync(azureServiceBusPublisher, outboxProcessingOptions)
            .ConfigureAwait(false);

            //************************************************************
            //*** Execute Cleanup of Historical Outbox Data...
            //************************************************************
            await sqlConnection
            .CleanupHistoricalOutboxItemsAsync(configSettings.OutboxHistoryToKeepTimeSpan)
            .ConfigureAwait(false);
        }
예제 #3
0
        public OutboxProcessor(SampleAppConfig configSettings)
        {
            configSettings.AssertNotNull(nameof(configSettings));

            var errorHandlerCallback = new Action <Exception>((e) =>
            {
                Console.WriteLine($"  ERROR => {e.GetMessagesRecursively()}");
                OutboxHelpers.DefaultLogErrorCallback(e);
            });

            //We Need a Publisher to publish Outbox Items...
            //  NOTE: this is AsyncDisposable so we Keep a Reference for Disposal!
            OutboxPublisher = new DefaultAzureServiceBusOutboxPublisher(
                configSettings.AzureServiceBusConnectionString,
                new AzureServiceBusPublishingOptions()
            {
                SenderApplicationName = typeof(OutboxHelpers).Assembly.GetName().Name,
                LogDebugCallback      = OutboxHelpers.DefaultLogDebugCallback,
                ErrorHandlerCallback  = errorHandlerCallback
            }
                );

            //Finally We Need the Processing Agent to process the Outbox on a background (Async) thread...
            //  NOTE: this is AsyncDisposable so we Keep a Reference for Disposal!
            OutboxProcessingAgent = new AsyncThreadOutboxProcessingAgent(
                TimeSpan.FromSeconds(20),
                TimeSpan.FromDays(1),
                configSettings.SqlConnectionString,
                OutboxPublisher,
                //We Need Processing Options for the Agent...
                outboxProcessingOptions: new OutboxProcessingOptions()
            {
                //ItemProcessingBatchSize = 200, //Only process the top X items to keep this function responsive!
                FifoEnforcedPublishingEnabled = true,     //The Service Bus Topic is Session Enabled so we must processes it with FIFO Processing Enabled!
                LogDebugCallback      = OutboxHelpers.DefaultLogDebugCallback,
                ErrorHandlerCallback  = errorHandlerCallback,
                MaxPublishingAttempts = configSettings.OutboxMaxPublishingRetryAttempts,
                TimeSpanToLive        = configSettings.OutboxMaxTimeToLiveTimeSpan
            }
                );
        }
 public OutboxSender(SampleAppConfig settings)
 {
     this.ServiceBusTopic     = settings.AzureServiceBusTopic;
     this.SqlConnectionString = settings.SqlConnectionString;
 }
예제 #5
0
 static TestConfiguration()
 {
     LocalSettingsEnvironmentReader.SetupEnvironmentFromLocalSettingsJson();
     SettingsConfig = new SampleAppConfig();
 }