本文整理汇总了C#中IModel.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IModel.Close方法的具体用法?C# IModel.Close怎么用?C# IModel.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModel
的用法示例。
在下文中一共展示了IModel.Close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseChannel
public static void CloseChannel(IModel channel)
{
if (channel != null)
{
try
{
channel.Close();
}
//TODO should this really be trace level?
catch (Exception ex)
{
logger.Trace("Unexpected exception on closing RabbitMQ Channel", ex);
}
}
}
示例2: CloseChannel
/// <summary>
/// Close the channel.
/// </summary>
/// <param name="channel">
/// The channel.
/// </param>
public static void CloseChannel(IModel channel)
{
if (channel != null && channel.IsOpen)
{
try
{
channel.Close();
}
catch (IOException ioex)
{
logger.Debug("Could not close RabbitMQ Channel", ioex);
}
catch (Exception ex)
{
logger.Debug("Unexpected exception on closing RabbitMQ Channel", ex);
}
}
}
示例3: receive
public String receive(String queueName)
{
Console.WriteLine(queueName);
Console.WriteLine("In RabbitMQ.receive");
string messageReceived = "";
Console.WriteLine("connectionFactory : " + connectionFactory);
using (connection = connectionFactory.CreateConnection())
{
Console.WriteLine("connection : " + connection);
using (channel = connection.CreateModel())
{
Console.WriteLine("channel : " + channel);
channel.QueueDeclare(queue: queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
EventingBasicConsumer consumer = new EventingBasicConsumer(channel);
Console.WriteLine("Requesting message");
consumer.Received += (Model, ea) =>
{
var body = ea.Body;
messageReceived = Encoding.UTF8.GetString(body);
Console.WriteLine("Message received : " + messageReceived);
};
channel.BasicConsume(queue: queueName,
noAck: true,
consumer: consumer);
Console.WriteLine("Waiting for message ...");
while (messageReceived == "") { } //menunggu hingga menerima pesan
channel.Close();
connection.Close();
return messageReceived;
}
}
}
示例4: CloseModel
public void CloseModel(IModel model, TimeSpan timeout)
{
model.Close((ushort) CurrentVersion.StatusCodes.Ok, "Goodbye");
}
示例5: ShutdownAmqp
private void ShutdownAmqp(IConnection connection, IModel model, ShutdownEventArgs reason)
{
try
{
if (connection != null)
{
connection.ConnectionShutdown -= ShutdownAmqp;
connection.AutoClose = true;
}
if (model != null)
{
model.ModelShutdown -= this.OnModelShutdown;
this.Debug("closing amqp model. {0}.", reason);
model.Close(Constants.ReplySuccess, "closing rabbitmq appender, shutting down logging");
model.Dispose();
this.Debug("amqp model closed.");
}
}
catch (Exception e)
{
ErrorHandler.Error("could not close model", e);
}
}
示例6: ConsumeAsync
private async void ConsumeAsync(IConnection connection)
{
await Task.Factory.StartNew(() =>
{
//Create a channel for the consuming thread
using (requestChannel = connection.CreateModel())
{
//Declare the exchange
requestChannel.ExchangeDeclare(ExchangeName, "topic");
//Decalre a temporary queue and bind it to the requests being sent to the exchange
var queueName = requestChannel.QueueDeclare().QueueName;
requestChannel.QueueBind(queueName, ExchangeName, RequestQueue);
//Create a consumer to get the request messages
var consumer = new QueueingBasicConsumer(requestChannel);
requestChannel.BasicConsume(queueName, true, consumer);
//Consume message queue
while (run)
{
BasicDeliverEventArgs ea;
if (!consumer.Queue.Dequeue(1000, out ea))
continue;
var isin = Encoding.UTF8.GetString(ea.Body);
//Check ISIN does not already exist - produce prices for the requested ISIN
if (!dataChannels.ContainsKey(isin))
ProduceAsync(connection, isin);
}
requestChannel.Close();
}
},
TaskCreationOptions.LongRunning);
Console.WriteLine("Stopped consuming requests");
}