public AggregateDictionariesService(IMessageBusClient messageBusClient, IOptions <AppSettings> options)
 {
     _messageBusClient     = messageBusClient ?? throw new ArgumentNullException(nameof(messageBusClient));
     _options              = options ?? throw new ArgumentNullException(nameof(options));
     _results              = new ConcurrentDictionary <Guid, object>();
     _providerNotResponded = new ConcurrentDictionary <Guid, int>();
     _delayTokenSource     = new CancellationTokenSource();
 }
Esempio n. 2
0
    public Task Setup(IMessageBusClient client)
    {
        try
        {
            //Create a disposable queue
            var queueName = client.Channel.QueueDeclare(Name, true, false, false).QueueName;

            client.Channel.BasicQos(0, 1, false);

            //Bind it to the exchange
            client.Channel.QueueBind(queueName, Exchange, Key);

            var consumer = new EventingBasicConsumer(client.Channel);
            consumer.Received += async(model, ea) =>
            {
                try
                {
                    using var scope = _services.CreateScope();
                    var messageJson = Encoding.UTF8.GetString(ea.Body.ToArray());

                    var message = messageJson.FromJson <T1>();

                    var response = await ProcessMessage(scope.ServiceProvider, message);

                    var responseJson = response.ToJson();

                    var responseData = Encoding.UTF8.GetBytes(responseJson);

                    //Send result
                    var replyProps = client.Channel.CreateBasicProperties();
                    replyProps.CorrelationId = ea.BasicProperties.CorrelationId;

                    client.Channel.BasicPublish("", ea.BasicProperties.ReplyTo, replyProps, responseData);

                    client.Channel.BasicAck(ea.DeliveryTag, false);
                }
                catch (Exception exc)
                {
                    var body = ea.Body.ToArray();

                    Logger.LogError(exc, "RabbitMQ Message Failed => {name} => {message}", Name, Encoding.UTF8.GetString(body));

                    client.Channel.BasicNack(ea.DeliveryTag, false, false);

                    client.SendError(body, ea.RoutingKey);
                }
            };
            client.Channel.BasicConsume(queueName, false, consumer);
        }
        catch (Exception exc)
        {
            Logger.LogError(exc, "Error setting up message bus listener (rpc) {name}", Name);
        }

        return(Task.CompletedTask);
    }
        public static IMessageBus AddMessageBus(this IServiceCollection services, IMessageBusAdminClient messageBusAdmin,
                                                IMessageBusClient messageBusClient, MessageBusOptions?options = null)
        {
            var messageBus = (IMessageBus) new Abstractions.MessageBus(new MessageHandlerResolver(services),
                                                                       messageBusAdmin, messageBusClient, new MessageProcessorResolver(services), options);

            services.AddSingleton(messageBus);

            return(messageBus);
        }
Esempio n. 4
0
 public PlatformsController(
     IPlatformRepo repo,
     IMapper mapper,
     ICommandDataClient commandDataClient,
     IMessageBusClient messageBusClient)
 {
     _repo              = repo;
     _mapper            = mapper;
     _commandDataClient = commandDataClient;
     _messageBusClient  = messageBusClient;
 }
Esempio n. 5
0
 public MessageBus(IMessageHandlerResolver messageHandlerResolver,
                   IMessageBusAdminClient messageBusAdmin, IMessageBusClient messageBusClient,
                   IMessageProcessorResolver messageProcessorResolver,
                   MessageBusOptions?messageBusOptions = null)
 {
     _messageHandlerResolver   = messageHandlerResolver;
     _messageBusAdminClient    = messageBusAdmin;
     _messageBusClient         = messageBusClient;
     _messageProcessorResolver = messageProcessorResolver;
     _messageBusOptions        = messageBusOptions ?? new MessageBusOptions();
     _messageTypePropertyName  = _messageBusOptions.MessageTypePropertyName;
 }
Esempio n. 6
0
    public MessageBusSender(ILogger <MessageBusSender> logger, IMessageBusClient client)
    {
        _logger = logger;
        _client = client;

        _rpcQueue = _client.Channel.QueueDeclare().QueueName;

        var consumer = new EventingBasicConsumer(_client.Channel);

        consumer.Received += Consumer_Received;
        _client.Channel.BasicConsume(consumer: consumer, queue: _rpcQueue, autoAck: true);

        _pendingMessages = new ConcurrentDictionary <string, TaskCompletionSource <string> >();
    }
Esempio n. 7
0
    /// <summary>
    /// Set up the message bus listener
    /// </summary>
    /// <param name="client"></param>
    /// <returns></returns>
    public Task Setup(IMessageBusClient client)
    {
        try
        {
            //Create a disposable queue
            var queueName = client.Channel.QueueDeclare(Name, true, false, false).QueueName;

            client.Channel.BasicQos(0, 1, false);

            //Bind it to the exchange
            client.Channel.QueueBind(queueName, Exchange, Key);

            var consumer = new EventingBasicConsumer(client.Channel);
            consumer.Received += async(model, ea) =>
            {
                try
                {
                    using var scope = _services.CreateScope();
                    var message = Encoding.UTF8.GetString(ea.Body.ToArray());

                    var item = message.FromJson <T>();

                    await ProcessMessage(scope.ServiceProvider, item);

                    client.Channel.BasicAck(ea.DeliveryTag, false);
                }
                catch (Exception exc)
                {
                    var body = ea.Body.ToArray();

                    Logger.LogTrace(exc, "RabbitMQ Message Failed => {name} => {message}", Name, Encoding.UTF8.GetString(body));

                    client.Channel.BasicNack(ea.DeliveryTag, false, false);

                    client.SendError(body, ea.RoutingKey);
                }
            };
            client.Channel.BasicConsume(queueName, false, consumer);
        }
        catch (Exception exc)
        {
            Logger.LogError(exc, "Error setting up message bus listener => {name}", Name);
        }

        return(Task.CompletedTask);
    }
Esempio n. 8
0
 public MessageBusService(ILogger <MessageBusService> logger, IServiceProvider services, IMessageBusClient client)
 {
     _logger   = logger;
     _client   = client;
     _services = services;
 }
Esempio n. 9
0
 public DealRepository(IEventStoreClient eventStoreClient, IMessageBusClient messageBusClient)
 {
     _eventStoreClient = eventStoreClient;
     _messageBusClient = messageBusClient;
 }
Esempio n. 10
0
 public CommandDispatcher(IMessageBusClient messageBusClient)
 {
     this.messageBusClient = messageBusClient;
 }
 public FlightController(RepositoryContext repo, IMapper mapper, IMessageBusClient messageBusClient)
 {
     _repo             = repo;
     _mapper           = mapper;
     _messageBusClient = messageBusClient;
 }
Esempio n. 12
0
 public MainViewModel(IMessageBusClient messageBusClient)
 {
     _messageBusClient = messageBusClient ?? throw new ArgumentNullException(nameof(messageBusClient));
     Download          = new RelayCommand(e => DownloadRun(System, Int32.Parse(RunId)), ce => Int32.TryParse(RunId, out var _));
 }
Esempio n. 13
0
 public FakeMessageBusSender(ILogger <MessageBusSender> logger, IMessageBusClient client)
 {
     Sent = new Dictionary <(string exchange, string key, Guid random), object>();
 }
Esempio n. 14
0
 public MessageBusinessService(IMessageBusClient messageBusClient)
 {
     _messageBusClient = messageBusClient ?? throw new ArgumentNullException(nameof(messageBusClient));
 }
Esempio n. 15
0
        public static Task Enqueue <T>(this IMessageBusClient client, T message)
        {
            var payload = message.ToJson();

            return(client.Enqueue(message.GetType().Name, payload));
        }
Esempio n. 16
0
 public FlightsController(AirlineDbContext context, IMapper mapper, IMessageBusClient messageBus)
 {
     _mapper     = mapper;
     _messageBus = messageBus;
     _context    = context;
 }
Esempio n. 17
0
        public static async Task <T> Dequeue <T>(this IMessageBusClient client)
        {
            var payload = await client.Dequeue(typeof(T).Name);

            return(payload.FromJson <T>());
        }
Esempio n. 18
0
 public DealRepository(IEventStoreClient eventStoreClient, IMessageBusClient messageBusClient)
 {
     _eventStoreClient = eventStoreClient;
     _messageBusClient = messageBusClient;
 }
 public DealEntryCommandHandler(IMessageBusClient messageBusClient, IEventStoreClient eventStoreClient)
 {
     _messageBusClient = messageBusClient;
     _eventStoreClient = eventStoreClient;
 }
 public FlightDetailController(AirlineDbContext context, IMapper mapper, IMessageBusClient messageBusClient)
 {
     _context          = context;
     _mapper           = mapper;
     _messageBusClient = messageBusClient;
 }
Esempio n. 21
0
 public OtherSearchService(IMessageBusClient messageBusClient, IOtherTourRepository tourRepository, IOtherDictionariesRepository dictionariesRepository)
 {
     _messageBusClient       = messageBusClient ?? throw new ArgumentNullException(nameof(messageBusClient));
     _tourRepository         = tourRepository ?? throw new ArgumentNullException(nameof(tourRepository));
     _dictionariesRepository = dictionariesRepository ?? throw new ArgumentNullException(nameof(dictionariesRepository));
 }
Esempio n. 22
0
 public WebhookSubscriptionController(AirlineDbContext context, IMapper mapper, IMessageBusClient messageBus)
 {
     _context    = context;
     _mapper     = mapper;
     _messageBus = messageBus;
 }
 public DealEntryCommandHandler(IMessageBusClient messageBusClient, IEventStoreClient eventStoreClient)
 {
     _messageBusClient = messageBusClient;
     _eventStoreClient = eventStoreClient;
 }