/// <summary> /// Connects a client factory to a host receive endpoint, using the bus as the send endpoint provider /// </summary> /// <param name="receiveEndpointHandle"> /// A handle to the receive endpoint, which is stopped when the client factory is disposed /// </param> /// <param name="timeout"></param> /// <returns></returns> public static async Task <IClientFactory> CreateClientFactory(this HostReceiveEndpointHandle receiveEndpointHandle, RequestTimeout timeout = default) { var ready = await receiveEndpointHandle.Ready.ConfigureAwait(false); var context = new HostReceiveEndpointClientFactoryContext(receiveEndpointHandle, ready, timeout); return(new ClientFactory(context)); }
/// <summary> /// Creates a request client factory which can be used to create a request client per message within a consume context. /// </summary> /// <typeparam name="TRequest"></typeparam> /// <typeparam name="TResponse"></typeparam> /// <param name="host">The host for the response endpoint</param> /// <param name="destinationAddress">The service address</param> /// <param name="timeout">The request timeout</param> /// <param name="timeToLive">The request time to live</param> /// <param name="callback">Customize the send context</param> /// <returns></returns> public static async Task <IRequestClientFactory <TRequest, TResponse> > CreateRequestClientFactory <TRequest, TResponse>(this IRabbitMqHost host, Uri destinationAddress, TimeSpan timeout, TimeSpan?timeToLive = default, Action <SendContext <TRequest> > callback = null) where TRequest : class where TResponse : class { var receiveEndpointHandle = ConnectResponseEndpoint(host); var ready = await receiveEndpointHandle.Ready.ConfigureAwait(false); var context = new HostReceiveEndpointClientFactoryContext(receiveEndpointHandle, ready, timeout); IClientFactory clientFactory = new ClientFactory(context); return(new MessageRequestClientFactory <TRequest, TResponse>(context, clientFactory, destinationAddress, timeToLive, callback)); }
/// <summary> /// Creates a request client factory which can be used to create a request client per message within a consume context. /// </summary> /// <typeparam name="TRequest"></typeparam> /// <typeparam name="TResponse"></typeparam> /// <param name="host">The host for the response endpoint</param> /// <param name="timeout">The request timeout</param> /// <param name="timeToLive">The request time to live</param> /// <param name="callback">Customize the send context</param> /// <returns></returns> public static async Task <IRequestClientFactory <TRequest, TResponse> > CreatePublishRequestClientFactory <TRequest, TResponse>(this IInMemoryHost host, TimeSpan timeout, TimeSpan?timeToLive = default, Action <SendContext <TRequest> > callback = null) where TRequest : class where TResponse : class { var receiveEndpointHandle = host.ConnectReceiveEndpoint(host.Topology.CreateTemporaryResponseQueueName()); var ready = await receiveEndpointHandle.Ready.ConfigureAwait(false); var context = new HostReceiveEndpointClientFactoryContext(receiveEndpointHandle, ready, timeout); IClientFactory clientFactory = new ClientFactory(context); return(new MessageRequestClientFactory <TRequest, TResponse>(context, clientFactory, null, timeToLive, callback)); }