コード例 #1
0
ファイル: Subscriber.cs プロジェクト: Ruandv/RabbitMQ_Demo
        public override void Run()
        {
            var consumer = new EventingBasicConsumer(Model);

            consumer.Received += (m, ea) =>
            {
                var body    = ea.Body;
                var message = Encoding.UTF8.GetString(body);
                Console.WriteLine($"Received : {message}");
                if (message == "asdf")
                {
                    Console.WriteLine("ERROR MESSAGE!!");

                    Model.BasicReject(ea.DeliveryTag, false);

                    throw new NotImplementedException();
                }
                else
                {
                    Model.BasicAck(ea.DeliveryTag, false);
                }
            };

            Model.BasicConsume(queue: QueueName.ToLower(),
                               autoAck: false,
                               consumer: consumer);
        }
コード例 #2
0
        /// <summary>
        /// Initialize the appender based on the options set
        /// </summary>
        /// <remarks>
        /// <para>
        /// This is part of the <see cref="T:log4net.Core.IOptionHandler"/> delayed object activation scheme.
        /// The <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions"/> method must be called on this object after the configuration properties have been set.
        /// Until <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions"/> is called this object is in an undefined state and must not be used.
        /// </para>
        /// <para>
        /// If any of the configuration properties are modified then <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions"/> must be called again.
        /// </para>
        /// </remarks>
        public override void ActivateOptions()
        {
            base.ActivateOptions();

            _account = new QueueServiceClient(ConnectionString);
            _queue   = _account.GetQueueClient(QueueName.ToLower());
            _queue.CreateIfNotExists();
        }
コード例 #3
0
        /// <summary>
        /// Initialize the appender based on the options set
        /// </summary>
        /// <remarks>
        /// <para>
        /// This is part of the <see cref="T:log4net.Core.IOptionHandler"/> delayed object
        ///             activation scheme. The <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions"/> method must
        ///             be called on this object after the configuration properties have
        ///             been set. Until <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions"/> is called this
        ///             object is in an undefined state and must not be used.
        /// </para>
        /// <para>
        /// If any of the configuration properties are modified then
        ///             <see cref="M:log4net.Appender.BufferingAppenderSkeleton.ActivateOptions"/> must be called again.
        /// </para>
        /// </remarks>
        public override void ActivateOptions()
        {
            base.ActivateOptions();

            _account     = CloudStorageAccount.Parse(ConnectionString);
            _queueClient = _account.CreateCloudQueueClient();
            _queue       = _queueClient.GetQueueReference(QueueName.ToLower());
            _queue.CreateIfNotExists();
        }
コード例 #4
0
 protected AzureServiceBusBaseProducer(IAzureServiceBusConnectionManager azureServiceBusConnectionManager, ILogger logger, ISerializer <TMessage> serializer,
                                       Func <string, Dictionary <int, string> > getSenders)
 {
     var(QueueName, Delay) = ModelBuilder.GetQueueName <TMessage>();
     _queueName            = QueueName.ToLower();
     _messageDelay         = Delay;
     _client     = azureServiceBusConnectionManager.GetClient();
     _logger     = logger;
     _serializer = serializer;
     _senders    = getSenders(_queueName).Select(i => new { i.Key, Value = _client.CreateSender(i.Value) }).ToDictionary(i => i.Key, i => i.Value);
 }