Created
November 15, 2013 14:49
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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); |
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.
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
I think it's a useful feature to add! I have just one consideration:
If you send two different types on the same queue, let's say T1 and T2 and there's just one Receive for one of the type, let's say just for T1, then the consumer will start to consume all the messages in the queue, and call the actions just for T1 messages, am I right? What about the T2 messages? Are they just be lost or moved in some easynetq system queue (AbandonedMessages)? Or republished on the same queue (but I think is really bad!)?