/// <summary> /// Build a listener to handle requests of the given type using common options. /// </summary> /// <typeparam name="TRequest">The type of the request object</typeparam> /// <typeparam name="TResponse">The type of the response object</typeparam> /// <param name="messageBus">The message bus</param> /// <param name="build">The lambda function to build the listener</param> /// <returns>A token representing the subscription whic, when disposed, cancels the subscription</returns> public static IDisposable Listen <TRequest, TResponse>(this IReqResBus messageBus, Action <ITopicListenerBuilder <TRequest, TResponse> > build) { Assert.ArgumentNotNull(messageBus, nameof(messageBus)); var builder = new ListenerBuilder <TRequest, TResponse>(messageBus, messageBus.WorkerPool); build(builder); var listener = builder.BuildListener(); var token = messageBus.Listen(builder.Topic, listener); return(builder.WrapToken(token)); }
private static IDisposable BuildListener(IReqResBus messageBus, Func <TRequest, TResponse> func, Action <IThreadListenerBuilder <TRequest, TResponse> > build, string topic) { var token = messageBus.Listen <TRequest, TResponse>(b => { var c = b .WithTopic(topic) .Invoke(func); build?.Invoke(c); }); return(token); }
public IDisposable Listen(string topic, IListener <TRequest, TResponse> listener) { return(_messageBus.Listen(topic, listener)); }
private IDisposable ListenUntypedMethodInfoInternal <TRequest, TResponse>(string topic, object target, MethodInfo method, bool useWeakReference) { return(_messageBus.Listen <TRequest, TResponse>(b => b .WithTopic(topic) .Invoke(p => (TResponse)method.Invoke(target, new object[] { p }), useWeakReference))); }