private PartitionContext InitializeManager(EventHubReceiver receiver) { this.eventHubReceiver = receiver; this.context = this.CreateContext(); this.processor = this.processorFactory.CreateEventProcessor(this.context); return(this.context); }
public EventDataPumpAsyncResult(EventProcessorLifecycleManager lifeCycleManager, EventHubReceiver receiver, PartitionContext context, AsyncCallback callback, object state) : base(TimeSpan.MaxValue, callback, state) { this.context = context; this.lifeCycleManager = lifeCycleManager; this.receiver = receiver; this.trackingContext = TrackingContext.GetInstance(Guid.NewGuid(), this.receiver.Name); base.Start(); }
protected override IEnumerator <IteratorAsyncResult <EventProcessorLifecycleManager.EventProcessorInitializeAsyncResult> .AsyncStep> GetAsyncSteps() { object obj; Func <Task <EventHubReceiver> > func = null; if (!string.IsNullOrWhiteSpace(this.startingOffset)) { func = () => this.lifeCycleManager.eventHubConsumer.CreateReceiverAsync(this.partitionId, this.startingOffset, this.epoch); } else { Func <string, object> initialOffsetProvider = this.lifeCycleManager.processorOptions.InitialOffsetProvider; obj = (initialOffsetProvider != null ? initialOffsetProvider(this.lease.PartitionId) : null); object obj1 = obj; if (obj1 != null) { string str = obj1 as string; if (str == null) { DateTime?nullable = (DateTime?)(obj1 as DateTime?); if (!nullable.HasValue) { throw Fx.Exception.AsError(new InvalidOperationException(SRClient.InitialOffsetProviderReturnTypeNotSupported(obj1.GetType().ToString())), null); } func = () => this.lifeCycleManager.eventHubConsumer.CreateReceiverAsync(this.partitionId, nullable.Value, this.epoch); } else { func = () => this.lifeCycleManager.eventHubConsumer.CreateReceiverAsync(this.partitionId, str, this.epoch); } } else { func = () => this.lifeCycleManager.eventHubConsumer.CreateReceiverAsync(this.partitionId, "-1", this.epoch); } } yield return(base.CallTask((EventProcessorLifecycleManager.EventProcessorInitializeAsyncResult thisPtr, TimeSpan t) => func().Then <EventHubReceiver>((EventHubReceiver receiver) => { thisPtr.partitionContext = thisPtr.lifeCycleManager.InitializeManager(receiver); thisPtr.receiver = receiver; return thisPtr.lifeCycleManager.processor.OpenAsync(thisPtr.partitionContext); }), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); TaskCompletionSource <object> taskCompletionSource = new TaskCompletionSource <object>(); try { EventProcessorLifecycleManager eventProcessorLifecycleManager = this.lifeCycleManager; EventHubReceiver eventHubReceiver = this.receiver; PartitionContext partitionContext = this.partitionContext; EventProcessorLifecycleManager.EventDataPumpAsyncResult.Begin(eventProcessorLifecycleManager, eventHubReceiver, partitionContext, (IAsyncResult ar) => taskCompletionSource.TrySetResult(null), null); } catch (Exception exception) { Environment.FailFast(exception.ToString()); } this.lifeCycleManager.dispatchTask = taskCompletionSource.Task; }
public EventProcessorShutdownAsyncResult(EventProcessorLifecycleManager lifeCycleManager, EventHubReceiver receiver, IEventProcessor processor, PartitionContext context, CloseReason reason, Task dispatchTask, AsyncCallback callback, object state) : base(TimeSpan.MaxValue, callback, state) { this.lifeCycleManager = lifeCycleManager; this.receiver = receiver; this.processor = processor; this.context = context; this.reason = reason; this.dispatchTask = dispatchTask; base.Start(); }
protected override IEnumerator <IteratorAsyncResult <EventHubConsumerGroup.CreateReceiverAsyncResult> .AsyncStep> GetAsyncSteps() { if (!this.startingDateTime.HasValue) { this.Receiver = new EventHubReceiver(this.owner.MessagingFactory, this.owner.EventHubPath, this.owner.GroupName, this.startingOffset, this.partitionId, this.owner.PrefetchCount, this.epoch, this.offsetInclusive); } else { this.Receiver = new EventHubReceiver(this.owner.MessagingFactory, this.owner.EventHubPath, this.owner.GroupName, this.startingDateTime, this.partitionId, this.owner.PrefetchCount, this.epoch); } if (this.Receiver != null) { EventHubConsumerGroup.CreateReceiverAsyncResult createReceiverAsyncResult = this; IteratorAsyncResult <EventHubConsumerGroup.CreateReceiverAsyncResult> .BeginCall beginCall = (EventHubConsumerGroup.CreateReceiverAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.Receiver.BeginOpen(t, c, s); yield return(createReceiverAsyncResult.CallAsync(beginCall, (EventHubConsumerGroup.CreateReceiverAsyncResult thisPtr, IAsyncResult r) => thisPtr.Receiver.EndOpen(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); this.owner.RegisterMessageClientEntity(this.Receiver); } }
public static IAsyncResult Begin(EventProcessorLifecycleManager lifeCycleManager, EventHubReceiver receiver, IEventProcessor processor, PartitionContext context, CloseReason reason, Task dispatchTask, AsyncCallback callback, object state) { return(new EventProcessorLifecycleManager.EventProcessorShutdownAsyncResult(lifeCycleManager, receiver, processor, context, reason, dispatchTask, callback, state)); }
public static IAsyncResult Begin(EventProcessorLifecycleManager lifeCycleManager, EventHubReceiver receiver, PartitionContext context, AsyncCallback callback, object state) { return(new EventProcessorLifecycleManager.EventDataPumpAsyncResult(lifeCycleManager, receiver, context, callback, state)); }
private void EnsureCreateInternalReceiver() { MessageReceiver result; base.ThrowIfDisposed(); if (this.InternalReceiver == null) { lock (base.ThisLock) { if (this.InternalReceiver == null) { try { ReceiveMode receiveMode = ReceiveMode.ReceiveAndDelete; if (string.IsNullOrWhiteSpace(this.StartingOffset) && !this.StartingDateTimeUtc.HasValue) { receiveMode = ReceiveMode.PeekLock; } if (this.StartingDateTimeUtc.HasValue) { Microsoft.ServiceBus.Messaging.MessagingFactory messagingFactory = this.MessagingFactory; string eventHubPath = this.EventHubPath; string name = this.Name; string partitionId = this.PartitionId; DateTime?startingDateTimeUtc = this.StartingDateTimeUtc; result = messagingFactory.CreateReceiverAsync(eventHubPath, name, receiveMode, partitionId, startingDateTimeUtc.Value, this.Epoch).Result; } else { result = this.MessagingFactory.CreateReceiverAsync(this.EventHubPath, this.Name, receiveMode, this.PartitionId, EventHubReceiver.GetValueOrDefaultOffset(this.StartingOffset), this.OffsetInclusive, this.Epoch).Result; } this.InternalReceiver = result; this.InternalReceiver.PrefetchCount = this.PrefetchCount; this.InternalReceiver.RetryPolicy = base.RetryPolicy; this.InternalReceiver.EntityType = new MessagingEntityType?(MessagingEntityType.ConsumerGroup); } catch (AggregateException aggregateException) { throw aggregateException.Flatten().InnerException; } } } } }