public void SetUp() { persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); var eventBus = MockRepository.GenerateStub<IEventBus>(); var configuration = new ConnectionConfiguration { Timeout = 1 }; var shutdownArgs = new ShutdownEventArgs( ShutdownInitiator.Peer, AmqpException.ConnectionClosed, "connection closed by peer"); var exception = new OperationInterruptedException(shutdownArgs); persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x => { throw exception; }); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); }
public ExclusiveConsumer( IQueue queue, Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection, IConsumerConfiguration configuration, IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus ) { Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory"); Preconditions.CheckNotNull(eventBus, "eventBus"); Preconditions.CheckNotNull(configuration, "configuration"); this.queue = queue; this.onMessage = onMessage; this.connection = connection; this.configuration = configuration; this.internalConsumerFactory = internalConsumerFactory; this.eventBus = eventBus; timer = new Timer(s => { StartConsumer(); ((Timer)s).Change(10000, -1); }); timer.Change(10000, -1); }
public void SetUp() { persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); channel = MockRepository.GenerateStub<IModel>(); var eventBus = new EventBus(); var configuration = new ConnectionConfiguration(); var shutdownArgs = new ShutdownEventArgs( ShutdownInitiator.Peer, AmqpException.ConnectionClosed, "connection closed by peer"); var exception = new OperationInterruptedException(shutdownArgs); var first = true; persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x => { if (first) { first = false; throw exception; } x.ReturnValue = channel; }); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite); persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct")); }
public void SetUp() { eventBus = new EventBus(); internalConsumers = new List<IInternalConsumer>(); createConsumerCalled = 0; mockBuilder = new MockBuilder(); queue = new Queue(queueName, false); onMessage = (body, properties, info) => Task.Factory.StartNew(() => { }); persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); internalConsumerFactory = MockRepository.GenerateStub<IInternalConsumerFactory>(); internalConsumerFactory.Stub(x => x.CreateConsumer()).WhenCalled(x => { var internalConsumer = MockRepository.GenerateStub<IInternalConsumer>(); internalConsumers.Add(internalConsumer); createConsumerCalled++; x.ReturnValue = internalConsumer; }).Repeat.Any(); consumer = new PersistentConsumer( queue, onMessage, persistentConnection, internalConsumerFactory, eventBus); AdditionalSetup(); }
public void SetUp() { persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); persistentConnection.Stub(x => x.CreateModel()); var configuration = new ConnectionConfiguration(); eventBus = new EventBus(); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); var persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); }
public RabbitBus( SerializeType serializeType, ISerializer serializer, IConsumerFactory consumerFactory, IConnectionFactory connectionFactory, IEasyNetQLogger logger, Func <string> getCorrelationId, IConventions conventions = null, ushort prefetchCount = 1000) { if (serializeType == null) { throw new ArgumentNullException("serializeType"); } if (serializer == null) { throw new ArgumentNullException("serializer"); } if (consumerFactory == null) { throw new ArgumentNullException("consumerFactory"); } if (connectionFactory == null) { throw new ArgumentNullException("connectionFactory"); } if (getCorrelationId == null) { throw new ArgumentNullException("getCorrelationId"); } _prefetchCount = prefetchCount; // Use default conventions if none were supplied. if (conventions == null) { conventions = new Conventions(); } this.serializeType = serializeType; this.consumerFactory = consumerFactory; this.logger = logger; this.serializer = serializer; this.getCorrelationId = getCorrelationId; this.conventions = conventions; connection = new PersistentConnection(connectionFactory, logger); connection.Connected += OnConnected; connection.Disconnected += consumerFactory.ClearConsumers; connection.Disconnected += OnDisconnected; subscribeActions = new ConcurrentBag <Action>(); }
public ClientCommandDispatcherSingleton( IPersistentConnection connection, IPersistentChannelFactory persistentChannelFactory) { Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(persistentChannelFactory, "persistentChannelFactory"); persistentChannel = persistentChannelFactory.CreatePersistentChannel(connection); StartDispatcherThread(); }
public void SetUp() { var logger = new ConsoleLogger(); var eventBus = new EventBus(); var parser = new ConnectionStringParser(); var configuration = parser.Parse("host=localhost"); var hostSelectionStrategy = new RandomClusterHostSelectionStrategy<ConnectionFactoryInfo>(); var connectionFactory = new ConnectionFactoryWrapper(configuration, hostSelectionStrategy); connection = new PersistentConnection(connectionFactory, logger, eventBus); persistentChannel = new PersistentChannel(connection, logger, configuration, new EventBus()); }
public void SetUp() { persistentConnection = MockRepository.GenerateStub <IPersistentConnection>(); persistentConnection.Stub(x => x.CreateModel()); var configuration = new ConnectionConfiguration(); eventBus = new EventBus(); var logger = MockRepository.GenerateStub <IEasyNetQLogger>(); var persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); }
public PersistentChannelTests() { var eventBus = new EventBus(); var parser = new ConnectionStringParser(); var configuration = parser.Parse("host=localhost"); var hostSelectionStrategy = new RandomClusterHostSelectionStrategy <ConnectionFactoryInfo>(); var connectionFactory = new ConnectionFactoryWrapper(configuration, hostSelectionStrategy); connection = new PersistentConnection(connectionFactory, eventBus); persistentChannel = new PersistentChannel(connection, configuration, new EventBus()); connection.Initialize(); }
/// <summary> /// Create the correct implementation of IConsumer based on queue properties /// </summary> /// <param name="queue"></param> /// <param name="onMessage"></param> /// <param name="connection"></param> /// <returns></returns> private IConsumer CreateConsumerInstance( IQueue queue, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection) { if (queue.IsExclusive) { return(new TransientConsumer(queue, onMessage, connection, internalConsumerFactory, eventBus)); } return(new PersistentConsumer(queue, onMessage, connection, internalConsumerFactory, eventBus)); }
public BusClient(IPersistentConnection persistentConnection, ILogger <BusClient> logger, string queueName = null, int retryCount = 5) { _persistentConnection = persistentConnection; _logger = logger; _queueName = queueName; _retryCount = retryCount; _consumerChannel = CreateConsumerChannel(); EventSubscriptions = new Dictionary <Type, HashSet <Type> >(); CommandSubscription = new Dictionary <Type, HashSet <Type> >(); }
/// <summary> /// Create the correct implementation of IConsumer based on queue properties /// </summary> /// <param name="queue"></param> /// <param name="onMessage"></param> /// <param name="connection"></param> /// <returns></returns> private IConsumer CreateConsumerInstance( IQueue queue, Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection) { if (queue.IsExclusive) { return new TransientConsumer(queue, onMessage, connection, internalConsumerFactory, eventBus); } return new PersistentConsumer(queue, onMessage, connection, internalConsumerFactory, eventBus); }
public StartConsumingStatus StartConsuming( IPersistentConnection connection, IQueue queue, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IConsumerConfiguration configuration ) { Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(configuration, "configuration"); var consumerTag = conventions.ConsumerTagConvention(); IDictionary <string, object> arguments = new Dictionary <string, object> { { "x-priority", configuration.Priority }, { "x-cancel-on-ha-failover", configuration.CancelOnHaFailover || connectionConfiguration.CancelOnHaFailover } }; try { Model = connection.CreateModel(); var basicConsumers = new BasicConsumer(SingleBasicConsumerCancelled, consumerDispatcher, queue, eventBus, handlerRunner, onMessage, logger, Model); this.basicConsumers = new[] { new BasicConsumer(SingleBasicConsumerCancelled, consumerDispatcher, queue, eventBus, handlerRunner, onMessage, logger, Model) }; Model.BasicQos(0, configuration.PrefetchCount, false); //// if configured, re-establish the consumer on a ConsumerCancelled event. //if (queue.IsConsumerRepairable) // ConsumerCancelled += (sender, args) => ConsumerReConnect(sender, consumerTag, configuration.IsExclusive, arguments,queue); Model.BasicConsume( queue.Name, // queue false, // noAck consumerTag, // consumerTag true, configuration.IsExclusive, arguments, // arguments basicConsumers); // consumer logger.InfoWrite("Declared Consumer. queue='{0}', consumer tag='{1}' prefetchcount={2} priority={3} x-cancel-on-ha-failover={4}", queue.Name, consumerTag, configuration.PrefetchCount, configuration.Priority, configuration.CancelOnHaFailover); } catch (Exception exception) { logger.ErrorWrite("Consume failed. queue='{0}', consumer tag='{1}', message='{2}'", queue.Name, consumerTag, exception.Message); return(StartConsumingStatus.Failed); } return(StartConsumingStatus.Succeed); }
public IConsumer CreateConsumer( ICollection <Tuple <IQueue, Func <byte[], MessageProperties, MessageReceivedInfo, Task> > > queueConsumerPairs, IPersistentConnection connection, IConsumerConfiguration configuration) { if (configuration.IsExclusive || queueConsumerPairs.Any(x => x.Item1.IsExclusive)) { throw new NotSupportedException("Exclusive multiple consuming is not supported."); } return(new PersistentMultipleConsumer(queueConsumerPairs, connection, configuration, internalConsumerFactory, eventBus)); }
public ConsumerErrorStrategy( IPersistentConnection connection, ISerializer serializer, IConventions conventions, ITypeNameSerializer typeNameSerializer, IErrorMessageSerializer errorMessageSerializer, ConnectionConfiguration connectionConfiguration, IServiceProvider serviceProvider) : base( connection, serializer, conventions, typeNameSerializer, errorMessageSerializer, connectionConfiguration) { _logger = serviceProvider.GetService <ILogger <ConsumerErrorStrategy> >(); }
public void SetUp() { var logger = new ConsoleLogger(); var eventBus = new EventBus(); var parser = new ConnectionStringParser(); var configuration = parser.Parse("host=localhost"); var hostSelectionStrategy = new RandomClusterHostSelectionStrategy <ConnectionFactoryInfo>(); var connectionFactory = new ConnectionFactoryWrapper(configuration, hostSelectionStrategy); connection = new PersistentConnection(connectionFactory, logger, eventBus); persistentChannel = new PersistentChannel(connection, logger, configuration, new EventBus()); }
public RabbitMQEventBus(IEventBusSubscriptionManager subscriptionManager, IPersistentConnection connection, string exchangeName, string queueName, ILogger <RabbitMQEventBus> logger, IServiceProvider services) { _subscriptionManager = subscriptionManager; _subscriptionManager.OnEventRemoved += SubscriptionManager_OnEventRemoved; _connection = connection; _exchangeName = exchangeName; _queueName = queueName; _logger = logger; _consumerChannel = CreateConsumerChannel(); _serviceProvider = services; }
public ClientCommandDispatcherSingleton( ConnectionConfiguration configuration, IPersistentConnection connection, IPersistentChannelFactory persistentChannelFactory) { Preconditions.CheckNotNull(configuration, "configuration"); Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(persistentChannelFactory, "persistentChannelFactory"); persistentChannel = persistentChannelFactory.CreatePersistentChannel(connection); channelSemaphore = new SemaphoreSlim(queueSize, queueSize); }
public ObjClient( string url , Func <string, IPersistentConnection> clientFactory , SerializationConfig sconfig) { _SerConfig = sconfig; _Client = clientFactory(url); _Stream = new ConnectionStream(_Client); _Splitter = sconfig.SplitterFactory(_Stream); _Splitter.OnReceiveBlock += OnReceiveBlock; _Client.StartConnect(); _LastReceiveTick = System.Environment.TickCount; }
public void SetUp() { var eventBus = new EventBus(); var logger = new ConsoleLogger(); var parser = new ConnectionStringParser(); var configuration = parser.Parse("host=localhost"); var hostSelectionStrategy = new DefaultClusterHostSelectionStrategy<ConnectionFactoryInfo>(); var connectionFactory = new ConnectionFactoryWrapper(configuration, hostSelectionStrategy); connection = new PersistentConnection(connectionFactory, logger, eventBus); var persistentChannelFactory = new PersistentChannelFactory(logger, configuration, eventBus); dispatcher = new ClientCommandDispatcher(connection, persistentChannelFactory); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (!_LeaveOpen) { var disp = _Con as IDisposable; if (disp != null) { disp.Dispose(); } } _Con = null; }
public IConsumer CreateConsumer( IQueue queue, Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection) { Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(connection, "connection"); var consumer = CreateConsumerInstance(queue, onMessage, connection); consumers.TryAdd(consumer, null); return consumer; }
public EventBus(IPersistentConnection serviceBusPersisterConnection, ILogger <EventBus> logger, IEventBusSubscriptionsManager subsManager, string subscriptionClientName, ILifetimeScope autofac) { _serviceBusPersisterConnection = serviceBusPersisterConnection; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _subsManager = subsManager ?? new InMemoryEventBusSubscriptionsManager(); _queueClient = _serviceBusPersisterConnection.CreateQueue(); _autofac = autofac; RegisterOnMessageHandlerAndReceiveMessages(); //RegisterSubscriptionClientMessageHandler(); }
public IConsumer CreateConsumer( IQueue queue, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection) { Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(connection, "connection"); var consumer = CreateConsumerInstance(queue, onMessage, connection); consumers.TryAdd(consumer, null); return(consumer); }
public void SetUp() { var eventBus = new EventBus(); var logger = new ConsoleLogger(); var parser = new ConnectionStringParser(); var configuration = parser.Parse("host=localhost"); var hostSelectionStrategy = new DefaultClusterHostSelectionStrategy <ConnectionFactoryInfo>(); var connectionFactory = new ConnectionFactoryWrapper(configuration, hostSelectionStrategy); connection = new PersistentConnection(connectionFactory, logger, eventBus); var persistentChannelFactory = new PersistentChannelFactory(logger, configuration, eventBus); dispatcher = new ClientCommandDispatcher(connection, persistentChannelFactory); }
public When_a_channel_action_is_invoked() { persistentConnection = Substitute.For <IPersistentConnection>(); channel = Substitute.For <IModel>(); var configuration = new ConnectionConfiguration(); eventBus = Substitute.For <IEventBus>(); persistentConnection.CreateModel().Returns(channel); persistentChannel = new PersistentChannel(persistentConnection, configuration, eventBus); persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct")); }
public ClientCommandDispatcherSingleton( ConnectionConfiguration configuration, IPersistentConnection connection, IPersistentChannelFactory persistentChannelFactory) { Preconditions.CheckNotNull(configuration, "configuration"); Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(persistentChannelFactory, "persistentChannelFactory"); queue = new BlockingCollection <Action>(configuration.DispatcherQueueSize); persistentChannel = persistentChannelFactory.CreatePersistentChannel(connection); StartDispatcherThread(configuration); }
public void SetUp() { persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); channel = MockRepository.GenerateStub<IModel>(); var configuration = new ConnectionConfiguration(); eventBus = MockRepository.GenerateStub<IEventBus>(); persistentConnection.Stub(x => x.CreateModel()).Return(channel); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"),DateTime.UtcNow ); }
public StartConsumingStatus StartConsuming( IPersistentConnection connection, IQueue queue, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IConsumerConfiguration configuration ) { Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(configuration, "configuration"); this.queue = queue; this.onMessage = onMessage; this.configuration = configuration; var consumerTag = conventions.ConsumerTagConvention(); IDictionary <string, object> arguments = new Dictionary <string, object> { { "x-priority", configuration.Priority }, { "x-cancel-on-ha-failover", configuration.CancelOnHaFailover || connectionConfiguration.CancelOnHaFailover } }; try { Model = connection.CreateModel(); Model.BasicQos(0, configuration.PrefetchCount, false); Model.BasicConsume( queue.Name, // queue false, // noAck consumerTag, // consumerTag true, configuration.IsExclusive, arguments, // arguments this); // consumer logger.InfoWrite("Declared Consumer. queue='{0}', consumer tag='{1}' prefetchcount={2} priority={3} x-cancel-on-ha-failover={4}", queue.Name, consumerTag, configuration.PrefetchCount, configuration.Priority, configuration.CancelOnHaFailover); } catch (Exception exception) { logger.ErrorWrite("Consume failed. queue='{0}', consumer tag='{1}', message='{2}'", queue.Name, consumerTag, exception.Message); return(StartConsumingStatus.Failed); } return(StartConsumingStatus.Succeed); }
public void SetUp() { persistentConnection = MockRepository.GenerateStub <IPersistentConnection>(); channel = MockRepository.GenerateStub <IModel>(); var configuration = new ConnectionConfiguration(); eventBus = MockRepository.GenerateStub <IEventBus>(); persistentConnection.Stub(x => x.CreateModel()).Return(channel); var logger = MockRepository.GenerateStub <IEasyNetQLogger>(); persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct")); }
public PersistentChannel( IPersistentConnection connection, ConnectionConfiguration configuration, IEventBus eventBus) { Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(configuration, "configuration"); Preconditions.CheckNotNull(eventBus, "eventBus"); this.connection = connection; this.configuration = configuration; this.eventBus = eventBus; WireUpEvents(); }
public TransientConsumer( IQueue queue, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection, IConsumerConfiguration configuration, IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus) { this.queue = queue; this.onMessage = onMessage; this.connection = connection; this.configuration = configuration; this.internalConsumerFactory = internalConsumerFactory; this.eventBus = eventBus; }
public RabbitMQEventBus(IPersistentConnection persistentConnection, IEventBusSubscriptionsManager subscriptionManager, ILogger <RabbitMQEventBus> logger, IConfiguration configuration, IServiceProvider serviceProvider, int retryCount = 5) { QueueName = configuration.GetSection("RabbitMqConnection")["QueueName"]; PersistentConnection = persistentConnection; SubscriptionManager = subscriptionManager; ServiceProvider = serviceProvider; Logger = logger; RetryCount = retryCount; ConsumerChannel = CreateConsumerChannel(); }
private static DefaultConsumerErrorStrategy CreateConsumerErrorStrategy( IPersistentConnection persistedConnectionMock, bool configurePublisherConfirm = false) { var consumerErrorStrategy = new DefaultConsumerErrorStrategy( persistedConnectionMock, Substitute.For <ISerializer>(), Substitute.For <IConventions>(), Substitute.For <ITypeNameSerializer>(), Substitute.For <IErrorMessageSerializer>(), new ConnectionConfiguration { PublisherConfirms = configurePublisherConfirm }); return(consumerErrorStrategy); }
/// <summary> /// Creates ConsumerFactory /// </summary> /// <param name="connection">The connection</param> /// <param name="internalConsumerFactory">The internal consumer factory</param> /// <param name="eventBus">The event bus</param> public ConsumerFactory( IPersistentConnection connection, IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus ) { Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory"); Preconditions.CheckNotNull(eventBus, "eventBus"); this.connection = connection; this.internalConsumerFactory = internalConsumerFactory; this.eventBus = eventBus; eventBus.Subscribe <StoppedConsumingEvent>(@event => consumers.Remove(@event.Consumer)); }
public QueueProvider( IPersistentConnection persistentConnection, ISubscriptionManager subsManager, ILifetimeScope autofac, string queueName = null, int retryCount = 5) { _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection)); _subsManager = subsManager; _autofac = autofac; _queueName = queueName; _consumerChannel = CreateConsumerChannel(); _retryCount = retryCount; //_subsManager.OnEventRemoved += SubsManager_OnEventRemoved; }
public RabbitMQEventBus(IEventDispatcher eventDispatcher, IPersistentConnection <IModel> persistentConnection, ILogger <RabbitMQEventBus> logger, int retryCount = 5) { _eventDispatcher = eventDispatcher ?? throw new ArgumentNullException(nameof(eventDispatcher)); _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _retryCount = retryCount; _consumerChannel = CreateConsumerChannel(); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { ContractResolver = new NonPublicPropertiesResolver() }; }
public TransientConsumer( IQueue queue, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection, IInternalConsumerFactory internalConsumerFactory) { Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory"); this.queue = queue; this.onMessage = onMessage; this.connection = connection; this.internalConsumerFactory = internalConsumerFactory; }
public PersistentConsumer( IQueue queue, Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection, IInternalConsumerFactory internalConsumerFactory) { Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory"); this.queue = queue; this.onMessage = onMessage; this.connection = connection; this.internalConsumerFactory = internalConsumerFactory; }
public void AddConnection(IPersistentConnection connection) { if (connection.SubscriptionType == SubscriptionType.ReceiveAndForget) { connection.NextReceiveAndForgetTime = ReceiveAndForgetTime; ReceiveAndForgetConnections.Enqueue(connection); return; } if (connection.SubscriptionType == SubscriptionType.PeekAndCommit) { connection.NextPeekTime = PeekTime; PeekConnections.Enqueue(connection); return; } throw new NotImplementedException(); }
public StartConsumingStatus StartConsuming( IPersistentConnection connection, IQueue queue, Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IConsumerConfiguration configuration ) { Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(configuration, "configuration"); this.queue = queue; this.onMessage = onMessage; var consumerTag = conventions.ConsumerTagConvention(); IDictionary<string, object> arguments = new Dictionary<string, object> { {"x-priority", configuration.Priority}, {"x-cancel-on-ha-failover", configuration.CancelOnHaFailover || connectionConfiguration.CancelOnHaFailover} }; try { Model = connection.CreateModel(); Model.BasicQos(0, configuration.PrefetchCount, false); Model.BasicConsume( queue.Name, // queue false, // noAck consumerTag, // consumerTag true, configuration.IsExclusive, arguments, // arguments this); // consumer logger.InfoWrite("Declared Consumer. queue='{0}', consumer tag='{1}' prefetchcount={2} priority={3} x-cancel-on-ha-failover={4}", queue.Name, consumerTag, configuration.PrefetchCount, configuration.Priority, configuration.CancelOnHaFailover); } catch (Exception exception) { logger.ErrorWrite("Consume failed. queue='{0}', consumer tag='{1}', message='{2}'", queue.Name, consumerTag, exception.Message); return StartConsumingStatus.Failed; } return StartConsumingStatus.Succeed; }
public PersistentChannel( IPersistentConnection connection, IEasyNetQLogger logger, IConnectionConfiguration configuration, IEventBus eventBus) { Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(logger, "logger"); Preconditions.CheckNotNull(configuration, "configuration"); Preconditions.CheckNotNull(eventBus, "eventBus"); this.connection = connection; this.logger = logger; this.configuration = configuration; this.eventBus = eventBus; WireUpEvents(); }
public TransientConsumer( IQueue queue, Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IPersistentConnection connection, IConsumerConfiguration configuration, IInternalConsumerFactory internalConsumerFactory, IEventBus eventBus) { Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(internalConsumerFactory, "internalConsumerFactory"); Preconditions.CheckNotNull(eventBus, "eventBus"); Preconditions.CheckNotNull(configuration, "configuration"); this.queue = queue; this.onMessage = onMessage; this.connection = connection; this.configuration = configuration; this.internalConsumerFactory = internalConsumerFactory; this.eventBus = eventBus; }
public void SetUp() { persistentConnection = MockRepository.GenerateStub<IPersistentConnection>(); channel = MockRepository.GenerateStub<IModel>(); var eventBus = new EventBus(); var configuration = new ConnectionConfiguration(); var shutdownArgs = new ShutdownEventArgs( ShutdownInitiator.Peer, AmqpException.ConnectionClosed, "connection closed by peer"); var exception = new OperationInterruptedException(shutdownArgs); persistentConnection.Stub(x => x.CreateModel()).Throw(exception).Repeat.Once(); persistentConnection.Stub(x => x.CreateModel()).Return(channel).Repeat.Any(); var logger = MockRepository.GenerateStub<IEasyNetQLogger>(); persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus); new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite); persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"),DateTime.UtcNow ); }
public IPersistentChannel CreatePersistentChannel(IPersistentConnection connection) { Preconditions.CheckNotNull(connection, "connection"); return new PersistentChannel(connection, logger, configuration, eventBus); }
public void StartConsuming( IPersistentConnection connection, IQueue queue, Func<byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IConsumerConfiguration configuration ) { Preconditions.CheckNotNull(connection, "connection"); Preconditions.CheckNotNull(queue, "queue"); Preconditions.CheckNotNull(onMessage, "onMessage"); Preconditions.CheckNotNull(configuration, "configuration"); this.queue = queue; this.onMessage = onMessage; var consumerTag = conventions.ConsumerTagConvention(); IDictionary<string, object> arguments = new Dictionary<string, object> { {"x-priority", configuration.Priority} }; try { Model = connection.CreateModel(); Model.BasicQos(0, connectionConfiguration.PrefetchCount, false); Model.BasicConsume( queue.Name, // queue false, // noAck consumerTag, // consumerTag arguments, // arguments this); // consumer logger.InfoWrite("Declared Consumer. queue='{0}', consumer tag='{1}' prefetchcount={2} priority={3}", queue.Name, consumerTag, connectionConfiguration.PrefetchCount, configuration.Priority); } catch (Exception exception) { logger.InfoWrite("Consume failed. queue='{0}', consumer tag='{1}', message='{2}'", queue.Name, consumerTag, exception.Message); } }
public IClientCommandDispatcher GetClientCommandDispatcher(IPersistentConnection connection) { Preconditions.CheckNotNull(connection, "connection"); return new ClientCommandDispatcher(connection, persistentChannelFactory); }