-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from sceneskope/dev
Added base reading receiver
- Loading branch information
Showing
4 changed files
with
65 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/SceneSkope.ServiceFabric.EventHubs/BaseReadingReceiver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.EventHubs; | ||
using Microsoft.ServiceFabric.Data; | ||
using Microsoft.ServiceFabric.Data.Collections; | ||
using Serilog; | ||
using ServiceFabric.Utilities; | ||
|
||
namespace SceneSkope.ServiceFabric.EventHubs | ||
{ | ||
public abstract class BaseReadingReceiver : IReadingReceiver | ||
{ | ||
public Func<Exception, bool> TransientExceptionChecker { get; } | ||
public ServiceFabricRetryHandler RetryHandler { get; } | ||
public ILogger Log { get; } | ||
public IReliableStateManager StateManager { get; } | ||
|
||
protected readonly IReliableDictionary<string, string> _offsets; | ||
protected readonly string _partition; | ||
|
||
public PartitionReceiver Receiver { get; } | ||
|
||
protected BaseReadingReceiver(ILogger log, | ||
IReliableStateManager stateManager, | ||
PartitionReceiver receiver, | ||
IReliableDictionary<string, string> offsets, string partition, | ||
ServiceFabricRetryHandler retryHandler, | ||
Func<Exception, bool> transientExceptionChecker = null) | ||
{ | ||
RetryHandler = retryHandler; | ||
Log = log; | ||
StateManager = stateManager; | ||
Receiver = receiver; | ||
_offsets = offsets; | ||
_partition = partition; | ||
TransientExceptionChecker = transientExceptionChecker; | ||
} | ||
|
||
public virtual Task InitialiseAsync() => Task.CompletedTask; | ||
|
||
protected Task SaveOffsetAsync(ITransaction tx, string latestOffset) => _offsets.SetAsync(tx, _partition, latestOffset); | ||
|
||
public virtual void Dispose() | ||
{ | ||
} | ||
|
||
public Task ProcessEventsAsync(IEnumerable<EventData> events) => ProcessEventsAsync((IReadOnlyList<EventData>)events); | ||
|
||
protected abstract Task ProcessEventsAsync(IReadOnlyList<EventData> events); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters