Skip to content

Instantly share code, notes, and snippets.

@mikehadlow
Created November 15, 2013 14:49
Show Gist options
  • Save mikehadlow/7485471 to your computer and use it in GitHub Desktop.
Save mikehadlow/7485471 to your computer and use it in GitHub Desktop.
EasyNetQ's proposed new send/receive API. This is for sending messages explicitly to a named destination queue via the default exchange. The Receive call creates a consumer for the specified message type. Further calls to Receive with the same queue, but a different message type will add additional message handlers to the same consumer.
/// <summary>
/// Send a message directly to a queue
/// </summary>
/// <typeparam name="T">The type of message to send</typeparam>
/// <param name="queue">The queue to send to</param>
/// <param name="message">The message</param>
void Send<T>(string queue, T message);
/// <summary>
/// Receive messages from a queue.
/// Multiple calls to Receive for the same queue, but with different message types
/// will add multiple message handlers to the same consumer.
/// </summary>
/// <typeparam name="T">The type of message to receive</typeparam>
/// <param name="queue">The queue to receive from</param>
/// <param name="onMessage">The message handler</param>
void Receive<T>(string queue, Action<T> onMessage);
/// <summary>
/// Receive messages from a queue.
/// Multiple calls to Receive for the same queue, but with different message types
/// will add multiple message handlers to the same consumer.
/// </summary>
/// <typeparam name="T">The type of message to receive</typeparam>
/// <param name="queue">The queue to receive from</param>
/// <param name="onMessage">The asychronous message handler</param>
void Receive<T>(string queue, Func<T, Task> onMessage);
@mikehadlow
Copy link
Author

Currently EasyNetQ will throw an exception when it receives a message for which it has no handler. So the message will end up in the EasyNetQ error queue.

@micdenny
Copy link

That's fine, I think it's robust enough, and it can be a good enhancement. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment