コード例 #1
0
        public static async Task Main(string[] args)
        {
            //
            //	get configuration information
            //
            MessageQueueAppConfig messageQueueAppConfig = new MessageQueueAppConfig();
            ConnectionStrings     connectionStrings     = new ConnectionStrings();

            string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
            string jsonFile    = $"appsettings.{environment}.json";

            var configBuilder = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile(jsonFile, optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = configBuilder.Build();

            configuration.GetSection("MessageQueueAppConfig").Bind(messageQueueAppConfig);
            configuration.GetSection("ConnectionStrings").Bind(connectionStrings);
            //
            //	set up sending queue
            //
            IMessageQueueConnection sendingQueueConnection = new MessageQueueConnection(messageQueueAppConfig);

            sendingQueueConnection.CreateConnection();

            List <IMessageQueueConfiguration> messageQueueConfigurations = new List <IMessageQueueConfiguration>();
            //
            //	Inventory Received Transactions
            //
            IMessageQueueConfiguration inventoryReceivedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.InventoryReceived, messageQueueAppConfig, sendingQueueConnection);

            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.PurchaseOrderQueue);
            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            inventoryReceivedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(inventoryReceivedConfiguration);
            //
            //	Product Creation and Updates
            //
            IMessageQueueConfiguration productUpdatedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.ProductUpdated, messageQueueAppConfig, sendingQueueConnection);

            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.PurchaseOrderQueue);
            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            productUpdatedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(productUpdatedConfiguration);
            //
            //	Inventory Shipped Transactions
            //
            IMessageQueueConfiguration inventoryShippedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.InventoryShipped, messageQueueAppConfig, sendingQueueConnection);

            inventoryShippedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            inventoryShippedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            inventoryShippedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(inventoryShippedConfiguration);

            //
            //	initialize Sending Messages
            //
            IInventoryManagementDataService inventoryManagementDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         messageProcessing = new MessageProcessing(inventoryManagementDataService);

            IHostedService sendInventoryManagementMessages = new SendMessages(sendingQueueConnection, messageProcessing,
                                                                              messageQueueAppConfig, connectionStrings, messageQueueConfigurations, MessageQueueEndpoints.InventoryQueue);
            //
            //	set up receiving queue
            //
            IMessageQueueConnection receivingConnection = new MessageQueueConnection(messageQueueAppConfig);

            receivingConnection.CreateConnection();

            List <IMessageQueueConfiguration> inboundMessageQueueConfigurations = new List <IMessageQueueConfiguration>();
            IMessageQueueConfiguration        inboundConfiguration = new MessageQueueConfiguration(messageQueueAppConfig, receivingConnection);

            inboundMessageQueueConfigurations.Add(inboundConfiguration);

            inboundConfiguration.InitializeInboundMessageQueueing(MessageQueueEndpoints.InventoryQueue);
            inboundConfiguration.InitializeLoggingExchange(MessageQueueExchanges.Logging, MessageQueueEndpoints.LoggingQueue);
            IInventoryManagementDataService inboundInventoryManagementDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         inboundMessageProcessing = new MessageProcessing(inboundInventoryManagementDataService);

            IHostedService receiveInventoryManagementMessages = new ReceiveMessages(receivingConnection, inboundMessageProcessing, messageQueueAppConfig, connectionStrings, inboundMessageQueueConfigurations);
            //
            //	Set Up Message Processing
            //
            IInventoryManagementDataService inventoryManagementProcessingDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         messageProcessor = new MessageProcessing(inventoryManagementProcessingDataService);
            ProcessMessages processMessages = new ProcessMessages(messageProcessor, messageQueueAppConfig, connectionStrings);

            var builder = new HostBuilder().ConfigureAppConfiguration((hostingContext, config) => {})
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddTransient <IHostedService>(provider => processMessages);
            })
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddTransient <IHostedService>(provider => sendInventoryManagementMessages);
            })
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddTransient <IHostedService>(provider => receiveInventoryManagementMessages);
            })
                          .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
            });

            await builder.RunConsoleAsync();
        }
コード例 #2
0
        public void Startup()
        {
            //
            //	get configuration information
            //

            MessageQueueAppConfig messageQueueAppConfig = new MessageQueueAppConfig();
            ConnectionStrings     connectionStrings     = new ConnectionStrings();

            var basePath = PlatformServices.Default.Application.ApplicationBasePath;

            if (basePath.ToLower().Contains("inventorymanagementqa"))
            {
                CodeProject.Shared.Common.Models.AppSettings.MessageQueueAppSettings appSettings = new CodeProject.Shared.Common.Models.AppSettings.MessageQueueAppSettings();

                string readContents;
                using (StreamReader streamReader = new StreamReader(basePath + @"\AppSettings.QA.json", Encoding.UTF8))
                {
                    readContents = streamReader.ReadToEnd();
                }

                appSettings = CodeProject.Shared.Common.Utilities.SerializationFunction <CodeProject.Shared.Common.Models.AppSettings.MessageQueueAppSettings> .ReturnObjectFromString(readContents);

                messageQueueAppConfig.MessageQueueHostName    = appSettings.MessageQueueAppConfig.MessageQueueHostName;
                messageQueueAppConfig.MessageQueueUserName    = appSettings.MessageQueueAppConfig.MessageQueueUserName;
                messageQueueAppConfig.MessageQueuePassword    = appSettings.MessageQueueAppConfig.MessageQueuePassword;
                messageQueueAppConfig.MessageQueueEnvironment = appSettings.MessageQueueAppConfig.MessageQueueEnvironment;
                messageQueueAppConfig.ExchangeName            = appSettings.MessageQueueAppConfig.ExchangeName;
                messageQueueAppConfig.RoutingKey            = appSettings.MessageQueueAppConfig.RoutingKey;
                messageQueueAppConfig.InboundMessageQueue   = appSettings.MessageQueueAppConfig.InboundMessageQueue;
                messageQueueAppConfig.OutboundMessageQueues = appSettings.MessageQueueAppConfig.OutboundMessageQueues;
                messageQueueAppConfig.LoggingExchangeName   = appSettings.MessageQueueAppConfig.LoggingExchangeName;
                messageQueueAppConfig.LoggingMessageQueue   = appSettings.MessageQueueAppConfig.LoggingMessageQueue;
                messageQueueAppConfig.OriginatingQueueName  = appSettings.MessageQueueAppConfig.OriginatingQueueName;
                messageQueueAppConfig.SendToLoggingQueue    = appSettings.MessageQueueAppConfig.SendToLoggingQueue;
                messageQueueAppConfig.AcknowledgementMessageExchangeSuffix = appSettings.MessageQueueAppConfig.AcknowledgementMessageExchangeSuffix;
                messageQueueAppConfig.AcknowledgementMessageQueueSuffix    = appSettings.MessageQueueAppConfig.AcknowledgementMessageQueueSuffix;
                messageQueueAppConfig.TriggerExchangeName       = appSettings.MessageQueueAppConfig.TriggerExchangeName;
                messageQueueAppConfig.TriggerQueueName          = appSettings.MessageQueueAppConfig.TriggerQueueName;
                messageQueueAppConfig.QueueImmediately          = appSettings.MessageQueueAppConfig.QueueImmediately;
                messageQueueAppConfig.InboundSemaphoreKey       = appSettings.MessageQueueAppConfig.InboundSemaphoreKey;
                messageQueueAppConfig.OutboundSemaphoreKey      = appSettings.MessageQueueAppConfig.OutboundSemaphoreKey;
                messageQueueAppConfig.ProcessingIntervalSeconds = appSettings.MessageQueueAppConfig.ProcessingIntervalSeconds;
                messageQueueAppConfig.SendingIntervalSeconds    = appSettings.MessageQueueAppConfig.SendingIntervalSeconds;
                messageQueueAppConfig.ReceivingIntervalSeconds  = appSettings.MessageQueueAppConfig.ReceivingIntervalSeconds;
                messageQueueAppConfig.SignalRHubUrl             = appSettings.MessageQueueAppConfig.SignalRHubUrl;
                messageQueueAppConfig.RunAsService = appSettings.MessageQueueAppConfig.RunAsService;

                connectionStrings.PrimaryDatabaseConnectionString = appSettings.ConnectionStrings.PrimaryDatabaseConnectionString;

                using (var sw = File.AppendText(Path))
                {
                    sw.WriteLine("HostName=" + messageQueueAppConfig.MessageQueueHostName + "*");
                }
            }
            else
            {
                string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
                string jsonFile    = $"AppSettings.{environment}.json";

                var configBuilder = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddJsonFile(jsonFile, optional: true, reloadOnChange: true);

                IConfigurationRoot configuration = configBuilder.Build();

                configuration.GetSection("MessageQueueAppConfig").Bind(messageQueueAppConfig);
                configuration.GetSection("ConnectionStrings").Bind(connectionStrings);
            }

            //
            //	set up sending queue
            //

            IMessageQueueConnection sendingQueueConnection = new MessageQueueConnection(messageQueueAppConfig);

            sendingQueueConnection.CreateConnection();

            List <IMessageQueueConfiguration> messageQueueConfigurations = new List <IMessageQueueConfiguration>();

            //
            //	Inventory Received Transactions
            //

            IMessageQueueConfiguration inventoryReceivedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.InventoryReceived, messageQueueAppConfig, sendingQueueConnection);

            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.PurchaseOrderQueue);
            inventoryReceivedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            inventoryReceivedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(inventoryReceivedConfiguration);

            //
            //	Product Creation and Updates
            //

            IMessageQueueConfiguration productUpdatedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.ProductUpdated, messageQueueAppConfig, sendingQueueConnection);

            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.PurchaseOrderQueue);
            productUpdatedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            productUpdatedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(productUpdatedConfiguration);

            //
            //	Inventory Shipped Transactions
            //

            IMessageQueueConfiguration inventoryShippedConfiguration = new MessageQueueConfiguration(MessageQueueExchanges.InventoryShipped, messageQueueAppConfig, sendingQueueConnection);

            inventoryShippedConfiguration.AddQueue(MessageQueueEndpoints.SalesOrderQueue);
            inventoryShippedConfiguration.AddQueue(MessageQueueEndpoints.LoggingQueue);

            inventoryShippedConfiguration.InitializeOutboundMessageQueueing();
            messageQueueConfigurations.Add(inventoryShippedConfiguration);

            //
            //	initialize Sending Messages
            //

            IInventoryManagementDataService inventoryManagementDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         messageProcessing = new MessageProcessing(inventoryManagementDataService);

            _sendInventoryManagementMessages = new SendMessages(sendingQueueConnection, messageProcessing,
                                                                messageQueueAppConfig, connectionStrings, messageQueueConfigurations, MessageQueueEndpoints.InventoryQueue);

            //
            //	set up receiving queue
            //

            IMessageQueueConnection receivingConnection = new MessageQueueConnection(messageQueueAppConfig);

            receivingConnection.CreateConnection();

            List <IMessageQueueConfiguration> inboundMessageQueueConfigurations = new List <IMessageQueueConfiguration>();
            IMessageQueueConfiguration        inboundConfiguration = new MessageQueueConfiguration(messageQueueAppConfig, receivingConnection);

            inboundMessageQueueConfigurations.Add(inboundConfiguration);

            inboundConfiguration.InitializeInboundMessageQueueing(MessageQueueEndpoints.InventoryQueue);
            inboundConfiguration.InitializeLoggingExchange(MessageQueueExchanges.Logging, MessageQueueEndpoints.LoggingQueue);
            IInventoryManagementDataService inboundInventoryManagementDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         inboundMessageProcessing = new MessageProcessing(inboundInventoryManagementDataService);

            _receiveInventoryManagementMessages = new ReceiveMessages(receivingConnection, inboundMessageProcessing, messageQueueAppConfig, connectionStrings, inboundMessageQueueConfigurations);

            //
            //	Set Up Message Processing
            //

            IInventoryManagementDataService inventoryManagementProcessingDataService = new InventoryManagementDataService();
            IMessageQueueProcessing         messageProcessor = new MessageProcessing(inventoryManagementProcessingDataService);

            _processMessages = new ProcessMessages(messageProcessor, messageQueueAppConfig, connectionStrings);
        }