Implement an Auto Responder?
See original GitHub issueLet me start by saying that I love the Auto Subscriber.
From what I can see in the wiki, the ārespondā side of the request/response pattern appears very similar to the āsubscribeā side of the publish/subscribe pattern (albeit, a little different; for example, thereās no subscription ID).
publish/subscribe
bus.Subscribe<MyMessage>("my_subscription_id", msg => Console.WriteLine(msg.Text));
request/response
bus.Respond<MyRequest, MyResponse>(request => new MyResponse { Text = āResponding to ā + request.Text});
That said, I still donāt want to manually manage and wire up all of the ārespondā handlers in my application. I figure we could provide an AutoResponder
just like the AutoSubscriber
.
Allow me to make some initial suggestions as to whatās required. Iām only just brushing up on the async and signature changes in the 4.0 release, so Iāll spec only the async methods, but I might get them a bit wrong as I browse the latest changes!
AutoRespond.cs
namespace EasyNetQ.AutoRespond
{
public class AutoResponder
{
protected readonly IBus bus;
public AutoResponder(IBus bus);
public IAutoResponderMessageDispatcher AutoResponderMessageDispatcher { get; set; }
public virtual async Task<IDisposable> RespondAsync(Type[] responderTypes, CancellationToken cancellationToken = default)
}
}
IAutoResponderMessageDispatcher.cs
namespace EasyNetQ.AutoRespond
{
public interface IAutoResponderMessageDispatcher
{
TResponse Dispatch<TRequest, TResponse, TResponder>(TRequest request, CancellationToken cancellationToken = default)
where TRequest : class
where TResponse : class
where TResponder : class, IRespond<TRequest, TResponse>;
Task<TResponse> DispatchAsync<TRequest, TResponse, TResponder>(TRequest request, CancellationToken cancellationToken = default)
where TRequest : class
where TResponse : class
where TResponder : class, IRespondAsync<TRequest, TResponse>;
}
}
IRespond.cs
namespace EasyNetQ.AutoRespond
{
public interface IRespond<TRequest, TResponse>
where TRequest : class
where TResponse : class
{
TResponse Respond(TRequest request, CancellationToken cancellationToken = default);
}
}
IRespondAsync.cs
namespace EasyNetQ.AutoRespond
{
public interface IRespondAsync<TRequest, TResponse>
where TRequest : class
where TResponse : class
{
Task<TResponse> RespondAsync(TRequest request, CancellationToken cancellationToken = default);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Obviously, let me know if this is something you even want. I canāt think of why you wouldnāt but, hey, itās not my project š¤
Iām getting the same feelings working through the send/receive patternā¦
https://github.com/EasyNetQ/EasyNetQ/wiki/Send-Receive
Iām actually implementing the āautoā classes now in a private project. If they work out and youāre interested, after all, Iāll send up a PR. To go a step further, if you want auto subscribe, respond, and receive and the impl. ends up looking goodā¦ would you consider an even more generic āauto wire allā?
OK! Iām willing to tackle thisā¦ I can start something under my own account, link it here, and see how it turns out? What do you think about the term āAutoRegistrationā as an umbrella to cover all of the relevant messaging patterns?