└── ExemploRabbitMQ ├── Scripts ├── Scripts.jfm ├── Scripts.dbmdl ├── Scripts.sqlproj.user ├── ScriptCotacoes.sql └── Scripts.sqlproj ├── APICotacoes ├── appsettings.Development.json ├── RabbitMQConfigurations.cs ├── Cotacao.cs ├── appsettings.json ├── APICotacoes.csproj ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs └── Controllers │ └── CotacoesController.cs ├── CarregarCotacoes ├── SeleniumConfigurations.cs ├── RabbitMQConfigurations.cs ├── Cotacao.cs ├── appsettings.json ├── CarregarCotacoes.csproj ├── CotacoesDAO.cs ├── PaginaCotacoes.cs └── Program.cs └── ExemploRabbitMQ.sln /ExemploRabbitMQ/Scripts/Scripts.jfm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/renatogroffe/RabbitMQ-DotnetCore2-Selenium/HEAD/ExemploRabbitMQ/Scripts/Scripts.jfm -------------------------------------------------------------------------------- /ExemploRabbitMQ/Scripts/Scripts.dbmdl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/renatogroffe/RabbitMQ-DotnetCore2-Selenium/HEAD/ExemploRabbitMQ/Scripts/Scripts.dbmdl -------------------------------------------------------------------------------- /ExemploRabbitMQ/Scripts/Scripts.sqlproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/CarregarCotacoes/SeleniumConfigurations.cs: -------------------------------------------------------------------------------- 1 | namespace CarregarCotacoes 2 | { 3 | public class SeleniumConfigurations 4 | { 5 | public string CaminhoDriverFirefox { get; set; } 6 | public string UrlPaginaCotacoes { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/RabbitMQConfigurations.cs: -------------------------------------------------------------------------------- 1 | namespace APICotacoes 2 | { 3 | public class RabbitMQConfigurations 4 | { 5 | public string HostName { get; set; } 6 | public int Port { get; set; } 7 | public string UserName { get; set; } 8 | public string Password { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/CarregarCotacoes/RabbitMQConfigurations.cs: -------------------------------------------------------------------------------- 1 | namespace CarregarCotacoes 2 | { 3 | public class RabbitMQConfigurations 4 | { 5 | public string HostName { get; set; } 6 | public int Port { get; set; } 7 | public string UserName { get; set; } 8 | public string Password { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /ExemploRabbitMQ/Scripts/ScriptCotacoes.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE TestesRabbitMQ 2 | GO 3 | 4 | USE TestesRabbitMQ 5 | GO 6 | 7 | CREATE TABLE [dbo].[Cotacoes]( 8 | [NomeMoeda] [varchar](30) NOT NULL, 9 | [DtUltimaCarga] [datetime] NOT NULL, 10 | [ValorCompra] [numeric](18, 4) NOT NULL, 11 | [ValorVenda] [numeric](18, 4) NULL, 12 | [Variacao] [varchar](10) NOT NULL, 13 | CONSTRAINT PK_Cotacoes PRIMARY KEY([NomeMoeda]) 14 | ) ON [PRIMARY] 15 | GO 16 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/Cotacao.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dapper.Contrib.Extensions; 3 | 4 | namespace APICotacoes 5 | { 6 | [Table("dbo.Cotacoes")] 7 | public class Cotacao 8 | { 9 | [ExplicitKey] 10 | public string NomeMoeda { get; set; } 11 | public DateTime DtUltimaCarga { get; set; } 12 | public double ValorCompra { get; set; } 13 | public double ValorVenda { get; set; } 14 | public string Variacao { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /ExemploRabbitMQ/CarregarCotacoes/Cotacao.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Dapper.Contrib.Extensions; 3 | 4 | namespace CarregarCotacoes 5 | { 6 | [Table("dbo.Cotacoes")] 7 | public class Cotacao 8 | { 9 | [ExplicitKey] 10 | public string NomeMoeda { get; set; } 11 | public DateTime DtUltimaCarga { get; set; } 12 | public double ValorCompra { get; set; } 13 | public double ValorVenda { get; set; } 14 | public string Variacao { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /ExemploRabbitMQ/CarregarCotacoes/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "TestesRabbitMQ": "Data Source=.\\MSSQLSERVER2016;Initial Catalog=TestesRabbitMQ;Integrated Security=SSPI;" 4 | }, 5 | "RabbitMQConfigurations": { 6 | "HostName": "localhost", 7 | "Port": 6672, 8 | "UserName": "testes", 9 | "Password": "Testes2018!" 10 | }, 11 | "SeleniumConfigurations": { 12 | "CaminhoDriverFirefox": "C:\\Selenium\\FirefoxDriver\\", 13 | "UrlPaginaCotacoes": "https://economia.uol.com.br/cotacoes/" 14 | } 15 | } -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "TestesRabbitMQ": "Data Source=.\\MSSQLSERVER2016;Initial Catalog=TestesRabbitMQ;Integrated Security=SSPI;" 4 | }, 5 | "RabbitMQConfigurations": { 6 | "HostName": "localhost", 7 | "Port": 6672, 8 | "UserName": "testes", 9 | "Password": "Testes2018!" 10 | }, 11 | "Logging": { 12 | "IncludeScopes": false, 13 | "Debug": { 14 | "LogLevel": { 15 | "Default": "Warning" 16 | } 17 | }, 18 | "Console": { 19 | "LogLevel": { 20 | "Default": "Warning" 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/APICotacoes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/CarregarCotacoes/CarregarCotacoes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace APICotacoes 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/CarregarCotacoes/CotacoesDAO.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Data.SqlClient; 3 | using Dapper; 4 | using Dapper.Contrib.Extensions; 5 | 6 | namespace CarregarCotacoes 7 | { 8 | public class CotacoesDAO 9 | { 10 | private string _strConnection; 11 | 12 | public CotacoesDAO(string stringConnection) 13 | { 14 | _strConnection = stringConnection; 15 | } 16 | 17 | public void CarregarDados(List cotacoes) 18 | { 19 | using (SqlConnection conexao = 20 | new SqlConnection(_strConnection)) 21 | { 22 | conexao.Execute("TRUNCATE TABLE dbo.Cotacoes"); 23 | conexao.Insert(cotacoes); 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:61892/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "launchUrl": "api/cotacoes", 15 | "environmentVariables": { 16 | "ASPNETCORE_ENVIRONMENT": "Development" 17 | } 18 | }, 19 | "APICotacoes": { 20 | "commandName": "Project", 21 | "launchBrowser": true, 22 | "launchUrl": "api/cotacoes", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "http://localhost:61893/" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Options; 11 | 12 | namespace APICotacoes 13 | { 14 | public class Startup 15 | { 16 | public Startup(IConfiguration configuration) 17 | { 18 | Configuration = configuration; 19 | } 20 | 21 | public IConfiguration Configuration { get; } 22 | 23 | public void ConfigureServices(IServiceCollection services) 24 | { 25 | // Para este exemplo foi criado um container Docker baseado 26 | // em uma imagem do RabbitMQ. Segue o comando para geração 27 | // desta estrutura: 28 | // docker run -d --hostname rabbit-local --name testes-rabbitmq -p 6672:5672 -p 15672:15672 -e RABBITMQ_DEFAULT_USER=testes -e RABBITMQ_DEFAULT_PASS=Testes2018! rabbitmq:3-management-alpine 29 | var rabbitMQConfigurations = new RabbitMQConfigurations(); 30 | new ConfigureFromConfigurationOptions( 31 | Configuration.GetSection("RabbitMQConfigurations")) 32 | .Configure(rabbitMQConfigurations); 33 | services.AddSingleton(rabbitMQConfigurations); 34 | 35 | services.AddMvc(); 36 | } 37 | 38 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 39 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 40 | { 41 | if (env.IsDevelopment()) 42 | { 43 | app.UseDeveloperExceptionPage(); 44 | } 45 | 46 | app.UseMvc(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/ExemploRabbitMQ.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2020 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarregarCotacoes", "CarregarCotacoes\CarregarCotacoes.csproj", "{B7F37D67-DA6F-4D0C-8A08-046DBECC48C4}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APICotacoes", "APICotacoes\APICotacoes.csproj", "{DE2F1F8C-2912-40F0-B9D7-AE4CB019009E}" 9 | EndProject 10 | Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "Scripts", "Scripts\Scripts.sqlproj", "{5B1A23B6-C1F8-41B1-B6B3-A63EFF99EDB1}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {B7F37D67-DA6F-4D0C-8A08-046DBECC48C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {B7F37D67-DA6F-4D0C-8A08-046DBECC48C4}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {B7F37D67-DA6F-4D0C-8A08-046DBECC48C4}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {B7F37D67-DA6F-4D0C-8A08-046DBECC48C4}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {DE2F1F8C-2912-40F0-B9D7-AE4CB019009E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {DE2F1F8C-2912-40F0-B9D7-AE4CB019009E}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {DE2F1F8C-2912-40F0-B9D7-AE4CB019009E}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {DE2F1F8C-2912-40F0-B9D7-AE4CB019009E}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {5B1A23B6-C1F8-41B1-B6B3-A63EFF99EDB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {5B1A23B6-C1F8-41B1-B6B3-A63EFF99EDB1}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {5B1A23B6-C1F8-41B1-B6B3-A63EFF99EDB1}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 29 | {5B1A23B6-C1F8-41B1-B6B3-A63EFF99EDB1}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {5B1A23B6-C1F8-41B1-B6B3-A63EFF99EDB1}.Release|Any CPU.Build.0 = Release|Any CPU 31 | {5B1A23B6-C1F8-41B1-B6B3-A63EFF99EDB1}.Release|Any CPU.Deploy.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(ExtensibilityGlobals) = postSolution 37 | SolutionGuid = {03C49966-AB25-4A43-B61B-C0D2277AB01F} 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/APICotacoes/Controllers/CotacoesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.SqlClient; 4 | using System.Text; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.Extensions.Configuration; 7 | using Dapper.Contrib.Extensions; 8 | using RabbitMQ.Client; 9 | 10 | namespace APICotacoes.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | public class CotacoesController : Controller 14 | { 15 | [HttpGet] 16 | public IEnumerable GetCotacoes( 17 | [FromServices]IConfiguration configuration) 18 | { 19 | using (SqlConnection conexao = new SqlConnection( 20 | configuration.GetConnectionString("TestesRabbitMQ"))) 21 | { 22 | return conexao.GetAll(); 23 | } 24 | } 25 | 26 | [HttpGet("carregar")] 27 | public object CarregarCotacoes( 28 | [FromServices]RabbitMQConfigurations rabbitMQConfigurations) 29 | { 30 | var factory = new ConnectionFactory() 31 | { 32 | HostName = rabbitMQConfigurations.HostName, 33 | Port = rabbitMQConfigurations.Port, 34 | UserName = rabbitMQConfigurations.UserName, 35 | Password = rabbitMQConfigurations.Password 36 | }; 37 | 38 | using (var connection = factory.CreateConnection()) 39 | using (var channel = connection.CreateModel()) 40 | { 41 | channel.QueueDeclare(queue: "CarregarCotacoes", 42 | durable: false, 43 | exclusive: false, 44 | autoDelete: false, 45 | arguments: null); 46 | 47 | string message = "Solicitação de Carga - " + 48 | $"API Cotacoes - {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}"; 49 | var body = Encoding.UTF8.GetBytes(message); 50 | 51 | channel.BasicPublish(exchange: "", 52 | routingKey: "CarregarCotacoes", 53 | basicProperties: null, 54 | body: body); 55 | } 56 | 57 | return new 58 | { 59 | Resultado = "Mensagem encaminhada com sucesso" 60 | }; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /ExemploRabbitMQ/CarregarCotacoes/PaginaCotacoes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Microsoft.Extensions.Configuration; 5 | using OpenQA.Selenium; 6 | using OpenQA.Selenium.Firefox; 7 | 8 | namespace CarregarCotacoes 9 | { 10 | public class PaginaCotacoes 11 | { 12 | private SeleniumConfigurations _configurations; 13 | private IWebDriver _driver; 14 | 15 | public PaginaCotacoes(SeleniumConfigurations seleniumConfigurations) 16 | { 17 | _configurations = seleniumConfigurations; 18 | 19 | FirefoxOptions optionsFF = new FirefoxOptions(); 20 | optionsFF.AddArgument("--headless"); 21 | 22 | _driver = new FirefoxDriver( 23 | _configurations.CaminhoDriverFirefox 24 | , optionsFF); 25 | } 26 | 27 | public void CarregarPagina() 28 | { 29 | _driver.Manage().Timeouts().PageLoad = 30 | TimeSpan.FromSeconds(30); 31 | _driver.Navigate().GoToUrl( 32 | _configurations.UrlPaginaCotacoes); 33 | } 34 | 35 | public List ObterCotacoes() 36 | { 37 | List cotacoes = new List(); 38 | var tableCotacoes = _driver.FindElement( 39 | By.ClassName("quatro-colunas")); 40 | var rowsCotacoes = tableCotacoes.FindElement(By.TagName("tbody")) 41 | .FindElements(By.TagName("tr")); 42 | foreach (var rowCotacao in rowsCotacoes) 43 | { 44 | var dadosCotacao = 45 | rowCotacao.FindElements(By.TagName("td")); 46 | 47 | Cotacao cotacao = new Cotacao(); 48 | cotacao.NomeMoeda = 49 | dadosCotacao[0].FindElement( 50 | By.TagName("a")).GetAttribute("innerHTML"); 51 | cotacao.DtUltimaCarga = DateTime.Now; 52 | cotacao.ValorCompra = Convert.ToDouble( 53 | dadosCotacao[1].GetAttribute("innerHTML")); 54 | cotacao.ValorVenda = Convert.ToDouble( 55 | dadosCotacao[2].GetAttribute("innerHTML")); 56 | cotacao.Variacao = 57 | dadosCotacao[3].FindElement(By.TagName("span")).Text; 58 | 59 | cotacoes.Add(cotacao); 60 | } 61 | 62 | return cotacoes; 63 | } 64 | 65 | public void Fechar() 66 | { 67 | _driver.Quit(); 68 | _driver = null; 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /ExemploRabbitMQ/Scripts/Scripts.sqlproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | Scripts 8 | 2.0 9 | 4.1 10 | {5b1a23b6-c1f8-41b1-b6b3-a63eff99edb1} 11 | Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider 12 | Database 13 | 14 | 15 | Scripts 16 | Scripts 17 | 1033, CI 18 | BySchemaAndSchemaType 19 | True 20 | v4.7 21 | CS 22 | Properties 23 | False 24 | True 25 | True 26 | 27 | 28 | bin\Release\ 29 | $(MSBuildProjectName).sql 30 | False 31 | pdbonly 32 | true 33 | false 34 | true 35 | prompt 36 | 4 37 | 38 | 39 | bin\Debug\ 40 | $(MSBuildProjectName).sql 41 | false 42 | true 43 | full 44 | false 45 | true 46 | true 47 | prompt 48 | 4 49 | 50 | 51 | 11.0 52 | 53 | True 54 | 11.0 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /ExemploRabbitMQ/CarregarCotacoes/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.Options; 7 | using RabbitMQ.Client; 8 | using RabbitMQ.Client.Events; 9 | 10 | namespace CarregarCotacoes 11 | { 12 | class Program 13 | { 14 | private static IConfiguration _configuration; 15 | private static SeleniumConfigurations _seleniumConfigurations; 16 | 17 | static void Main(string[] args) 18 | { 19 | var builder = new ConfigurationBuilder() 20 | .SetBasePath(Directory.GetCurrentDirectory()) 21 | .AddJsonFile($"appsettings.json"); 22 | _configuration = builder.Build(); 23 | 24 | // Para este exemplo foi criado um container Docker baseado 25 | // em uma imagem do RabbitMQ. Segue o comando para geração 26 | // desta estrutura: 27 | // docker run -d --hostname rabbit-local --name testes-rabbitmq -p 6672:5672 -p 15672:15672 -e RABBITMQ_DEFAULT_USER=testes -e RABBITMQ_DEFAULT_PASS=Testes2018! rabbitmq:3-management-alpine 28 | var rabbitMQConfigurations = new RabbitMQConfigurations(); 29 | new ConfigureFromConfigurationOptions( 30 | _configuration.GetSection("RabbitMQConfigurations")) 31 | .Configure(rabbitMQConfigurations); 32 | 33 | _seleniumConfigurations = new SeleniumConfigurations(); 34 | new ConfigureFromConfigurationOptions( 35 | _configuration.GetSection("SeleniumConfigurations")) 36 | .Configure(_seleniumConfigurations); 37 | 38 | var factory = new ConnectionFactory() 39 | { 40 | HostName = rabbitMQConfigurations.HostName, 41 | Port = rabbitMQConfigurations.Port, 42 | UserName = rabbitMQConfigurations.UserName, 43 | Password = rabbitMQConfigurations.Password 44 | }; 45 | 46 | using (var connection = factory.CreateConnection()) 47 | using (var channel = connection.CreateModel()) 48 | { 49 | channel.QueueDeclare(queue: "CarregarCotacoes", 50 | durable: false, 51 | exclusive: false, 52 | autoDelete: false, 53 | arguments: null); 54 | 55 | var consumer = new EventingBasicConsumer(channel); 56 | consumer.Received += Consumer_Received; 57 | channel.BasicConsume(queue: "CarregarCotacoes", 58 | autoAck: true, 59 | consumer: consumer); 60 | 61 | Console.WriteLine("Aguardando mensagens para processamento"); 62 | Console.WriteLine("Pressione uma tecla para encerrar..."); 63 | Console.ReadKey(); 64 | } 65 | } 66 | 67 | private static void Consumer_Received( 68 | object sender, BasicDeliverEventArgs e) 69 | { 70 | var message = Encoding.UTF8.GetString(e.Body); 71 | Console.WriteLine(Environment.NewLine + 72 | "[Nova mensagem recebida] " + message); 73 | 74 | List cotacoes; 75 | PaginaCotacoes pagina = 76 | new PaginaCotacoes(_seleniumConfigurations); 77 | try 78 | { 79 | Console.WriteLine("Iniciando extração dos dados..."); 80 | pagina.CarregarPagina(); 81 | cotacoes = pagina.ObterCotacoes(); 82 | Console.WriteLine("Dados extraídos com sucesso!"); 83 | 84 | new CotacoesDAO(_configuration.GetConnectionString("TestesRabbitMQ")) 85 | .CarregarDados(cotacoes); 86 | Console.WriteLine("Carga dos dados efetuada com sucesso!"); 87 | } 88 | finally 89 | { 90 | pagina.Fechar(); 91 | } 92 | } 93 | } 94 | } --------------------------------------------------------------------------------