Ejemplo n.º 1
0
 public async Task Shutdown(TimeSpan timeout)
 {
     try
     {
         // await the last pending operation, so after we shutdown and stop this receiver we don't get async operation completions from pending operations.
         if (_outstandingTask != null)
         {
             await _outstandingTask;
         }
     }
     finally
     {
         // remember that we shut down so we never try to read from the queue again.
         _pubSub = null;
     }
 }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public async Task QueueMessageBatchAsync <T>(StreamId streamId, IEnumerable <T> events, StreamSequenceToken token, Dictionary <string, object> requestContext)
        {
            if (token != null)
            {
                throw new ArgumentException("Google PubSub stream provider currently does not support non-null StreamSequenceToken.", nameof(token));
            }
            var queueId = _streamQueueMapper.GetQueueForStream(streamId);

            PubSubDataManager pubSub;

            if (!Subscriptions.TryGetValue(queueId, out pubSub))
            {
                var tmpPubSub = new PubSubDataManager(this.loggerFactory, ProjectId, TopicId, queueId.ToString(), ServiceId, Deadline);
                await tmpPubSub.Initialize();

                pubSub = Subscriptions.GetOrAdd(queueId, tmpPubSub);
            }

            var msg = _dataAdapter.ToPubSubMessage(streamId, events, requestContext);
            await pubSub.PublishMessages(new[] { msg });
        }
Ejemplo n.º 5
0
        private PubSubAdapterReceiver(ILoggerFactory loggerFactory, QueueId queueId, string topicId, PubSubDataManager pubSub, IPubSubDataAdapter dataAdapter)
        {
            if (queueId == null)
            {
                throw new ArgumentNullException(nameof(queueId));
            }
            Id = queueId;
            if (pubSub == null)
            {
                throw new ArgumentNullException(nameof(pubSub));
            }
            _pubSub = pubSub;

            if (dataAdapter == null)
            {
                throw new ArgumentNullException(nameof(dataAdapter));
            }
            _dataAdapter = dataAdapter;

            _logger  = loggerFactory.CreateLogger($"{this.GetType().FullName}.{topicId}.{queueId}");
            _pending = new List <PendingDelivery>();
        }
Ejemplo n.º 6
0
        private PubSubAdapterReceiver(SerializationManager serializationManager, Logger baseLogger, QueueId queueId, PubSubDataManager pubSub, IPubSubDataAdapter dataAdapter)
        {
            if (queueId == null)
            {
                throw new ArgumentNullException(nameof(queueId));
            }
            Id = queueId;
            _serializationManager = serializationManager;
            if (pubSub == null)
            {
                throw new ArgumentNullException(nameof(pubSub));
            }
            _pubSub = pubSub;

            if (dataAdapter == null)
            {
                throw new ArgumentNullException(nameof(dataAdapter));
            }
            _dataAdapter = dataAdapter;

            _logger  = baseLogger.GetSubLogger(GetType().Name);
            _pending = new List <PendingDelivery>();
        }