Beispiel #1
0
        internal CQRSClient(ClientConfiguration config)
        {
            _config     = config;
            _connection = config.CreateConnection();

            _publisherModels = new IModel[PublishingPoolSize];
            _publisherLocks  = new object[PublishingPoolSize];

            for (var i = 0; i < PublishingPoolSize; i++)
            {
                _publisherModels[i] = _connection.CreateModel();
                _publisherLocks[i]  = new object();
            }

            _consumers = new CustomConsumer[ConsumingPoolSize];

            for (var i = 0; i < ConsumingPoolSize; i++)
            {
                var consumerModel     = _connection.CreateModel();
                var consumerQueueName = $"req_{Guid.NewGuid().ToString()}";

                consumerModel.QueueDeclare(consumerQueueName, false, true, true, new Dictionary <string, object>());
                var consumer = _consumers[i] = new CustomConsumer(consumerModel, consumerQueueName);
                consumerModel.BasicConsume(consumerQueueName, true, consumer);
            }
        }
Beispiel #2
0
        internal CQRSClient(ClientConfiguration config)
        {
            _config     = config;
            _connection = config.CreateConnection();

            _retryPolicy = Policy.Handle <OperationTimeoutException>()
                           .Or <RequestNotFoundException>()
                           .RetryAsync(Retries, (exception, retryCount) =>
            {
                // Do nothing
            });

            _publisherModels = new IModel[PublishingPoolSize];
            _publisherLocks  = new object[PublishingPoolSize];

            for (var i = 0; i < PublishingPoolSize; i++)
            {
                _publisherModels[i] = _connection.CreateModel();
                _publisherLocks[i]  = new object();
            }

            _consumers = new AsyncMessageConsumer[ConsumingPoolSize];

            for (var i = 0; i < ConsumingPoolSize; i++)
            {
                var consumerModel     = _connection.CreateModel();
                var consumerQueueName = $"req_{Guid.NewGuid().ToString()}";

                consumerModel.QueueDeclare(consumerQueueName, false, true, true, new Dictionary <string, object>());
                var consumer = _consumers[i] = new AsyncMessageConsumer(consumerModel, Logger, consumerQueueName);
                consumerModel.BasicConsume(consumerQueueName, true, consumer);
            }
        }