ConnectHandle IConsumerConnector.ConnectConsumer <T>(IConsumePipeConnector consumePipe, IConsumerFactory <T> consumerFactory, IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications) { var factory = consumerFactory as IConsumerFactory <TConsumer>; if (factory == null) { throw new ArgumentException("The consumer factory type does not match: " + TypeMetadataCache <T> .ShortName); } IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe = ConsumerPipeBuilder.BuildConsumerPipe(_consumeFilter, pipeSpecifications); IPipe <ConsumeContext <TMessage> > messagePipe = MessagePipeBuilder.BuildMessagePipe <TConsumer, TMessage, T>(pipeSpecifications, new ConsumerMessageFilter <TConsumer, TMessage>(factory, consumerPipe)); return(consumePipe.ConnectConsumePipe(messagePipe)); }
ConnectHandle IInstanceConnector.ConnectInstance <T>(IConsumePipeConnector consumePipe, T instance, IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } var consumer = instance as TConsumer; if (consumer == null) { throw new ConsumerException( $"The instance type {instance.GetType().GetTypeName()} does not match the consumer type: {TypeMetadataCache<TConsumer>.ShortName}"); } IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe = ConsumerPipeBuilder.BuildConsumerPipe(_consumeFilter, pipeSpecifications); IPipe <ConsumeContext <TMessage> > messagePipe = MessagePipeBuilder.BuildMessagePipe <TConsumer, TMessage, T>(pipeSpecifications, new InstanceMessageFilter <TConsumer, TMessage>(consumer, consumerPipe)); return(consumePipe.ConnectConsumePipe(messagePipe)); }