Esempio n. 1
0
        public Task Send(string destination, BasicMessage basicMessage)
        {
            var consumers = serviceProvider.GetServices <IConsumer>();

            basicMessage.AddHeader(MessageHeaders.Destination, destination);

            foreach (var consumer in consumers)
            {
                ((TestConsumer)consumer).Invoke(basicMessage);
            }

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        private void OnReceivedMessage(object sender, BasicDeliverEventArgs args)
        {
            var body    = args.Body.ToArray();
            var message = new BasicMessage(new MemoryStream(body));

            foreach (var header in args.BasicProperties.Headers)
            {
                var value = Encoding.UTF8.GetString((byte[])header.Value);
                message.AddHeader(header.Key, value);
            }

            onMessage(message).GetAwaiter().GetResult();

            channel.BasicAck(args.DeliveryTag, false);
        }
        public async Task OnError(Exception ex)
        {
            if (bm == null)
            {
                throw new Exception("Message is null!", ex);
            }
            bm.BodyStream.Position = 0;

            var level = 0;

            while (ex != null)
            {
                var headerName = $"EzBus.ErrorMessage L{level}";
                var value      = $"{DateTime.UtcNow}: {ex.Message}";
                bm.AddHeader(headerName, value);
                ex = ex.InnerException;
                level++;
            }

            await broker.Send(addressConfig.ErrorAddress, bm);
        }