public static IQueueAdapterReceiver Create(SerializationManager serializationManager, QueueId queueId, string dataConnectionString, string deploymentId, IAzureQueueDataAdapter dataAdapter, TimeSpan?messageVisibilityTimeout = null)
        {
            if (queueId == null)
            {
                throw new ArgumentNullException(nameof(queueId));
            }
            if (string.IsNullOrEmpty(dataConnectionString))
            {
                throw new ArgumentNullException(nameof(dataConnectionString));
            }
            if (string.IsNullOrEmpty(deploymentId))
            {
                throw new ArgumentNullException(nameof(deploymentId));
            }
            if (dataAdapter == null)
            {
                throw new ArgumentNullException(nameof(dataAdapter));
            }
            if (serializationManager == null)
            {
                throw new ArgumentNullException(nameof(serializationManager));
            }

            var queue = new AzureQueueDataManager(queueId.ToString(), deploymentId, dataConnectionString, messageVisibilityTimeout);

            return(new AzureQueueAdapterReceiver(serializationManager, queueId, queue, dataAdapter));
        }
        public Task QueueMessageBatchAsync <T>(Guid streamGuid,
                                               string streamNamespace,
                                               IEnumerable <T> events,
                                               StreamSequenceToken token,
                                               Dictionary <string, object> requestContext)
        {
            if (_publishSubscribe == null)
            {
                return(Task.CompletedTask);
            }

            QueueId queueId       = _streamQueueMapper.GetQueueForStream(streamGuid, streamNamespace);
            string  queueidString = queueId.ToString();

            foreach (T @event in events)
            {
                MessageData messageData = new MessageData(_serializationManager)
                {
                    Payload         = _serializationManager.SerializeToByteArray(@event),
                    StreamGuid      = streamGuid,
                    StreamNamespace = streamNamespace,
                    SequenceNumber  = DateTime.UtcNow.Ticks,
                    RequestContext  = requestContext
                };

                _publishSubscribe.Publish(queueidString, messageData);
            }

            return(Task.CompletedTask);
        }
        public static IQueueAdapterReceiver Create(QueueId queueId, string rabbitMqConnectionString, string deploymentId = "")
        {
            if (queueId == null) throw new ArgumentNullException(nameof(queueId));
            if (String.IsNullOrEmpty(rabbitMqConnectionString)) throw new ArgumentNullException(nameof(rabbitMqConnectionString));

            var queue = new RabbitMessageQueueDataManager(queueId.ToString(), deploymentId, rabbitMqConnectionString);

            return new RabbitMessageQueueAdapterReceiver(queueId, queue);
        }
Example #4
0
        /// <summary>
        /// Creates a queue receiver for the specified queueId
        /// </summary>
        /// <param name="queueId"></param>
        /// <returns></returns>
        public IQueueAdapterReceiver CreateReceiver(QueueId queueId)
        {
            var dimensions      = new ReceiverMonitorDimensions(queueId.ToString());
            var receiverMonitor = this.ReceiverMonitorFactory(dimensions, this.telemetryProducer);
            var receiver        = receivers.GetOrAdd(queueId, new Receiver(receiverMonitor));

            SetGeneratorOnReceiver(receiver);
            return(receiver);
        }
Example #5
0
        /// <summary>
        /// Create a cache for a given queue id
        /// </summary>
        /// <param name="queueId"></param>
        public IQueueCache CreateQueueCache(QueueId queueId)
        {
            //move block pool creation from init method to here, to avoid unnecessary block pool creation when stream provider is initialized in client side.
            CreateBufferPoolIfNotCreatedYet();
            var logger  = this.loggerFactory.CreateLogger($"{typeof(MemoryPooledCache<TSerializer>).FullName}.{this.Name}.{queueId}");
            var monitor = this.CacheMonitorFactory(new CacheMonitorDimensions(queueId.ToString(), this.blockPoolMonitorDimensions.BlockPoolId), this.telemetryProducer);

            return(new MemoryPooledCache <TSerializer>(bufferPool, purgePredicate, logger, this.serializer, monitor, this.statisticOptions.StatisticMonitorWriteInterval));
        }
 public static IQueueAdapterReceiver Create(QueueId queueId, string dataConnectionString, string deploymentId)
 {
     if (queueId == null) throw new ArgumentNullException("queueId");
     if (String.IsNullOrEmpty(dataConnectionString)) throw new ArgumentNullException("dataConnectionString");
     if (String.IsNullOrEmpty(deploymentId)) throw new ArgumentNullException("deploymentId");
     
     var queue = new AzureQueueDataManager(queueId.ToString(), deploymentId, dataConnectionString);
     return new AzureQueueAdapterReceiver(queueId, queue);
 }
Example #7
0
        /// <summary>
        /// Creates a queue receiver for the specified queueId
        /// </summary>
        /// <param name="queueId"></param>
        /// <returns></returns>
        public IQueueAdapterReceiver CreateReceiver(QueueId queueId)
        {
            var dimensions                 = new ReceiverMonitorDimensions(queueId.ToString());
            var receiverLogger             = this.loggerFactory.CreateLogger($"{typeof(MemoryAdapterReceiver<TSerializer>).FullName}.{this.Name}.{queueId}");
            var receiverMonitor            = this.ReceiverMonitorFactory(dimensions, this.telemetryProducer);
            IQueueAdapterReceiver receiver = new MemoryAdapterReceiver <TSerializer>(GetQueueGrain(queueId), receiverLogger, this.serializer, receiverMonitor);

            return(receiver);
        }
        /// <summary>
        /// Create a cache for a given queue id
        /// </summary>
        /// <param name="queueId"></param>
        public IQueueCache CreateQueueCache(QueueId queueId)
        {
            //move block pool creation from init method to here, to avoid unnecessary block pool creation when stream provider is initialized in client side.
            CreateBufferPoolIfNotCreatedYet();
            var dimensions   = new CacheMonitorDimensions(this.sharedDimensions, queueId.ToString(), this.blockPoolMonitorDimensions.BlockPoolId);
            var cacheMonitor = this.CacheMonitorFactory(dimensions, logger.GetSubLogger(typeof(ICacheMonitor).Name));

            return(new GeneratorPooledCache(bufferPool, logger.GetSubLogger(typeof(GeneratorPooledCache).Name), serializationManager,
                                            cacheMonitor, this.adapterConfig.StatisticMonitorWriteInterval));
        }
        public Task Initialize(TimeSpan timeout)
        {
            _subscription?.Dispose();
            _subscription = _publishSubscribe
                            .Observe <MessageData>(_queueId.ToString(), _queueId.ToString())
                            .Subscribe(tuple =>
            {
                switch (tuple.Data)
                {
                case MessageData messageData:
                    messageData.SerializationManager = _serializationManager;
                    break;
                }

                _batchContainers.Enqueue(tuple.Data);
            });

            return(Task.CompletedTask);
        }
Example #10
0
        /// <summary>
        /// Create a cache for a given queue id
        /// </summary>
        /// <param name="queueId"></param>
        public IQueueCache CreateQueueCache(QueueId queueId)
        {
            //move block pool creation from init method to here, to avoid unnecessary block pool creation when stream provider is initialized in client side.
            CreateBufferPoolIfNotCreatedYet();
            var dimensions   = new CacheMonitorDimensions(queueId.ToString(), this.blockPoolMonitorDimensions.BlockPoolId);
            var cacheMonitor = this.CacheMonitorFactory(dimensions, this.telemetryProducer);

            return(new GeneratorPooledCache(bufferPool, this.loggerFactory.CreateLogger($"{typeof(GeneratorPooledCache).FullName}.{this.Name}.{queueId}"), serializationManager,
                                            cacheMonitor, this.statisticOptions.StatisticMonitorWriteInterval));
        }
        public IQueueAdapterReceiver CreateReceiver(QueueId queueId)
        {
            int maxRetry = 3;

            while (maxRetry-- > 0)
            {
                if (!_queueAdapterReceivers.TryGetValue(queueId.ToString(), out PublishSubscribeQueueAdapterReceiver adapterReceiver))
                {
                    adapterReceiver = new PublishSubscribeQueueAdapterReceiver(queueId, _publishSubscribe, _serializationManager);
                    if (!_queueAdapterReceivers.TryAdd(queueId.ToString(), adapterReceiver))
                    {
                        continue;
                    }
                }

                return(adapterReceiver);
            }

            throw new Exception("Internal exception, should not happen!");
        }
        public static IQueueAdapterReceiver Create(ILoggerFactory loggerFactory, QueueId queueId, string projectId, string topicId,
                                                   string serviceId, IPubSubDataAdapter dataAdapter, TimeSpan?deadline = null, string customEndpoint = "")
        {
            if (queueId == null)
            {
                throw new ArgumentNullException(nameof(queueId));
            }
            if (dataAdapter == null)
            {
                throw new ArgumentNullException(nameof(dataAdapter));
            }

            var pubSub = new PubSubDataManager(loggerFactory, projectId, topicId, queueId.ToString(), serviceId, deadline, customEndpoint);

            return(new PubSubAdapterReceiver(loggerFactory, queueId, topicId, pubSub, dataAdapter));
        }
        public static IQueueAdapterReceiver Create(QueueId queueId, string dataConnectionString, string deploymentId)
        {
            if (queueId == null)
            {
                throw new ArgumentNullException("queueId");
            }
            if (string.IsNullOrEmpty(dataConnectionString))
            {
                throw new ArgumentNullException("dataConnectionString");
            }
            if (string.IsNullOrEmpty(deploymentId))
            {
                throw new ArgumentNullException("deploymentId");
            }
            var queue = new RabbitMessageQueueDataManager(queueId.ToString(), deploymentId, dataConnectionString);

            return(new RabbitMessageQueueAdapterReceiver(queueId, queue));
        }
Example #14
0
        public async Task Initialize(TimeSpan timeout)
        {
            if (!_eventStoreRepository.IStarted)
            {
                await _eventStoreRepository.Connect(timeout);
            }

            var group = _queueId.ToString();

            await _eventStoreRepository.CreatePersistentSubscription(_providerName, group);

            _cleanUp = _eventStoreRepository.ObservePersistentSubscription(_providerName, group)
                       .Subscribe(ev =>
            {
                Debug.WriteLine($"{ev.StreamId} {ev.Version}");
                //todo: implement batch
                _receivedMessages.Enqueue(new EventStoreBatchContainer(Guid.Empty, ev.StreamId, ev, new EventStoreStreamSequenceToken(ev.Version)));
            });
        }
Example #15
0
        public static IQueueAdapterReceiver Create(Serializer <SQSBatchContainer> serializer, ILoggerFactory loggerFactory, QueueId queueId, string dataConnectionString, string serviceId)
        {
            if (queueId == null)
            {
                throw new ArgumentNullException("queueId");
            }
            if (string.IsNullOrEmpty(dataConnectionString))
            {
                throw new ArgumentNullException("dataConnectionString");
            }
            if (string.IsNullOrEmpty(serviceId))
            {
                throw new ArgumentNullException(nameof(serviceId));
            }

            var queue = new SQSStorage(loggerFactory, queueId.ToString(), dataConnectionString, serviceId);

            return(new SQSAdapterReceiver(serializer, loggerFactory, queueId, queue));
        }
Example #16
0
        public static IQueueAdapterReceiver Create(SerializationManager serializationManager, ILoggerFactory loggerFactory, QueueId queueId, string dataConnectionString, string deploymentId)
        {
            if (queueId == null)
            {
                throw new ArgumentNullException("queueId");
            }
            if (string.IsNullOrEmpty(dataConnectionString))
            {
                throw new ArgumentNullException("dataConnectionString");
            }
            if (string.IsNullOrEmpty(deploymentId))
            {
                throw new ArgumentNullException("deploymentId");
            }

            var queue = new SQSStorage(loggerFactory, queueId.ToString(), dataConnectionString, deploymentId);

            return(new SQSAdapterReceiver(serializationManager, loggerFactory, queueId, queue));
        }
Example #17
0
        public static IQueueAdapterReceiver Create(QueueId queueId, string dataConnectionString, string deploymentId, TimeSpan?messageVisibilityTimeout = null)
        {
            if (queueId == null)
            {
                throw new ArgumentNullException("queueId");
            }
            if (String.IsNullOrEmpty(dataConnectionString))
            {
                throw new ArgumentNullException("dataConnectionString");
            }
            if (String.IsNullOrEmpty(deploymentId))
            {
                throw new ArgumentNullException("deploymentId");
            }

            var queue = new AzureQueueDataManager(queueId.ToString(), deploymentId, dataConnectionString, messageVisibilityTimeout);

            return(new AzureQueueAdapterReceiver(queueId, queue));
        }
Example #18
0
        public static IQueueAdapterReceiver Create(SerializationManager serializationManager, Logger baseLogger, QueueId queueId, string projectId, string topicId,
                                                   string deploymentId, IPubSubDataAdapter dataAdapter, TimeSpan?deadline = null, string customEndpoint = "")
        {
            if (queueId == null)
            {
                throw new ArgumentNullException(nameof(queueId));
            }
            if (dataAdapter == null)
            {
                throw new ArgumentNullException(nameof(dataAdapter));
            }
            if (serializationManager == null)
            {
                throw new ArgumentNullException(nameof(serializationManager));
            }

            var pubSub = new PubSubDataManager(baseLogger, projectId, topicId, queueId.ToString(), deploymentId, deadline, customEndpoint);

            return(new PubSubAdapterReceiver(serializationManager, baseLogger, queueId, pubSub, dataAdapter));
        }
Example #19
0
        public static IQueueAdapterReceiver Create(QueueId queueId, string dataConnectionString, string deploymentId, int cacheSize)
        {
            if (queueId == null)
            {
                throw new ArgumentNullException("queueId");
            }
            if (String.IsNullOrEmpty(dataConnectionString))
            {
                throw new ArgumentNullException("dataConnectionString");
            }
            if (String.IsNullOrEmpty(deploymentId))
            {
                throw new ArgumentNullException("deploymentId");
            }
            if (cacheSize <= 0)
            {
                throw new ArgumentOutOfRangeException("cacheSize", "CacheSize must be positive number.");
            }

            var queue = new AzureQueueDataManager(queueId.ToString(), deploymentId, dataConnectionString);

            return(new AzureQueueAdapterReceiver(queueId, queue, cacheSize));
        }
        /// <summary>
        /// Creates a quere receiver for the specificed queueId
        /// </summary>
        /// <param name="queueId"></param>
        /// <returns></returns>
        public IQueueAdapterReceiver CreateReceiver(QueueId queueId)
        {
            var      dimensions      = new ReceiverMonitorDimensions(this.sharedDimensions, queueId.ToString());
            var      receiverMonitor = this.ReceiverMonitorFactory(dimensions, logger.GetSubLogger(typeof(IQueueAdapterReceiverMonitor).Name));
            Receiver receiver        = receivers.GetOrAdd(queueId, qid => new Receiver(receiverMonitor));

            SetGeneratorOnReciever(receiver);
            return(receiver);
        }
 public RabbitMqConnector(RabbitMqStreamProviderOptions options, QueueId queueId, Logger logger)
 {
     _options  = options;
     QueueName = queueId.ToString();
     Logger    = logger;
 }
Example #22
0
        /// <summary>
        /// Creates a quere receiver for the specificed queueId
        /// </summary>
        /// <param name="queueId"></param>
        /// <returns></returns>
        public IQueueAdapterReceiver CreateReceiver(QueueId queueId)
        {
            var dimensions                 = new ReceiverMonitorDimensions(this.sharedDimensions, queueId.ToString());
            var receiverLogger             = logger.GetSubLogger(typeof(MemoryAdapterReceiver <TSerializer>).Name);
            var receiverMonitor            = this.ReceiverMonitorFactory(dimensions, receiverLogger.GetSubLogger(typeof(IQueueAdapterReceiverMonitor).Name));
            IQueueAdapterReceiver receiver = new MemoryAdapterReceiver <TSerializer>(GetQueueGrain(queueId), receiverLogger, this.serializer, receiverMonitor);

            return(receiver);
        }
 public string QueueIdToQueueName(QueueId queueId)
 {
     return(queueId.ToString());
 }
Example #24
0
        /// <summary>
        /// Create a cache for a given queue id
        /// </summary>
        /// <param name="queueId"></param>
        public IQueueCache CreateQueueCache(QueueId queueId)
        {
            //move block pool creation from init method to here, to avoid unnecessary block pool creation when stream provider is initialized in client side.
            CreateBufferPoolIfNotCreatedYet();
            var logger  = this.logger.GetSubLogger(typeof(MemoryPooledCache <TSerializer>).Name);
            var monitor = this.CacheMonitorFactory(new CacheMonitorDimensions(this.sharedDimensions, queueId.ToString(), this.blockPoolMonitorDimensions.BlockPoolId), logger.GetSubLogger(typeof(ICacheMonitor).Name));

            return(new MemoryPooledCache <TSerializer>(bufferPool, purgePredicate, logger, this.serializer, monitor, this.adapterConfig.StatisticMonitorWriteInterval));
        }