private void RegisterWithRabbit(ReceiveMessage receiver)
        {
            var consumer = new EventingBasicConsumer(creator.GetChannel());

            consumer.Received += (sender, ea) =>
            {
                receiver(creator.GetChannel(), sender, ea);
            };

            creator.GetChannel().BasicConsume(queue: queue,
                                              autoAck: autoAck,
                                              consumer: consumer);
        }
        public void Publish(byte[] body, string routingKey)
        {
            if (body == null || body.Length == 0)
            {
                throw new ArgumentException("Body cannot be null or empty");
            }

            if (routingKey == null)
            {
                throw new ArgumentException("routingKey cannot be null");
            }

            creator.GetChannel().BasicPublish(exchange: exchange,
                                              routingKey: routingKey,
                                              mandatory: true,
                                              basicProperties: basicProperties,
                                              body: body);

            if (this.requireReliableDelivery)
            {
                creator.GetChannel().WaitForConfirmsOrDie(waitFromConfirmationTimeSpan);
            }
        }
        internal void ConstructExchange()
        {
            if (String.IsNullOrEmpty(Exchange))
            {
                throw new ArgumentException("Set Exchange required");
            }

            creator.GetChannel().BasicQos(this.qosPrefetchSize, this.QosPreFetchLimit, this.qosGlobal);


            try{
                creator.GetChannel().ExchangeDeclare
                    (Exchange, ExchangeType.ToString(), Durable, AutoDelete);
            }
            catch (OperationInterruptedException e)
            {
                Console.WriteLine($"WARNING: {e.Message} so using EXISTING exchange");
                creator.GetChannel().ExchangeDeclarePassive(Exchange);
            }
        }
Esempio n. 4
0
 public RabbitPublisherBuilder(IRabbitConnectionCreator connectionCreator, ushort qosPreFetchLimit) : base(connectionCreator, qosPreFetchLimit)
 {
     this.connectionCreator = connectionCreator;
     Persistent             = true;
     connectionCreator.GetChannel().BasicReturn += HandleReturn;
 }