本文整理汇总了C#中IBasicConsumer类的典型用法代码示例。如果您正苦于以下问题:C# IBasicConsumer类的具体用法?C# IBasicConsumer怎么用?C# IBasicConsumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IBasicConsumer类属于命名空间,在下文中一共展示了IBasicConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: BasicConsume
/// <summary>Start a Basic content-class consumer.</summary>
public static string BasicConsume(this IModel model, string queue,
bool autoAck,
string consumerTag,
IBasicConsumer consumer)
{
return model.BasicConsume(queue, autoAck, consumerTag, false, false, null, consumer);
}
示例3: 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);
}
}
});
}
示例4: HandleBasicDeliver
public void HandleBasicDeliver(IBasicConsumer consumer,
string consumerTag,
ulong deliveryTag,
bool redelivered,
string exchange,
string routingKey,
IBasicProperties basicProperties,
byte[] body)
{
UnlessShuttingDown(() =>
{
try
{
consumer.HandleBasicDeliver(consumerTag,
deliveryTag,
redelivered,
exchange,
routingKey,
basicProperties,
body);
}
catch (Exception e)
{
var details = new Dictionary<string, object>()
{
{"consumer", consumer},
{"context", "HandleBasicDeliver"}
};
model.OnCallbackException(CallbackExceptionEventArgs.Build(e, details));
}
});
}
示例5: SubscriberBase
public SubscriberBase(IModel model, string queue, IBasicConsumer consumer, SubscriberConfigurator configurator)
{
_model = model;
_queue = queue;
_consumer = consumer;
_configurator = configurator;
}
示例6: ConsumerOnReceived
private void ConsumerOnReceived(IBasicConsumer sender, BasicDeliverEventArgs args)
{
var millisecondsTimeout = m_rnd.Next(1, 10) * 1000;
Console.WriteLine("Message received: {0}, sleeping for {1} seconds", Encoding.UTF8.GetString(args.Body), millisecondsTimeout/1000);
Thread.Sleep(millisecondsTimeout);
sender.Model.BasicAck(args.DeliveryTag, false);
}
示例7: ConsumerOnReceived
private static void ConsumerOnReceived(IBasicConsumer sender, BasicDeliverEventArgs args)
{
var n = int.Parse(Encoding.UTF8.GetString(args.Body));
Console.WriteLine("Received computation request for n = {0}, correlation id {1}", n, args.BasicProperties.CorrelationId);
var fib = Fibonacci(n);
var properties = sender.Model.CreateBasicProperties();
properties.CorrelationId = args.BasicProperties.CorrelationId;
sender.Model.BasicPublish("", args.BasicProperties.ReplyTo, properties, Encoding.UTF8.GetBytes(fib.ToString()));
sender.Model.BasicAck(args.DeliveryTag, false);
}
示例8: ConsumerExecutionContext
public ConsumerExecutionContext(
Func<byte[], MessageProperties, MessageReceivedInfo, Task> userHandler,
MessageReceivedInfo info,
MessageProperties properties,
byte[] body,
IBasicConsumer consumer)
{
Preconditions.CheckNotNull(userHandler, "userHandler");
Preconditions.CheckNotNull(info, "info");
Preconditions.CheckNotNull(properties, "properties");
Preconditions.CheckNotNull(body, "body");
Preconditions.CheckNotNull(consumer, "consumer");
UserHandler = userHandler;
Info = info;
Properties = properties;
Body = body;
Consumer = consumer;
}
示例9: HandleBasicCancelOk
public void HandleBasicCancelOk(IBasicConsumer consumer, string consumerTag)
{
UnlessShuttingDown(() =>
{
try
{
consumer.HandleBasicCancelOk(consumerTag);
}
catch (Exception e)
{
var details = new Dictionary<string, object>()
{
{"consumer", consumer},
{"context", "HandleBasicCancelOk"}
};
model.OnCallbackException(CallbackExceptionEventArgs.Build(e, details));
}
});
}
示例10: DoAckForTest
public void DoAckForTest(BasicDeliverEventArgs basicDeliverEventArgs, IBasicConsumer subscriptionInfo)
{
DoAck(basicDeliverEventArgs, subscriptionInfo);
}
示例11: DoAck
internal protected override void DoAck(BasicDeliverEventArgs basicDeliverEventArgs, IBasicConsumer subscriptionInfo)
{
base.DoAck(basicDeliverEventArgs, subscriptionInfo);
WaitHandler.Set();
}
示例12: HandleEvent
private void HandleEvent(IBasicConsumer sender, BasicDeliverEventArgs args)
{
var elementBody = Encoding.Unicode.GetString(args.Body);
var element = XElement.Parse(elementBody);
DecodeAndRouteEvent(element);
}
示例13: TestExceptionHandlingWith
protected void TestExceptionHandlingWith(IBasicConsumer consumer, FailingOp fn)
{
Object o = new Object();
bool notified = false;
string q = Model.QueueDeclare();
Model.CallbackException += (m, evt) => {
notified = true;
Monitor.PulseAll(o);
};
string tag = Model.BasicConsume(q, true, consumer);
fn(Model, q, consumer, tag);
WaitOn(o);
Assert.IsTrue(notified);
}
示例14: BasicConsume
public string BasicConsume(string queue,
bool noAck,
string consumerTag,
bool noLocal,
bool exclusive,
IDictionary<string, object> arguments,
IBasicConsumer consumer)
{
ModelShutdown += new ModelShutdownEventHandler(consumer.HandleModelShutdown);
BasicConsumerRpcContinuation k = new BasicConsumerRpcContinuation();
k.m_consumer = consumer;
Enqueue(k);
// Non-nowait. We have an unconventional means of getting
// the RPC response, but a response is still expected.
_Private_BasicConsume(queue, consumerTag, noLocal, noAck, exclusive,
/*nowait:*/ false, arguments);
k.GetReply();
string actualConsumerTag = k.m_consumerTag;
return actualConsumerTag;
}
示例15: BasicConsume
public string BasicConsume(string queue, bool noAck, IDictionary filter, IBasicConsumer consumer)
{
throw new NotImplementedException();
}