public async Task DeclareAsync() { bool exists = await _bunny.ExchangeExistsAsync(Name); if (exists) { return; } IModel channel = null; try { channel = _bunny.Channel(newOne: true); await Task.Run(() => { channel.ExchangeDeclare(Name, ExchangeType, Durable, AutoDelete, _args); }); } catch (System.Exception exc) { throw DeclarationException.DeclareFailed(exc, "exchange-declare failed!"); } finally { channel.Close(); } }
internal static async Task <bool> ExchangeExistsAsync(this IBunny bunny, string name) { try { var channel = bunny.Channel(newOne: true); await Task.Run(() => channel.ExchangeDeclarePassive(name)); return(true); } catch (RabbitMQ.Client.Exceptions.OperationInterruptedException) { return(false); } catch (Exception ex) { throw DeclarationException.DeclareFailed(ex); } }
internal static async Task <bool> QueueExistsAsync(this IBunny bunny, string name) { try { var channel = bunny.Channel(newOne: true); var result = await new TaskFactory().StartNew <QueueDeclareOk>(() => channel.QueueDeclarePassive(name)); return(true); } catch (RabbitMQ.Client.Exceptions.OperationInterruptedException) { return(false); } catch (Exception ex) { throw DeclarationException.DeclareFailed(ex); } }