Skip to content

Commit

Permalink
Merge pull request EasyNetQ#35 from gediminasgu/master
Browse files Browse the repository at this point in the history
Autodelete for exchanges
  • Loading branch information
Mike Hadlow committed Aug 23, 2012
2 parents 2f9da3c + b3f9c9a commit 91a21c6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
45 changes: 44 additions & 1 deletion Source/EasyNetQ/Topology/Exchange.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -9,6 +10,8 @@ public class Exchange : IExchange
protected readonly IList<IBinding> bindings = new List<IBinding>();
public string Name { get; private set; }
public string ExchangeType { get; private set; }
public bool AutoDelete { get; private set; }
public IDictionary Arguments { get; private set; }

public static IExchange DeclareDirect(string exchangeName)
{
Expand All @@ -19,6 +22,15 @@ public static IExchange DeclareDirect(string exchangeName)
return new Exchange(exchangeName, Topology.ExchangeType.Direct);
}

public static IExchange DeclareDirect(string exchangeName, bool autoDelete, IDictionary arguments)
{
if (string.IsNullOrEmpty(exchangeName))
{
throw new ArgumentException("name is null or empty");
}
return new Exchange(exchangeName, Topology.ExchangeType.Direct, autoDelete, arguments);
}

public static IExchange DeclareTopic(string exchangeName)
{
if (string.IsNullOrEmpty(exchangeName))
Expand All @@ -28,6 +40,15 @@ public static IExchange DeclareTopic(string exchangeName)
return new Exchange(exchangeName, Topology.ExchangeType.Topic);
}

public static IExchange DeclareTopic(string exchangeName, bool autoDelete, IDictionary arguments)
{
if (string.IsNullOrEmpty(exchangeName))
{
throw new ArgumentException("name is null or empty");
}
return new Exchange(exchangeName, Topology.ExchangeType.Topic, autoDelete, arguments);
}

public static IExchange DeclareFanout(string exchangeName)
{
if (string.IsNullOrEmpty(exchangeName))
Expand All @@ -37,6 +58,15 @@ public static IExchange DeclareFanout(string exchangeName)
return new Exchange(exchangeName, Topology.ExchangeType.Fanout);
}

public static IExchange DeclareFanout(string exchangeName, bool autoDelete, IDictionary arguments)
{
if (string.IsNullOrEmpty(exchangeName))
{
throw new ArgumentException("name is null or empty");
}
return new Exchange(exchangeName, Topology.ExchangeType.Fanout, autoDelete, arguments);
}

public static IExchange GetDefault()
{
return new DefaultExchange();
Expand All @@ -53,6 +83,19 @@ protected Exchange(string name, string exchangeType)
ExchangeType = exchangeType;
}

protected Exchange(string name, string exchangeType, bool autoDelete, IDictionary arguments)
{
if (name == null)
{
throw new ArgumentNullException("name");
}

Name = name;
ExchangeType = exchangeType;
AutoDelete = autoDelete;
Arguments = arguments;
}

public virtual void Visit(ITopologyVisitor visitor)
{
if (visitor == null)
Expand All @@ -61,7 +104,7 @@ public virtual void Visit(ITopologyVisitor visitor)
}
if (Name != string.Empty)
{
visitor.CreateExchange(Name, ExchangeType);
visitor.CreateExchange(Name, ExchangeType, AutoDelete, Arguments);
foreach (var binding in bindings)
{
binding.Visit(visitor);
Expand Down
3 changes: 2 additions & 1 deletion Source/EasyNetQ/Topology/ITopologyVisitor.cs
@@ -1,10 +1,11 @@
using System.Collections;
using System.Collections.Generic;

namespace EasyNetQ.Topology
{
public interface ITopologyVisitor
{
void CreateExchange(string exchangeName, string exchangeType);
void CreateExchange(string exchangeName, string exchangeType, bool autoDelete, IDictionary arguments);
void CreateQueue(string queueName, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object> arguments);
string CreateQueue();
void CreateBinding(IBindable bindable, IExchange exchange, string[] routingKeys);
Expand Down
4 changes: 2 additions & 2 deletions Source/EasyNetQ/Topology/TopologyBuilder.cs
Expand Up @@ -20,14 +20,14 @@ public TopologyBuilder(IModel model)
this.model = model;
}

public void CreateExchange(string exchangeName, string exchangeType)
public void CreateExchange(string exchangeName, string exchangeType, bool autoDelete, IDictionary arguments)
{
if(exchangeName == null)
{
throw new ArgumentNullException("exchangeName");
}

model.ExchangeDeclare(exchangeName, exchangeType, true);
model.ExchangeDeclare(exchangeName, exchangeType, true, autoDelete, arguments);
}

public void CreateQueue(string queueName, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object> arguments)
Expand Down

0 comments on commit 91a21c6

Please sign in to comment.