public ReplyMessageService(IRabbitService rabbitService) { _channel = rabbitService.GetChannel(); replyQueueName = rabbitService.GetReplyQueueName(); _channel.QueueDeclare(replyQueueName, false, false, false, null); consumer = new EventingBasicConsumer(_channel); consumer.Received += (model, ea) => { var body = ea.Body; var message = Encoding.UTF8.GetString(body); var tab = message.Split("."); observerHandler.SetObserver(tab[0], tab[1]); }; _channel.BasicConsume(replyQueueName, true, consumer); observerHandler = new ReplyObserverHandler(); Console.WriteLine("Created replies handler"); }
public EmailWorkerService( IConfiguration config, ISerializationProvider serializationProvider, IRabbitService rabbitService, ILogger <EmailWorkerService> logger = null) { Guard.AgainstNull(config, nameof(config)); Guard.AgainstNull(rabbitService, nameof(rabbitService)); Guard.AgainstNull(serializationProvider, nameof(serializationProvider)); _config = config; _serializationProvider = serializationProvider; _rabbitService = rabbitService; _logger = logger; var mailKitOptions = new MailKitOptions { // Use Papercut Smtp for local testing! // https://github.com/ChangemakerStudios/Papercut-SMTP/releases Server = _config.GetValue <string>("HouseofCat:EmailService:SmtpHost"), Port = _config.GetValue <int>("HouseofCat:EmailService:SmtpPort"), SenderName = _config.GetValue <string>("HouseofCat:EmailService:SenderName"), SenderEmail = _config.GetValue <string>("HouseofCat:EmailService:SenderEmail"), //Account = Configuration.GetValue<string>("Email:Account"), //Password = Configuration.GetValue<string>("Email:Password"), //Security = Configuration.GetValue<bool>("Email:EnableTls") }; var provider = new MailKitProvider(mailKitOptions); _emailService = new EmailService(provider); }
public RestoreHandler(ILogFactory logFactory, IRabbitService rabbitService) { // TODO: Sometimes, it is enough to hardcode the period right here, but sometimes it's better to move it to the settings. // Choose the simplest and sufficient solution _timerTrigger = new TimerTrigger(nameof(RestoreHandler), TimeSpan.FromSeconds(10), logFactory); _timerTrigger.Triggered += Execute; }
public Worker(ILogger <Worker> logger, IConnection connection, ICarService carService, IRabbitService rabbitService) { _logger = logger; _connection = connection; _carService = carService; _rabbitService = rabbitService; }
public TextMessageWorkerService( IConfiguration config, IRabbitService rabbitService, ISerializationProvider serializationProvider, ILogger <TextMessageWorkerService> logger = null) { Guard.AgainstNull(config, nameof(config)); Guard.AgainstNull(rabbitService, nameof(rabbitService)); Guard.AgainstNull(rabbitService, nameof(rabbitService)); Guard.AgainstNull(serializationProvider, nameof(serializationProvider)); _logger = logger; _config = config; _rabbitService = rabbitService; _serializationProvider = serializationProvider; _consumerName = _config.GetSection("HouseofCat:NotificationService:ConsumerName").Get <string>(); _options = _rabbitService.Options.GetConsumerOptions(_consumerName); _from = _config.GetSection("HouseofCat:NotificationService:From").Get <string>(); _account = _config.GetSection("HouseofCat:NotificationService:Account").Get <string>(); _token = _config.GetSection("HouseofCat:NotificationService:Token").Get <string>(); TwilioClient.Init(_account, _token); }
public ConsumerDataflow( IRabbitService rabbitService, string workflowName, string consumerName, int consumerCount) { Guard.AgainstNull(rabbitService, nameof(rabbitService)); Guard.AgainstNullOrEmpty(consumerName, nameof(consumerName)); WorkflowName = workflowName; _consumerCount = consumerCount; _consumerName = consumerName; _logger = LogHelper.LoggerFactory.CreateLogger <ConsumerDataflow <TState> >(); _rabbitService = rabbitService; _consumerOptions = rabbitService.GetConsumer(consumerName).ConsumerOptions; _linkStepOptions = new DataflowLinkOptions { PropagateCompletion = true }; _executeStepOptions = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = _consumerOptions.ConsumerPipelineOptions.MaxDegreesOfParallelism ?? 1, SingleProducerConstrained = true, EnsureOrdered = _consumerOptions.ConsumerPipelineOptions.EnsureOrdered ?? true }; _consumerBlocks = new List <ConsumerBlock <ReceivedData> >(); }
public ConsumerDataflow( IRabbitService rabbitService, string workflowName, string consumerName, int consumerCount, TaskScheduler taskScheduler = null) { Guard.AgainstNull(rabbitService, nameof(rabbitService)); Guard.AgainstNullOrEmpty(consumerName, nameof(consumerName)); WorkflowName = workflowName; _consumerCount = consumerCount; _consumerName = consumerName; _rabbitService = rabbitService; _consumerOptions = rabbitService.Options.GetConsumerOptions(consumerName); _serializationProvider = rabbitService.SerializationProvider; _linkStepOptions = new DataflowLinkOptions { PropagateCompletion = true }; _taskScheduler = taskScheduler ?? TaskScheduler.Current; _executeStepOptions = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = _consumerOptions.ConsumerPipelineOptions.MaxDegreesOfParallelism ?? 1, SingleProducerConstrained = true, EnsureOrdered = _consumerOptions.ConsumerPipelineOptions.EnsureOrdered ?? true, TaskScheduler = _taskScheduler, }; _consumerBlocks = new List <ConsumerBlock <ReceivedData> >(); }
/// <summary> /// This constructor is used for when you want to supply Consumers manually, or custom Consumers without having to write a custom IRabbitService, /// and want a custom maxDoP and/or ensureOrdered. /// </summary> /// <param name="rabbitService"></param> /// <param name="workflowName"></param> /// <param name="consumers"></param> /// <param name="maxDoP"></param> /// <param name="ensureOrdered"></param> /// <param name="taskScheduler"></param> public ConsumerDataflow( IRabbitService rabbitService, string workflowName, ICollection <IConsumer <ReceivedData> > consumers, int maxDoP, bool ensureOrdered, TaskScheduler taskScheduler = null) { Guard.AgainstNull(rabbitService, nameof(rabbitService)); Guard.AgainstNullOrEmpty(consumers, nameof(consumers)); WorkflowName = workflowName; _consumers = consumers; _rabbitService = rabbitService; _serializationProvider = rabbitService.SerializationProvider; _linkStepOptions = new DataflowLinkOptions { PropagateCompletion = true }; _taskScheduler = taskScheduler ?? TaskScheduler.Current; _executeStepOptions = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = maxDoP, SingleProducerConstrained = true, EnsureOrdered = ensureOrdered, TaskScheduler = _taskScheduler, }; _consumerBlocks = new List <ConsumerBlock <ReceivedData> >(); }
private static async Task SetupAsync() { var letterTemplate = new Letter("", "TestRabbitServiceQueue", null, new LetterMetadata()); var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel)); _logger = loggerFactory.CreateLogger <ConsumerDataflow <WorkState> >(); _hashingProvider = new Argon2ID_HashingProvider(); var hashKey = await _hashingProvider.GetHashKeyAsync("passwordforencryption", "saltforencryption", 32).ConfigureAwait(false); _metricsProvider = new NullMetricsProvider(); _encryptionProvider = new AesGcmEncryptionProvider(hashKey); _compressionProvider = new LZ4PickleProvider(); _serializationProvider = new Utf8JsonProvider(); _rabbitService = new RabbitService( "Config.json", _serializationProvider, _encryptionProvider, _compressionProvider, loggerFactory); await _rabbitService .Topologer .CreateQueueAsync("TestRabbitServiceQueue") .ConfigureAwait(false); }
public ConsumerTests(ITestOutputHelper output) { this.output = output; config = ConfigReader.ConfigFileReadAsync("TestConfig.json").GetAwaiter().GetResult(); channelPool = new ChannelPool(config); topologer = new Topologer(config); rabbitService = new RabbitService("Config.json", null, null, null, null); }
public ConsumerTests(ITestOutputHelper output) { this.output = output; options = JsonFileReader.ReadFileAsync <Options>("TestConfig.json").GetAwaiter().GetResult(); channelPool = new ChannelPool(options); topologer = new Topologer(options); rabbitService = new RabbitService("Config.json", null, null, null, null); }
public StartupManager( ILogFactory logFactory, IRabbitService rabbitService, RabbitMqSettings rabbitMqSettings) { _logFactory = logFactory; _log = logFactory.CreateLog(this); _rabbitService = rabbitService; _rabbitMqSettings = rabbitMqSettings; }
private void PreparePublisher(IRabbitService publisher, RabbitConfig config) { try { publisher.InitializePublisher(PublisherName, config); _logger.LogInformation("connection established successfully"); } catch (Exception e) { _logger.LogError(e, "can't connect to rabbit"); throw; } }
/// <summary> /// This constructor is used for when you want to supply Consumers manually, or custom Consumers without having to write a custom IRabbitService, /// and have global consumer pipeline options to retrieve maxDoP and ensureOrdered from. /// </summary> /// <param name="rabbitService"></param> /// <param name="workflowName"></param> /// <param name="consumers"></param> /// <param name="globalConsumerPipelineOptions"></param> /// <param name="taskScheduler"></param> public ConsumerDataflow( IRabbitService rabbitService, string workflowName, ICollection <IConsumer <ReceivedData> > consumers, GlobalConsumerPipelineOptions globalConsumerPipelineOptions, TaskScheduler taskScheduler = null) : this( rabbitService, workflowName, consumers, globalConsumerPipelineOptions?.MaxDegreesOfParallelism ?? 1, globalConsumerPipelineOptions?.EnsureOrdered ?? true, taskScheduler) { Guard.AgainstNull(globalConsumerPipelineOptions, nameof(globalConsumerPipelineOptions)); }
public RabbitHostedService(ILogger log, IDispatchEvent eventDispatcher, RabbitServiceConfiguration serviceConfiguration) { _log = log; _serviceConfiguration = serviceConfiguration; _log.Debug("Connecting to RabbitMQ on {rabbitUri}", serviceConfiguration.Uri); _connection = new ConnectionFactory() { Uri = new Uri(_serviceConfiguration.Uri), AutomaticRecoveryEnabled = true, }.CreateConnection(); _internal = new RabbitService(log.ForContext <RabbitService>(), _connection, eventDispatcher, _serviceConfiguration.Publisher.Exchange); }
public MessageService(IRabbitService rabbitService) { _channel = rabbitService.GetChannel(); replyQueueName = rabbitService.GetReplyQueueName(); _channel.QueueDeclare(replyQueueName, false, false, false, null); props = _channel.CreateBasicProperties(); props.ReplyTo = replyQueueName; Console.WriteLine("Created messages handler"); }
public ConsumerDataflowService( IConfiguration config, ILoggerFactory logger, IRabbitService rabbitService, ISerializationProvider serializationProvider, ICompressionProvider compressionProvider, IEncryptionProvider encryptionProvider, IMetricsProvider metricsProvider) { _config = config; _logger = logger.CreateLogger <ConsumerDataflowService>(); _rabbitService = rabbitService; _serializationProvider = serializationProvider; _compressionProvider = compressionProvider; _encryptionProvider = encryptionProvider; _metricsProvider = metricsProvider; }
public TestMessageService( ILogger <TestMessageService> logger, IConfiguration config, IRabbitService rabbitService) { _logger = logger; _config = config; _rabbitService = rabbitService; _consumerName = _config.GetSection("HouseofCat:NotificationService:ConsumerName").Get <string>(); _options = _rabbitService.Options.GetConsumerOptions(_consumerName); _from = _config.GetSection("HouseofCat:NotificationService:From").Get <string>(); _account = _config.GetSection("HouseofCat:NotificationService:Account").Get <string>(); _token = _config.GetSection("HouseofCat:NotificationService:Token").Get <string>(); TwilioClient.Init(_account, _token); }
public RestoreRabbitSubscriber( ILogFactory logFactory, IRabbitService rabbitService, string connectionString, string exchangeName) { _logFactory = logFactory; _rabbitService = rabbitService; _connectionString = connectionString; _exchangeName = exchangeName; _messageSerializer = new JsonMessageSerializer <string>(); _retryPolicy = RetryPolicy .Handle <Exception>() .WaitAndRetryAsync(10, (i) => { int baseMs = 100; var exponentialWaitMs = baseMs * Math.Pow(2, i); return(TimeSpan.FromMilliseconds(exponentialWaitMs)); }); }
protected override Task ExecuteAsync(CancellationToken stoppingToken) { stoppingToken.ThrowIfCancellationRequested(); var consumer = new EventingBasicConsumer(_channel); consumer.Received += (ch, ea) => { //convert bytes to string string payload = Encoding.UTF8.GetString(ea.Body.ToArray()); Console.Write("=== Rabbit revieved Event ==="); // received message try { using (var serviceScope = _scopeFactory.CreateScope()) { _rabbitService = serviceScope.ServiceProvider.GetRequiredService <IRabbitService>(); var content = JsonConvert.DeserializeObject <EventContent>(payload); // handle the received message _rabbitService.Recieve(content.pattern, content.data); } } finally { //_logger.LogInformation($"consumer received {content}"); _channel.BasicAck(ea.DeliveryTag, false); Console.Write("=== Rabbit proccessed Event ==="); } }; consumer.Shutdown += OnConsumerShutdown; consumer.Registered += OnConsumerRegistered; consumer.Unregistered += OnConsumerUnregistered; consumer.ConsumerCancelled += OnConsumerConsumerCancelled; _channel.BasicConsume(_options.Queue, false, consumer); return(Task.CompletedTask); }
public async Task StartAsync() { _targetCount = Program.GlobalCount; await Console.Out.WriteLineAsync("\r\nRunning example...\r\n").ConfigureAwait(false); _rabbitService = await SetupAsync().ConfigureAwait(false); _errorQueue = _rabbitService.Config.GetConsumerSettings("ConsumerFromConfig").ErrorQueueName; _consumerPipeline = _rabbitService.CreateConsumerPipeline("ConsumerFromConfig", Program.MaxDoP, Program.EnsureOrdered, BuildPipeline); Program.Stopwatch = Stopwatch.StartNew(); await _consumerPipeline.StartAsync(Program.UseStreamPipeline).ConfigureAwait(false); if (Program.AwaitShutdown) { await Console.Out.WriteLineAsync("\r\nAwaiting full ConsumerPipeline finish...\r\n").ConfigureAwait(false); await _consumerPipeline.AwaitCompletionAsync().ConfigureAwait(false); } Program.Stopwatch.Stop(); await Console.Out.WriteLineAsync("\r\nExample finished...").ConfigureAwait(false); }
public static async Task Main() { _hashingProvider = new Argon2IDHasher(); var hashKey = await _hashingProvider.GetHashKeyAsync("passwordforencryption", "saltforencryption", 32).ConfigureAwait(false); _encryptionProvider = new AesGcmEncryptionProvider(hashKey, _hashingProvider.Type); _compressionProvider = new GzipProvider(); _serializationProvider = new Utf8JsonProvider(StandardResolver.Default); _rabbitService = new RabbitService( "Config.json", _serializationProvider, _encryptionProvider, _compressionProvider, null); await RunSimpleClientWithEncryptionAsync() .ConfigureAwait(false); await RunDataExecutionEngineAsync() .ConfigureAwait(false); }
private static async Task SetupAsync() { var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel)); _hashingProvider = new Argon2IDHasher(); var hashKey = await _hashingProvider.GetHashKeyAsync("passwordforencryption", "saltforencryption", 32).ConfigureAwait(false); _encryptionProvider = new AesGcmEncryptionProvider(hashKey, _hashingProvider.Type); _compressionProvider = new LZ4PickleProvider(); _serializationProvider = new Utf8JsonProvider(); _rabbitService = new RabbitService( "Config.json", _serializationProvider, _encryptionProvider, _compressionProvider, loggerFactory); await _rabbitService .Topologer .CreateQueueAsync("TestRabbitServiceQueue") .ConfigureAwait(false); }
public RabbitController(IRabbitService rabbitService) { Ensure.ThatIsNotNull(rabbitService); this.rabbitService = rabbitService; }
public TimedHostedService(ILogger <TimedHostedService> logger, IRabbitService service) { _logger = logger; _service = service; }
public PossController(IRabbitService rabbitService, ILogger <PossController> logger) { _rabbitService = rabbitService; this.logger = logger; }
public AliceController(IRabbitService rabbit) { _rabbit = rabbit; }
public ClientesController(IRabbitService rabbitService, ILogger <ClientesController> logger) { _rabbitService = rabbitService; this.logger = logger; }
public RabbitController(IRabbitService rabbitService) =>
public ProductService(IRabbitService serviceBusService) { _serviceBusService = serviceBusService; }