public void CanSendMessageWithSentException() { IAmqpConnectionFactory connectionFactory = A.Fake <IAmqpConnectionFactory>(); AmqpMessageBuilder messageBuilder = A.Fake <AmqpMessageBuilder>(); ISourceBlock <IMessage> sourceBlock = A.Fake <ISourceBlock <IMessage> >(); IConnection connection = A.Fake <IConnection>(); IAmqpProperties properties = A.Fake <IAmqpProperties>(); IModel channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); A.CallTo(() => channel.CreateBasicProperties()).Returns(null); A.CallTo(() => channel.BasicPublish( A <string> ._, A <string> ._, A <bool> ._, A <IBasicProperties> ._, A <byte[]> ._)) .Throws <Exception>() .Once(); A.CallTo(() => messageBuilder.Serialize(A <IMessage> ._)) .Returns(new AmqpMessage(properties, null, null, null)).Twice(); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); Result <AmqpMessage, ExceptionDispatchInfo> result = new Result <AmqpMessage, ExceptionDispatchInfo>( new AmqpMessage(new AmqpProperties(), string.Empty, string.Empty, new byte[0])); Action action = () => sut.Send(result); action.Should().NotThrow("because the AmqpSender should catch all exceptions to prevent from destroying of the DataFlow chain."); }
public AmqpSender(IAmqpConnectionFactory connectionFactory, IAmqpMessageBuilder amqpMessageBuilder, ILogServiceProvider logServiceProvider = null) { this.connectionFactory = connectionFactory; this.amqpMessageBuilder = amqpMessageBuilder; this.logServiceProvider = logServiceProvider ?? new NullLogServiceProvider(); this.logService = this.logServiceProvider.GetLogServiceOf(typeof(AmqpSender)); }
public async Task CanSendMessageAfterSentException() { // Arrange var channel = A.Fake <IModel>(); A.CallTo(() => channel.CreateBasicProperties()) .Returns(null); A.CallTo(() => channel.BasicPublish( A <string> ._, A <string> ._, A <bool> ._, A <IBasicProperties> ._, A <byte[]> ._)) .Throws <Exception>() .Once(); IAmqpConnectionFactory connectionFactory = GetConnectionFactory(channel); var tasks = new List <TaskCompletionSource <bool> >() { new TaskCompletionSource <bool>(), new TaskCompletionSource <bool>() }; var properties = A.Fake <IAmqpProperties>(); var messageBuilder = A.Fake <AmqpMessageBuilder>(); A.CallTo(() => messageBuilder.Serialize(A <IMessage> ._)) .ReturnsNextFromSequence(new AmqpMessage[] { new AmqpMessage(properties, null, null, new byte[1], tasks[0]), new AmqpMessage(properties, null, null, new byte[1], tasks[1]) }); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); var input = new BufferBlock <IMessage>(); sut.SubscribeTo(input); // Act input.Post(new Message <string>("hello", new Dictionary <string, string>(), tasks[0])); input.Post(new Message <string>("hello", new Dictionary <string, string>(), tasks[1])); // Assert await tasks[0].Task.ContinueWith(t => { t.Status.Should().Be(TaskStatus.Faulted); }); (await tasks[1].Task).Should().Be(true); }
/// <summary> /// 构造方法 /// </summary> /// <param name="amqpConfigReader">AMQP配置读取</param> /// <param name="connectionFactory">连接工厂</param> public AmqpRpcClientMethodBase(IAmqpConfigReader amqpConfigReader, IAmqpConnectionFactory connectionFactory) { if (amqpConfigReader == null) { this.amqpConfigReader = AmqpUtil.GetConfigReader(amqpConfigReader); } else { this.amqpConfigReader = amqpConfigReader; } this.connectionFactory = connectionFactory; }
public AsyncAmqpBasicConsumer( IAmqpConnectionFactory connectionFactory, IAmqpPropertyBuilder amqpPropertyBuilder, IAmqpMessageBuilder amqpMessageBuilder, bool continueOnCapturedContext, string queue) { this.connectionFactory = connectionFactory; this.amqpPropertyBuilder = amqpPropertyBuilder; this.amqpMessageBuilder = amqpMessageBuilder; this.continueOnCapturedContext = continueOnCapturedContext; this.queue = queue; }
public AsyncAmqpBasicConsumer( IAmqpConnectionFactory connectionFactory, IAmqpPropertyBuilder amqpPropertyBuilder, IAmqpMessageBuilder amqpMessageBuilder, bool continueOnCapturedContext, string queue, ILogServiceProvider logServiceProvder = null) { this.connectionFactory = connectionFactory; this.amqpPropertyBuilder = amqpPropertyBuilder; this.amqpMessageBuilder = amqpMessageBuilder; this.continueOnCapturedContext = continueOnCapturedContext; this.queue = queue; this.logServiceProvder = logServiceProvder ?? new NullLogServiceProvider(); this.logService = this.logServiceProvder.GetLogServiceOf(typeof(AsyncAmqpBasicConsumer <T>)); }
public void CanLinkTo() { IAmqpConnectionFactory connectionFactory = A.Fake <IAmqpConnectionFactory>(); AmqpMessageBuilder messageBuilder = A.Fake <AmqpMessageBuilder>(); ISourceBlock <IMessage> sourceBlock = A.Fake <ISourceBlock <IMessage> >(); IConnection connection = A.Fake <IConnection>(); IModel channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); ISubscriptionTag tag = sut.SubscribeTo(sourceBlock); tag.Id.Should().NotBeNull(); }
public void CanSendMessageWithSerializationException() { IAmqpConnectionFactory connectionFactory = A.Fake <IAmqpConnectionFactory>(); AmqpMessageBuilder messageBuilder = A.Fake <AmqpMessageBuilder>(); ISourceBlock <IMessage> sourceBlock = A.Fake <ISourceBlock <IMessage> >(); IConnection connection = A.Fake <IConnection>(); IAmqpProperties properties = A.Fake <IAmqpProperties>(); IModel channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); A.CallTo(() => messageBuilder.Serialize(A <IMessage> ._)) .Throws <Exception>() .Once() .Then. Returns(new AmqpMessage(properties, null, null, null)); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); IMessage message = new Message <string>("hello", new Dictionary <string, string>()); Action action = () => sut.Transform(message); action.Should().NotThrow("because the AmqpSender should catch all exception to prevent from destroying the DataFlow chain."); }
public WeatherForecastController(ILogger <WeatherForecastController> logger, IAmqpConnectionFactory factory) { _logger = logger; this.factory = factory; }
public IAmqpSubscriptionBuilder WithConnectionFactory(IAmqpConnectionFactory connectionFactory) { this.ConnectionFactory = connectionFactory; return(this); }
/// <summary> /// 构造方法 /// </summary> /// <param name="amqpConfigReader">AMQP配置读取</param> /// <param name="connectionFactory">连接工厂</param> public RabbitRpcClientMethod(IAmqpConfigReader amqpConfigReader, IAmqpConnectionFactory connectionFactory) : base(amqpConfigReader, connectionFactory) { }
/// <summary> /// 构造方法 /// </summary> /// <param name="connectionFactory">连接工厂</param> public AmqpRpcClientMethodBase(IAmqpConnectionFactory connectionFactory) : this(null, connectionFactory) { }
public AmqpSender(IAmqpConnectionFactory connectionFactory, IAmqpMessageBuilder amqpMessageBuilder) { this.connectionFactory = connectionFactory; this.amqpMessageBuilder = amqpMessageBuilder; }
public IAmqpPublishingBuilder WithConnectionFactory(IAmqpConnectionFactory connectionFactory) { this.ConnectionFactory = connectionFactory; return(this); }