本文整理汇总了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);
}
}
});
}
示例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
};
}
示例3: FromBasicDeliverEventArgs
public static ConsumedMessageContext FromBasicDeliverEventArgs(BasicDeliverEventArgs args)
{
if (args == null)
throw new ArgumentNullException(nameof(args));
return new ConsumedMessageContext(args);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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());
}
示例12: RabbitMessageConverterTests
public RabbitMessageConverterTests()
{
_message = new BasicDeliverEventArgs();
_message.BasicProperties = new BasicProperties();
_converter = new RabbitMessageConverter();
}
示例13: Encoding
private static Encoding Encoding(BasicDeliverEventArgs args)
{
var encoding = args.BasicProperties.ContentEncoding;
return encoding == null
? new UTF8Encoding(true)
: System.Text.Encoding.GetEncoding(encoding);
}
示例14: GetQueueItem
private static LogOrderQueueItem GetQueueItem(BasicDeliverEventArgs deliverEventArgs)
{
return deliverEventArgs.Body
.ToOption()
.Map(Encoding.UTF8.GetString)
.Map(JsonConvert.DeserializeObject<LogOrderQueueItem>)
.Value;
}
示例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;
}