當前位置: 首頁>>代碼示例>>C#>>正文


C# Events.BasicDeliverEventArgs類代碼示例

本文整理匯總了C#中RabbitMQ.Client.Events.BasicDeliverEventArgs的典型用法代碼示例。如果您正苦於以下問題:C# BasicDeliverEventArgs類的具體用法?C# BasicDeliverEventArgs怎麽用?C# BasicDeliverEventArgs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BasicDeliverEventArgs類屬於RabbitMQ.Client.Events命名空間,在下文中一共展示了BasicDeliverEventArgs類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: HandleMessage

        public virtual void HandleMessage(IBasicConsumer consumer, BasicDeliverEventArgs eventArg)
        {
            var completionTask = _jobFactory(eventArg);
            completionTask.ContinueWith(task =>
            {
                try
                {
                    if (task.IsFaulted)
                    {
                        HandleError(consumer, eventArg, task.Exception);
                    }
                }
                catch (Exception ex)
                {
                    _watcher.Error(ex);
                }
                finally
                {
                    // Broadcast msgs
                    AfterHandlingMessage(consumer, eventArg);

                    //NOTE: Only this way, the new event to interupt other consumers will override previous resume event
                    if (HandlingComplete != null)
                    {
                        // Release pool + DoAck
                        HandlingComplete(eventArg);
                    }
                }
            });
        }
開發者ID:brett--anderson,項目名稱:Burrow.NET,代碼行數:30,代碼來源:DefaultMessageHandler.cs

示例2: Translate

		protected virtual ChannelMessage Translate(BasicDeliverEventArgs message)
		{
			var properties = message.BasicProperties;

			var dispatched = properties.Timestamp.UnixTime.ToDateTime();
			var expiration = properties.Expiration.ToDateTime(dispatched);
			expiration = expiration == DateTime.MinValue ? DateTime.MaxValue : expiration;

			if (expiration <= SystemTime.UtcNow)
				throw new DeadLetterException(expiration);

			var payload = this.Deserialize(message.Body, properties.Type, properties.ContentFormat(), properties.ContentEncoding);

			return new ChannelMessage(
				properties.MessageId.ToGuid(),
				properties.CorrelationId.ToGuid(),
				properties.ReplyTo.ToUri(),
				new Dictionary<string, string>(),
				payload)
			{
				Dispatched = properties.Timestamp.UnixTime.ToDateTime(),
				Expiration = expiration,
				Persistent = properties.DeliveryMode == Persistent
			};
		}
開發者ID:yonglehou,項目名稱:NanoMessageBus,代碼行數:25,代碼來源:RabbitMessageAdapter.cs

示例3: FromBasicDeliverEventArgs

        public static ConsumedMessageContext FromBasicDeliverEventArgs(BasicDeliverEventArgs args)
        {
            if (args == null)
                throw new ArgumentNullException(nameof(args));

            return new ConsumedMessageContext(args);
        }
開發者ID:naighes,項目名稱:Carrot,代碼行數:7,代碼來源:ConsumedMessageContext.cs

示例4: DeserializeThrows

 public void DeserializeThrows()
 {
     const String type = "fake-type";
     const String contentType = "application/null";
     var body = new Byte[] { };
     var args = new BasicDeliverEventArgs
                    {
                        Body = body,
                        BasicProperties = new BasicProperties
                        {
                            ContentType = contentType,
                            Type = type
                        }
                    };
     var context = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
     var runtimeType = typeof(Foo);
     var serializer = new Mock<ISerializer>();
     serializer.Setup(_ => _.Deserialize(body, runtimeType, new UTF8Encoding(true)))
               .Throws(new Exception("boom"));
     var serializationConfiguration = new SerializationConfigurationWrapper(serializer.Object);
     var resolver = new Mock<IMessageTypeResolver>();
     resolver.Setup(_ => _.Resolve(context)).Returns(new MessageBinding(type, runtimeType));
     var builder = new ConsumedMessageBuilder(serializationConfiguration, resolver.Object);
     var message = builder.Build(args);
     Assert.IsType<CorruptedMessage>(message);
 }
開發者ID:naighes,項目名稱:Carrot,代碼行數:26,代碼來源:ConsumedMessageBuilding.cs

示例5: rate_limit_notify

 private static void rate_limit_notify(IBasicConsumer consumer,
                                       BasicDeliverEventArgs eargs) {
     
     string[] EMAIL_RECIPS = new string[] {"[email protected]"};
     
     IBasicProperties msg_props = eargs.BasicProperties;
     String msg_body = Encoding.ASCII.GetString(eargs.Body);
     
     //#/(ascdn.4) Decode our message from JSON
     msg_body = JsonConvert.DeserializeObject
                            <string>(msg_body);
     
     //#/(ascdn.5) Transmit e-mail to SMTP server
     send_mail(EMAIL_RECIPS,
               "RATE LIMIT ALERT!",
               msg_body);
     
     Console.WriteLine("Sent alert via e-mail! Alert Text: " +
                       msg_body + " Recipients: " +
                       string.Join(",", EMAIL_RECIPS));
     
     //#/(ascdn.6) Acknowledge the message
     consumer.Model.BasicAck(eargs.DeliveryTag,
                             false);
 }
開發者ID:FFng,項目名稱:sourcecode,代碼行數:25,代碼來源:alerting_server_consumer.cs

示例6: HandleBasicDeliver

        public override void HandleBasicDeliver(String consumerTag,
                                                UInt64 deliveryTag,
                                                Boolean redelivered,
                                                String exchange,
                                                String routingKey,
                                                IBasicProperties properties,
                                                Byte[] body)
        {
            base.HandleBasicDeliver(consumerTag,
                                    deliveryTag,
                                    redelivered,
                                    exchange,
                                    routingKey,
                                    properties,
                                    body);

            var args = new BasicDeliverEventArgs
                           {
                               ConsumerTag = consumerTag,
                               DeliveryTag = deliveryTag,
                               Redelivered = redelivered,
                               Exchange = exchange,
                               RoutingKey = routingKey,
                               BasicProperties = properties,
                               Body = body
                           };

            ConsumeInternalAsync(args);
        }
開發者ID:emadb,項目名稱:Carrot,代碼行數:29,代碼來源:ConsumerBase.cs

示例7: Build

		public virtual ChannelMessage Build(BasicDeliverEventArgs message)
		{
			if (message == null)
				throw new ArgumentNullException("message");

			try
			{
				var result = this.Translate(message);
				this.AppendHeaders(result, message.BasicProperties);
				return result;
			}
			catch (SerializationException e)
			{
				Log.Error("Unable to deserialize message '{0}'.".FormatWith(message.MessageId()), e);
				throw new PoisonMessageException(e.Message, e);
			}
			catch (DeadLetterException)
			{
				throw;
			}
			catch (Exception e)
			{
				Log.Error("General deserialize error for message '{0}'.".FormatWith(message.MessageId()), e);
				throw new PoisonMessageException(e.Message, e);
			}
		}
開發者ID:akurtov,項目名稱:NanoMessageBus,代碼行數:26,代碼來源:RabbitMessageAdapter.cs

示例8: HandleMessage

 private void HandleMessage(BasicDeliverEventArgs result)
 {
     var data = Encoding.UTF8.GetString(result.Body);
     var telegram = new Telegram(data);
     var telegramEventArgs = new TelegramReceivedEventArgs(telegram);
     OnTelegramReceived(telegramEventArgs);
 }
開發者ID:bnathyuw,項目名稱:Telegram,代碼行數:7,代碼來源:Telegraph.cs

示例9: TryReceive

		protected virtual void TryReceive(BasicDeliverEventArgs message, Action<IDeliveryContext> callback)
		{
			var messageId = message.MessageId();

			try
			{
				Log.Verbose("Translating wire-specific message into channel message.");
				this.CurrentMessage = this.adapter.Build(message);

				Log.Info("Routing message '{0}' received through group '{1}' to configured receiver callback.", messageId, this.configuration.GroupName);
				callback(this);
			}
			catch (ChannelConnectionException)
			{
				Log.Warn("The channel has become unavailable, aborting current transaction.");
				this.CurrentTransaction.TryDispose();
				throw;
			}
			catch (PoisonMessageException e)
			{
				Log.Warn("Wire message {0} could not be deserialized; forwarding to poison message exchange.", messageId);
				this.ForwardToPoisonMessageExchange(message, e);
			}
			catch (DeadLetterException)
			{
				Log.Info("Wire message {0} has expired on the wire; forwarding to dead-letter exchange.", messageId);
				this.ForwardTo(message, this.configuration.DeadLetterExchange);
			}
			catch (Exception e)
			{
				this.RetryMessage(message, e);
			}
		}
開發者ID:sevst,項目名稱:NanoMessageBus,代碼行數:33,代碼來源:RabbitChannel.cs

示例10: OnResponseHandlerExceptionAsync

        public virtual Task OnResponseHandlerExceptionAsync(IRawConsumer rawConsumer, IConsumerConfiguration cfg, BasicDeliverEventArgs args, Exception exception)
        {
            _logger.LogError($"An unhandled exception was thrown in the response handler for message '{args.BasicProperties.MessageId}'.", exception);
            var innerException = UnwrapInnerException(exception);
            var rawException = new MessageHandlerException(
                message: $"An unhandled exception was thrown when consuming a message\n  MessageId: {args.BasicProperties.MessageId}\n  Queue: '{cfg.Queue.FullQueueName}'\n  Exchange: '{cfg.Exchange.ExchangeName}'\nSee inner exception for more details.",
                inner: innerException
            );

            _logger.LogInformation($"Sending MessageHandlerException with CorrelationId '{args.BasicProperties.CorrelationId}'");
            rawConsumer.Model.BasicPublish(
                exchange: string.Empty,
                routingKey: args.BasicProperties?.ReplyTo ?? string.Empty,
                basicProperties: _propertiesProvider.GetProperties<MessageHandlerException>(p =>
                {
                    p.CorrelationId = args.BasicProperties?.CorrelationId ?? string.Empty;
                    p.Headers.Add(PropertyHeaders.ExceptionHeader, _messageExceptionName);
                }),
                body: _serializer.Serialize(rawException)
            );

            if (!cfg.NoAck)
            {
                _logger.LogDebug($"Nack'ing message with delivery tag '{args.DeliveryTag}'.");
                rawConsumer.Model.BasicNack(args.DeliveryTag, false, false);
            }
            return Task.FromResult(true);
        }
開發者ID:yuriik83,項目名稱:RawRabbit,代碼行數:28,代碼來源:DefaultStrategy.cs

示例11: HeaderMapping

        public void HeaderMapping()
        {
            var content = new Foo();
            const String messageId = "one-id";
            const Int64 timestamp = 123456789L;
            const String replyExchangeType = "direct";
            const String replyExchangeName = "exchange-name";
            const String replyRoutingKey = "routing-key";
            const String correlationId = "one-correlation-id";
            var replyTo = $"{replyExchangeType}://{replyExchangeName}/{replyRoutingKey}";

            var args = new BasicDeliverEventArgs
                           {
                               BasicProperties = new BasicProperties
                                                     {
                                                         MessageId = messageId,
                                                         Timestamp = new AmqpTimestamp(timestamp),
                                                         CorrelationId = correlationId,
                                                         ReplyTo = replyTo
                                                     }
                           };
            var message = new FakeConsumedMessage(content, args);
            var actual = message.To<Foo>();
            Assert.Equal(messageId, actual.Headers.MessageId);
            Assert.Equal(timestamp, actual.Headers.Timestamp);
            Assert.Equal(correlationId, actual.Headers.CorrelationId);
            Assert.Equal(replyTo, actual.Headers.ReplyConfiguration.ToString());
        }
開發者ID:naighes,項目名稱:Carrot,代碼行數:28,代碼來源:MessageBuilding.cs

示例12: RabbitMessageConverterTests

		public RabbitMessageConverterTests()
		{
			_message = new BasicDeliverEventArgs();
			_message.BasicProperties = new BasicProperties();

			_converter = new RabbitMessageConverter();
		}
開發者ID:Pondidum,項目名稱:Overseer.RabbitMQ,代碼行數:7,代碼來源:RabbitMessageConverterTests.cs

示例13: Encoding

        private static Encoding Encoding(BasicDeliverEventArgs args)
        {
            var encoding = args.BasicProperties.ContentEncoding;

            return encoding == null
                       ? new UTF8Encoding(true)
                       : System.Text.Encoding.GetEncoding(encoding);
        }
開發者ID:emadb,項目名稱:Carrot,代碼行數:8,代碼來源:ConsumedMessageBuilder.cs

示例14: GetQueueItem

 private static LogOrderQueueItem GetQueueItem(BasicDeliverEventArgs deliverEventArgs)
 {
     return deliverEventArgs.Body
         .ToOption()
         .Map(Encoding.UTF8.GetString)
         .Map(JsonConvert.DeserializeObject<LogOrderQueueItem>)
         .Value;
 }
開發者ID:SergerGood,項目名稱:OrderSample,代碼行數:8,代碼來源:Program.cs

示例15: MakePayment

        private string MakePayment(BasicDeliverEventArgs ea)
        {
            var payment = (CardPayment)ea.Body.DeSerialize(typeof(CardPayment));
            var response = _rnd.Next(1000, 100000000).ToString(CultureInfo.InvariantCulture);
            Console.WriteLine("Payment -  {0} : £{1} : Auth Code <{2}> ", payment.CardNumber, payment.Amount, response);

            return response;
        }
開發者ID:FantasticFiasco,項目名稱:sandbox,代碼行數:8,代碼來源:RabbitMQConsumer.cs


注:本文中的RabbitMQ.Client.Events.BasicDeliverEventArgs類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。