public IBasicProperties CreateBasicProperties(RabbitMQProducerDeclaration declaration)
        {
            var properties = channel.CreateBasicProperties();

            foreach (var property in declaration.Properties)
            {
                property(properties);
            }

            return(properties);
        }
        private RabbitMQProducerDeclaration GetDeclaration <TPayload>(Action <IRabbitMQProducerBuilder <TPayload> > overrides)
        {
            var producerDeclaration = options.ProducerDeclarations.TryGetValue(typeof(TPayload), out var declaration)
                                ? declaration
                                : throw new RabbitMQMissingDeclarationException(typeof(TPayload));

            if (overrides != null)
            {
                producerDeclaration = RabbitMQProducerDeclaration.FromDeclaration(producerDeclaration);
                overrides(new RabbitMQProducerBuilder <TPayload>(producerDeclaration));
            }

            return(producerDeclaration);
        }
        // Producers
        public void BasicPublish(RabbitMQProducerDeclaration declaration, byte[] payload)
        {
            var properties = CreateBasicProperties(declaration);

            lock (@lock)
            {
                channel.BasicPublish(
                    declaration.ExchangeDeclaration.Name,
                    declaration.RoutingKey ?? declaration.ExchangeDeclaration.Name,
                    declaration.Mandatory,
                    properties,
                    payload);
            }
        }
Esempio n. 4
0
        private static IRabbitMQProducerBuilder <TPayload> AddProducer <TPayload>(
            this IRabbitMQConnectionBuilder connection,
            IRabbitMQExchangeBuilderCore exchange)
        {
            var declaration = new RabbitMQProducerDeclaration(
                typeof(TPayload),
                connection.ConnectionDeclaration,
                exchange.ExchangeDeclaration);

            connection.Services
            .Configure <RabbitMQOptions>(
                options => options.ProducerDeclarations.Add(typeof(TPayload), declaration));

            return(new RabbitMQProducerBuilder <TPayload>(declaration));
        }
Esempio n. 5
0
 public static RabbitMQProducerDeclaration FromDeclaration(RabbitMQProducerDeclaration declaration)
 {
     return(new RabbitMQProducerDeclaration(
                declaration.PayloadType,
                declaration.ConnectionDeclaration,
                declaration.ExchangeDeclaration)
     {
         RoutingKey = declaration.RoutingKey,
         Mandatory = declaration.Mandatory,
         Transactional = declaration.Transactional,
         WaitForConfirms = declaration.WaitForConfirms,
         Die = declaration.Die,
         Timeout = declaration.Timeout,
         Arguments = declaration.Arguments,
         Properties = declaration.Properties
     });
 }
        public IBasicPublishBatch CreateBasicPublishBatch(
            RabbitMQProducerDeclaration declaration,
            IEnumerable <byte[]> payloads)
        {
            var batch      = channel.CreateBasicPublishBatch();
            var properties = CreateBasicProperties(declaration);

            foreach (var payload in payloads)
            {
                batch.Add(
                    declaration.ExchangeDeclaration.Name,
                    declaration.RoutingKey ?? declaration.ExchangeDeclaration.Name,
                    declaration.Mandatory,
                    properties,
                    payload);
            }

            return(batch);
        }
        public bool WaitForConfirms(RabbitMQProducerDeclaration declaration)
        {
            lock (@lock)
            {
                if (declaration.Die)
                {
                    if (declaration.Timeout is null)
                    {
                        channel.WaitForConfirmsOrDie();
                    }
                    else
                    {
                        channel.WaitForConfirmsOrDie(declaration.Timeout.Value);
                    }

                    return(true);
                }

                return(declaration.Timeout is null
                                        ? channel.WaitForConfirms()
                                        : channel.WaitForConfirms(declaration.Timeout.Value));
            }
        }