Skip to content

Commit

Permalink
Adds RoutingKey class
Browse files Browse the repository at this point in the history
  • Loading branch information
toby.henderson committed Jun 13, 2017
1 parent b6a77b1 commit 83e66d3
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,23 @@ public DocumentService()
new InputChannelFactory(sqsMessageConsumerFactory, sqsMessageProducerFactory),
typeof(DocumentCreatedEvent),
new ChannelName("https://sqs.eu-west-1.amazonaws.com/027649620536/DocumentCreatedEvent"),
"DocumentCreatedEvent",
new RoutingKey("DocumentCreatedEvent"),
timeoutInMilliseconds: 5000,
noOfPerformers: 10),
new Connection(
new ConnectionName("paramore.example.documentsandfolders.documentupdatedevent"),
new InputChannelFactory(sqsMessageConsumerFactory, sqsMessageProducerFactory),
typeof(DocumentUpdatedEvent),
new ChannelName("https://sqs.eu-west-1.amazonaws.com/027649620536/DocumentUpdatedEvent"),
"DocumentUpdatedEvent",
new RoutingKey("DocumentUpdatedEvent"),
timeoutInMilliseconds: 5000,
noOfPerformers: 10),
new Connection(
new ConnectionName("paramore.example.documentsandfolders.foldercreateddevent"),
new InputChannelFactory(sqsMessageConsumerFactory, sqsMessageProducerFactory),
typeof(FolderCreatedEvent),
new ChannelName("https://sqs.eu-west-1.amazonaws.com/027649620536/FolderCreatedEvent"),
"FolderCreatedEvent",
new RoutingKey("FolderCreatedEvent"),
timeoutInMilliseconds: 5000,
noOfPerformers: 10)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ Dispatcher BuildDispatcher(HandlerConfig handlers)
var connections = new List<Connection>
{
// Generic Events
new Connection(new ConnectionName("Task.Added"),inputChannelFactory, typeof(GenericTaskAddedEvent), new ChannelName("Task.Added"), "Task.Added", noOfPerformers:1, timeoutInMilliseconds: 200),
new Connection(new ConnectionName("Task.Edited"),inputChannelFactory, typeof(GenericTaskEditedEvent), new ChannelName("Task.Edited"), "Task.Edited", noOfPerformers:1, timeoutInMilliseconds: 200),
new Connection(new ConnectionName("Task.Completed"),inputChannelFactory, typeof(GenericTaskCompletedEvent), new ChannelName("Task.Completed"), "Task.Completed", noOfPerformers:1, timeoutInMilliseconds: 200),
new Connection(new ConnectionName("Task.Added"),inputChannelFactory, typeof(GenericTaskAddedEvent), new ChannelName("Task.Added"), new RoutingKey("Task.Added"), noOfPerformers:1, timeoutInMilliseconds: 200),
new Connection(new ConnectionName("Task.Edited"),inputChannelFactory, typeof(GenericTaskEditedEvent), new ChannelName("Task.Edited"), new RoutingKey("Task.Edited"), noOfPerformers:1, timeoutInMilliseconds: 200),
new Connection(new ConnectionName("Task.Completed"),inputChannelFactory, typeof(GenericTaskCompletedEvent), new ChannelName("Task.Completed"),new RoutingKey( "Task.Completed"), noOfPerformers:1, timeoutInMilliseconds: 200),
};

return DispatchBuilder.With()
Expand Down
2 changes: 1 addition & 1 deletion samples/GreetingsCoreConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static void Main(string[] args)
new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory),
typeof(GreetingEvent),
new ChannelName("greeting.event"),
"greeting.event",
new RoutingKey("greeting.event"),
timeoutInMilliseconds: 200)
};

Expand Down
2 changes: 1 addition & 1 deletion samples/GreetingsWindowsService/GreetingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public GreetingService()
new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory),
typeof(GreetingEvent),
new ChannelName("greeting.event"),
"greeting.event",
new RoutingKey("greeting.event"),
timeoutInMilliseconds: 200)
};

Expand Down
4 changes: 2 additions & 2 deletions src/Paramore.Brighter.ServiceActivator/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Connection
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string RoutingKey { get; set; }
public RoutingKey RoutingKey { get; set; }

/// <summary>
/// Gets the channel.
Expand Down Expand Up @@ -119,7 +119,7 @@ public class Connection
/// <param name="unacceptableMessageLimit">The number of unacceptable messages to handle, before stopping reading from the channel</param>
/// <param name="channelName">The channel name</param>
/// <param name="isDurable">The durability of the queue</param>
public Connection(ConnectionName name, IAmAChannelFactory channelFactory, Type dataType, ChannelName channelName, string routingKey, int noOfPerformers = 1,
public Connection(ConnectionName name, IAmAChannelFactory channelFactory, Type dataType, ChannelName channelName, RoutingKey routingKey, int noOfPerformers = 1,
int timeoutInMilliseconds = 300, int requeueCount = -1, int requeueDelayInMilliseconds = 0, int unacceptableMessageLimit = 0, bool isDurable = false,
bool isAsync = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Connection Build()
_inputChannelFactory,
_type,
new ChannelName(_channelName),
_routingKey,
new RoutingKey(_routingKey),
timeoutInMilliseconds: _milliseconds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ a base naming scheme to allow centralized management.
_channelFactory,
typeof(ConfigurationCommand),
new ChannelName(hostName + "." + CONFIGURATION),
hostName + "." + CONFIGURATION
new RoutingKey(hostName + "." + CONFIGURATION)
);
//var connectionConfiguration = new ConnectionConfiguration()
//{
Expand All @@ -137,7 +137,7 @@ a base naming scheme to allow centralized management.
_channelFactory,
typeof(HeartbeatRequest),
new ChannelName(hostName + "." + HEARTBEAT),
hostName + "." + HEARTBEAT,
new RoutingKey(hostName + "." + HEARTBEAT),
isDurable:false
);

Expand Down
98 changes: 98 additions & 0 deletions src/Paramore.Brighter/RoutingKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
namespace Paramore.Brighter
{
/// <summary>
/// The name of a Routing Key used to wrap communication with a Broker
/// </summary>
public class RoutingKey
{
/// <summary>
/// Initializes a new instance of the <see cref="RoutingKey"/> class.
/// </summary>
/// <param name="name">The name.</param>
public RoutingKey(string name)
{
Value = name;
}

/// <summary>
/// Gets the name of the channel as a string.
/// </summary>
/// <value>The value.</value>
public string Value { get; }

/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
public override string ToString()
{
return Value;
}

/// <summary>
/// Performs an implicit conversion from <see cref="RoutingKey"/> to <see cref="System.String"/>.
/// </summary>
/// <param name="rhs">The RHS.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator string(RoutingKey rhs)
{
return rhs.ToString();
}

/// <summary>
/// Do the routing key name's match?
/// </summary>
/// <param name="other">The other.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public bool Equals(RoutingKey other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(Value, other.Value);
}

/// <summary>
/// Do the channel name's match?
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>
/// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((RoutingKey)obj);
}

/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public override int GetHashCode()
{
return Value?.GetHashCode() ?? 0;
}

/// <summary>
/// Implements the ==. Do the channel name's match?
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static bool operator ==(RoutingKey left, RoutingKey right)
{
return Equals(left, right);
}

/// <summary>
/// Implements the !=. Do the channel name's not match?
/// </summary>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static bool operator !=(RoutingKey left, RoutingKey right)
{
return !Equals(left, right);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MessageDispatcherRoutingAsyncTests()
timeoutInMilliseconds: 1000,
channelFactory: new InMemoryChannelFactory(_channel),
channelName: new ChannelName("fakeChannel"),
routingKey: "fakekey",
routingKey: new RoutingKey("fakekey"),
isAsync: true);
_dispatcher = new Dispatcher(_commandProcessor, messageMapperRegistry, new List<Connection> { connection });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public DispatcherAddNewConnectionTests()
var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MyEventMessageMapper()));
messageMapperRegistry.Register<MyEvent, MyEventMessageMapper>();

_connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
_newConnection = new Connection(new ConnectionName("newTest"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
_connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
_newConnection = new Connection(new ConnectionName("newTest"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
_dispatcher = new Dispatcher(_commandProcessor, messageMapperRegistry, new List<Connection> { _connection });

var @event = new MyEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public MessageDispatcherRoutingTests()
timeoutInMilliseconds: 1000,
channelFactory: new InMemoryChannelFactory(_channel),
channelName: new ChannelName("fakeChannel"),
routingKey: "fakekey");
routingKey: new RoutingKey("fakekey"));
_dispatcher = new Dispatcher(_commandProcessor, messageMapperRegistry, new List<Connection> { connection });

var @event = new MyEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public MessageDispatcherResetConnection()
var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MyEventMessageMapper()));
messageMapperRegistry.Register<MyEvent, MyEventMessageMapper>();

_connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
_connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
_dispatcher = new Dispatcher(_commandProcessor, messageMapperRegistry, new List<Connection> { _connection });

var @event = new MyEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public DispatcherRestartConnectionTests()
var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MyEventMessageMapper()));
messageMapperRegistry.Register<MyEvent, MyEventMessageMapper>();

_connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
_newConnection = new Connection(new ConnectionName("newTest"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
_connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
_newConnection = new Connection(new ConnectionName("newTest"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
_dispatcher = new Dispatcher(_commandProcessor, messageMapperRegistry, new List<Connection> { _connection, _newConnection });

var @event = new MyEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public MessageDispatcherShutConnectionTests()
var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MyEventMessageMapper()));
messageMapperRegistry.Register<MyEvent, MyEventMessageMapper>();

_connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 3, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
_connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 3, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(channel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
_dispatcher = new Dispatcher(commandProcessor, messageMapperRegistry, new List<Connection> { _connection });

var @event = new MyEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public MessageDispatcherMultipleConnectionTests()
messageMapperRegistry.Register<MyCommand, MyCommandMessageMapper>();


var myEventConnection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_eventChannel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
var myCommandConnection = new Connection(new ConnectionName("anothertest"), dataType: typeof(MyCommand), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_commandChannel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
var myEventConnection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_eventChannel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
var myCommandConnection = new Connection(new ConnectionName("anothertest"), dataType: typeof(MyCommand), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_commandChannel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
_dispatcher = new Dispatcher(commandProcessor, messageMapperRegistry, new List<Connection> { myEventConnection, myCommandConnection });

var @event = new MyEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public MessageDispatcherMultiplePerformerTests()
var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MyEventMessageMapper()));
messageMapperRegistry.Register<MyEvent, MyEventMessageMapper>();

var connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 3, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
var connection = new Connection(new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 3, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
_dispatcher = new Dispatcher(_commandProcessor, messageMapperRegistry, new List<Connection> { connection });

var @event = new MyEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public DispatchBuilderTests()
new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory),
typeof(MyEvent),
new ChannelName("mary"),
"bob",
new RoutingKey("bob"),
timeoutInMilliseconds: 200),
new Connection(
new ConnectionName("bar"),
new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory),
typeof(MyEvent),
new ChannelName("alice"),
"simon",
new RoutingKey("simon"),
timeoutInMilliseconds: 200)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public DispatchBuilderWithNamedGateway()
new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory),
typeof(MyEvent),
new ChannelName("mary"),
"bob",
new RoutingKey("bob"),
timeoutInMilliseconds: 200),
new Connection(
new ConnectionName("bar"),
new InputChannelFactory(rmqMessageConsumerFactory, rmqMessageProducerFactory),
typeof(MyEvent),
new ChannelName("alice"),
"simon",
new RoutingKey("simon"),
timeoutInMilliseconds: 200)
};

Expand Down

0 comments on commit 83e66d3

Please sign in to comment.