本文整理汇总了C#中IModel.BasicQos方法的典型用法代码示例。如果您正苦于以下问题:C# IModel.BasicQos方法的具体用法?C# IModel.BasicQos怎么用?C# IModel.BasicQos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModel
的用法示例。
在下文中一共展示了IModel.BasicQos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeclareQueue
protected virtual void DeclareQueue(IModel channel)
{
if (this.DispatchOnly)
return;
var declarationArgs = new Dictionary<string, object>();
if (this.DeadLetterExchange != null)
declarationArgs[DeadLetterExchangeDeclaration] = this.DeadLetterExchange.ExchangeName;
if (this.Clustered)
declarationArgs[ClusteredQueueDeclaration] = ReplicateToAllNodes;
var inputQueue = this.InputQueue;
if (this.RandomInputQueue)
inputQueue = string.Empty;
var declaration = channel.QueueDeclare(
inputQueue, this.DurableQueue, this.ExclusiveQueue, this.AutoDelete, declarationArgs);
if (declaration != null)
this.InputQueue = declaration.QueueName;
if (!this.ReturnAddressSpecified)
this.ReturnAddress = new Uri(DefaultReturnAddressFormat.FormatWith(this.InputQueue));
if (this.PurgeOnStartup)
channel.QueuePurge(this.InputQueue);
channel.BasicQos(0, (ushort)this.ChannelBuffer, false);
}
示例2: ReceiveDotNetObjects
private static void ReceiveDotNetObjects(IModel model)
{
model.BasicQos(0, 1, false);
QueueingBasicConsumer consumer = new QueueingBasicConsumer(model);
model.BasicConsume(CommonService.DotNetObjectQueueName, false, consumer);
while (true)
{
BasicDeliverEventArgs deliveryArguments = consumer.Queue.Dequeue() as BasicDeliverEventArgs;
string objectType = deliveryArguments.BasicProperties.Type;
Type t = Type.GetType(objectType);
String jsonified = Encoding.UTF8.GetString(deliveryArguments.Body);
object rawObject = JsonConvert.DeserializeObject(jsonified, t);
Console.WriteLine("Object type: {0}", objectType);
if (rawObject.GetType() == typeof(Customer))
{
Customer customer = rawObject as Customer;
Console.WriteLine("Customer name: {0}", customer.Name);
}
else if (rawObject.GetType() == typeof(NewCustomer))
{
NewCustomer newCustomer = rawObject as NewCustomer;
Console.WriteLine("NewCustomer name: {0}", newCustomer.Name);
}
model.BasicAck(deliveryArguments.DeliveryTag, false);
}
}
示例3: MessageQueue
//private string _exchange;
//_________________________________________________________________________________________________
// Constructor, it initializes the message queue to just consume messages
public MessageQueue(string server, string exchange, string queue)
{
try
{
ConnectionFactory factory;
/*server = (server == null) ? ConfigurationManager.AppSettings["queueServer"] : server;
_queueName = (queue == null) ? ConfigurationManager.AppSettings["queueName"] : queue;*/
_queueName = queue;
factory = new ConnectionFactory();
factory.UserName = "guest";
factory.Password = "guest";
factory.Port = 5672; // default is 5672
factory.VirtualHost = "/"; // default is "/"
factory.HostName = server;
_conn = factory.CreateConnection();
_channel = _conn.CreateModel();
_channel.QueueDeclare(_queueName, true, false, false, null); // it will save to the disk
_channel.BasicQos(0, 1, false); // get just 1 message
// We configure the class to have a event consumer
_consumer = new QueueingBasicConsumer(_channel);
_channel.BasicConsume(_queueName, false, _consumer);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
示例4: ConfigureQos
protected void ConfigureQos(IModel channel, ushort prefetchCount)
{
channel.BasicQos(
prefetchSize: 0,
prefetchCount: prefetchCount,
global: false
);
}
示例5: ConfigureQueueChannel
private void ConfigureQueueChannel(IModel channel)
{
channel.QueueDeclare(queue: _defaultQueue,
durable: true,
exclusive: false,
autoDelete: false,
arguments: null);
channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
Console.WriteLine("[*] Waiting for messages...");
}
示例6: Consumer
public Consumer(string hostName, string queueName)
{
QueueName = queueName;
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.HostName = hostName;
Connection = connectionFactory.CreateConnection();
Model = Connection.CreateModel();
Model.BasicQos(0,1,false);
bool durable = true;
Model.QueueDeclare(QueueName, durable, false, false, null);
}
示例7: CreateConnection
public void CreateConnection()
{
_factory = new ConnectionFactory { HostName = "localhost", UserName = "guest", Password = "guest" };
_connection = _factory.CreateConnection();
_channel = _connection.CreateModel();
_channel.QueueDeclare("rpc_queue", false, false, false, null);
_channel.BasicQos(0, 1, false);
_consumer = new QueueingBasicConsumer(_channel);
_channel.BasicConsume("rpc_queue", false, _consumer);
_rnd = new Random();
}
示例8: Declare
public virtual void Declare(IModel channel)
{
if (Name.StartsWith("amq.", StringComparison.OrdinalIgnoreCase) == false)
channel.QueueDeclare(
Name,
Durable,
Exclusive,
AutoDelete,
Args);
channel.BasicQos(0, 1, false);
}
示例9: ConfigureQos
protected void ConfigureQos(IModel channel, ushort prefetchCount)
{
/*
QoS is per consumer on channel. If ChannelFactory is used,
we might get a new channel than the one the consumer is
we are configuring.
*/
_logger.LogDebug($"Setting QoS\n Prefetch Size: 0\n Prefetch Count: {prefetchCount}\n global: false");
channel.BasicQos(
prefetchSize: 0, //TODO : what is this?
prefetchCount: prefetchCount,
global: false // https://www.rabbitmq.com/consumer-prefetch.html
);
}
示例10: ReceiveBufferedMessages
private static void ReceiveBufferedMessages(IModel model)
{
model.BasicQos(0, 1, false);
QueueingBasicConsumer consumer = new QueueingBasicConsumer(model);
model.BasicConsume(RabbitMqService.LargeMessageBufferedQueue, false, consumer);
while (true)
{
BasicDeliverEventArgs deliveryArguments = consumer.Queue.Dequeue() as BasicDeliverEventArgs;
byte[] messageContents = deliveryArguments.Body;
string randomFileName = string.Concat(@"c:\large_file_from_rabbit_", Guid.NewGuid(), ".txt");
Console.WriteLine("Received message, will save it to {0}", randomFileName);
File.WriteAllBytes(randomFileName, messageContents);
model.BasicAck(deliveryArguments.DeliveryTag, false);
}
}
示例11: DemoQueue
// This shows handling messages from a queue - each message is handled by a single worker
static void DemoQueue(IModel model)
{
model.QueueDeclare("myqueue", true, false, false, null);
model.BasicQos(0, 1, false);
var consumer = new QueueingBasicConsumer(model);
model.BasicConsume("myqueue", false, consumer);
while (true)
{
var message = consumer.Queue.Dequeue();
DoWork(message);
// Since BasicConsume is called with noAck: false, we need to manually let Rabbit know that the message was handled
model.BasicAck(message.DeliveryTag, false);
}
}
示例12: GetUserRegisteredConsumer
private static QueueingBasicConsumer GetUserRegisteredConsumer(out IModel channel)
{
var mqname = "UserRegisterWatcher";
channel = _mqpool.GetMQChannel(mqname);
var exchangeAndQueueName = Utilities.GetExchangeAndQueueNameOfUserRegistered();
channel.ExchangeDeclare(exchangeAndQueueName.Item1, ExchangeType.Direct, true, false, null);
channel.QueueDeclare(exchangeAndQueueName.Item2, true, false, false, null);
channel.QueueBind(exchangeAndQueueName.Item2, exchangeAndQueueName.Item1, string.Empty);
channel.BasicQos(0, 1, false);
var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(exchangeAndQueueName.Item2, false, consumer);
return consumer;
}
示例13: LauncherServerSendRequestToTShock
public LauncherServerSendRequestToTShock()
{
channel = OverallInformations.conn.CreateModel();
channel.ExchangeDeclare(exchange: OverallInformations.LauncherServerTShockExchange, type: "direct", durable: false, autoDelete: true, arguments: null);
replyQueueOk = channel.QueueDeclare();
channel.QueueBind(queue: replyQueueOk.QueueName, exchange: OverallInformations.LauncherServerTShockExchange, routingKey: replyQueueOk.QueueName, arguments: null);
channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, _ea) =>
{
ea = _ea;
LauncherReadyEvent.Set();
};
channel.BasicConsume(queue: replyQueueOk.QueueName, noAck: true, consumer: consumer);
}
示例14: ReceiveSerialisationMessages
private static void ReceiveSerialisationMessages(IModel model)
{
model.BasicQos(0, 1, false);
QueueingBasicConsumer consumer = new QueueingBasicConsumer(model);
model.BasicConsume(CommonService.SerialisationQueueName, false, consumer);
while (true)
{
BasicDeliverEventArgs deliveryArguments = consumer.Queue.Dequeue() as BasicDeliverEventArgs;
string contentType = deliveryArguments.BasicProperties.ContentType;
string objectType = deliveryArguments.BasicProperties.Type;
String jsonified = Encoding.UTF8.GetString(deliveryArguments.Body);
Customer customer = JsonConvert.DeserializeObject<Customer>(jsonified);
Console.WriteLine("Pure json: {0}", jsonified);
Console.WriteLine("Customer name: {0}", customer.Name);
model.BasicAck(deliveryArguments.DeliveryTag, false);
}
}
示例15: GetAddressGeneratorConsumer
private static QueueingBasicConsumer GetAddressGeneratorConsumer(CurrencyType currency, out IModel channel)
{
var mqname = "NXTAccountGenerator";
channel = _mqpool.GetMQChannel(mqname);
var exchangeAndQueueName = Utilities.GenerateExchangeAndQueueNameOfGenerateNewAddress(currency);
channel.ExchangeDeclare(exchangeAndQueueName.Item1, ExchangeType.Direct, true, false, null);
channel.QueueDeclare(exchangeAndQueueName.Item2, true, false, false, null);
channel.QueueBind(exchangeAndQueueName.Item2, exchangeAndQueueName.Item1, string.Empty);
channel.BasicQos(0, 1, false);
var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(exchangeAndQueueName.Item2, false, consumer);
return consumer;
}