Skip to content

Commit

Permalink
ServiceFabricProcessor preview (#262)
Browse files Browse the repository at this point in the history
This is the code that built and released as preview version 0.5.2 https://www.nuget.org/packages/Microsoft.Azure.EventHubs.ServiceFabricProcessor/0.5.2

At the time it couldn't be merged with dev due to test issues from unrelated work, so we did the release from the SFprocessor branch. Those issues have been resolved, and we expect that future preview releases will come from dev branch.
  • Loading branch information
JamesBirdsall authored Feb 14, 2019
1 parent 4ce1613 commit 321f188
Show file tree
Hide file tree
Showing 17 changed files with 1,951 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Microsoft.Azure.EventHubs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.EventHubs.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.EventHubs.Processor", "src\Microsoft.Azure.EventHubs.Processor\Microsoft.Azure.EventHubs.Processor.csproj", "{8C89967A-4E1F-46B0-8458-81B545C822B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.EventHubs.ServiceFabricProcessor", "src\Microsoft.Azure.EventHubs.ServiceFabricProcessor\Microsoft.Azure.EventHubs.ServiceFabricProcessor.csproj", "{D96BCC8F-D5EE-464A-9C15-EF59613F9F82}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,6 +38,10 @@ Global
{8C89967A-4E1F-46B0-8458-81B545C822B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C89967A-4E1F-46B0-8458-81B545C822B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C89967A-4E1F-46B0-8458-81B545C822B2}.Release|Any CPU.Build.0 = Release|Any CPU
{D96BCC8F-D5EE-464A-9C15-EF59613F9F82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D96BCC8F-D5EE-464A-9C15-EF59613F9F82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D96BCC8F-D5EE-464A-9C15-EF59613F9F82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D96BCC8F-D5EE-464A-9C15-EF59613F9F82}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -44,5 +50,6 @@ Global
{126D946D-CE0F-4F14-9F13-8FD7098B81D8} = {08E028C1-29E7-42B5-871F-C911DB93E78A}
{154F7B4C-B998-4FA0-933F-F34DB0CA9B88} = {AF49C862-CB78-4110-A275-8111B387805D}
{8C89967A-4E1F-46B0-8458-81B545C822B2} = {08E028C1-29E7-42B5-871F-C911DB93E78A}
{D96BCC8F-D5EE-464A-9C15-EF59613F9F82} = {08E028C1-29E7-42B5-871F-C911DB93E78A}
EndGlobalSection
EndGlobal
151 changes: 151 additions & 0 deletions src/Microsoft.Azure.EventHubs.ServiceFabricProcessor/Checkpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.using System;

namespace Microsoft.Azure.EventHubs.ServiceFabricProcessor
{
using System;
using System.Collections.Generic;

/// <summary>
/// A persistable representation of what events in the stream have been processed.
/// Version 1 checkpoint is just a high-water mark, containing an offset and sequence number. All events at or lower than the given position
/// have been processed. Any events higher than the given position are unprocessed.
/// </summary>
public class Checkpoint
{
/// <summary>
/// Create an uninitialized checkpoint of the given version.
/// </summary>
/// <param name="version"></param>
internal Checkpoint(int version)
{
this.Version = version;
this.Valid = false;
}

/// <summary>
/// Create an initialized version 1 checkpoint.
/// </summary>
/// <param name="offset">Offset of highest-processed position.</param>
/// <param name="sequenceNumber">Sequence number of highest-processed position.</param>
public Checkpoint(string offset, long sequenceNumber)
{
this.Version = 1;
this.Offset = offset;
this.SequenceNumber = sequenceNumber;
this.Valid = true;
}

#region AllVersions
//
// Methods and properties valid for all versions.
//

/// <summary>
/// Version of this checkpoint.
/// </summary>
public int Version { get; protected set; }

/// <summary>
/// True if this checkpoint contains a valid position.
/// </summary>
public bool Valid { get; protected set; }

/// <summary>
/// Serialize this instance to a persistable representation as a name-value dictionary.
/// </summary>
/// <returns>Serialized dictionary representation.</returns>
public Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> converted = new Dictionary<string, object>();

converted.Add(Constants.CheckpointPropertyVersion, this.Version);
converted.Add(Constants.CheckpointPropertyValid, this.Valid);

switch (this.Version)
{
case 1:
converted.Add(Constants.CheckpointPropertyOffsetV1, this.Offset);
converted.Add(Constants.CheckpointPropertySequenceNumberV1, this.SequenceNumber);
break;

default:
throw new NotImplementedException();
}

return converted;
}

/// <summary>
/// Deserialize from a name-value dictionary.
/// </summary>
/// <param name="dictionary">Serialized representation.</param>
/// <returns>Deserialized instance.</returns>
static public Checkpoint CreateFromDictionary(Dictionary<string, object> dictionary)
{
int version = (int)dictionary[Constants.CheckpointPropertyVersion];
bool valid = (bool)dictionary[Constants.CheckpointPropertyValid];

Checkpoint result = new Checkpoint(version);

if (valid)
{
result.Valid = true;

switch (result.Version)
{
case 1:
result.Offset = (string)dictionary[Constants.CheckpointPropertyOffsetV1];
result.SequenceNumber = (long)dictionary[Constants.CheckpointPropertySequenceNumberV1];
break;

default:
throw new NotImplementedException($"Unrecognized checkpoint version {result.Version}");
}
}

return result;
}
#endregion AllVersions

#region Version1
//
// Methods and properties for Version==1
//

/// <summary>
/// Initialize an uninitialized instance as a version 1 checkpoint.
/// </summary>
/// <param name="offset">Offset of highest-processed position.</param>
/// <param name="sequenceNumber">Sequence number of highest-processed position.</param>
public void InitializeV1(string offset, long sequenceNumber)
{
this.Version = 1;

if (string.IsNullOrEmpty(offset))
{
throw new ArgumentException("offset must not be null or empty");
}
if (sequenceNumber < 0)
{
throw new ArgumentException("sequenceNumber must be >= 0");
}

this.Offset = offset;
this.SequenceNumber = sequenceNumber;

this.Valid = true;
}

/// <summary>
/// Offset of highest-processed position. Immutable after construction or initialization.
/// </summary>
public string Offset { get; private set; }

/// <summary>
/// Sequence number of highest-processed position. Immutable after construction or initialization.
/// </summary>
public long SequenceNumber { get; private set; }
#endregion Version1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.using System;

namespace Microsoft.Azure.EventHubs.ServiceFabricProcessor
{
/// <summary>
/// Why the event processor is being shut down.
/// </summary>
public enum CloseReason
{
/// <summary>
/// It was cancelled by Service Fabric.
/// </summary>
Cancelled,

/// <summary>
/// There was an event hubs failure.
/// </summary>
Failure
}
}
24 changes: 24 additions & 0 deletions src/Microsoft.Azure.EventHubs.ServiceFabricProcessor/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.using System;

namespace Microsoft.Azure.EventHubs.ServiceFabricProcessor
{
using System;

class Constants
{
internal static readonly int RetryCount = 5;

internal static readonly int FixedReceiverEpoch = 0;

internal static readonly TimeSpan MetricReportingInterval = TimeSpan.FromMinutes(1.0);
internal static readonly string DefaultUserLoadMetricName = "CountOfPartitions";

internal static readonly TimeSpan ReliableDictionaryTimeout = TimeSpan.FromSeconds(10.0); // arbitrary
internal static readonly string CheckpointDictionaryName = "EventProcessorCheckpointDictionary";
internal static readonly string CheckpointPropertyVersion = "version";
internal static readonly string CheckpointPropertyValid = "valid";
internal static readonly string CheckpointPropertyOffsetV1 = "offsetV1";
internal static readonly string CheckpointPropertySequenceNumberV1 = "sequenceNumberV1";
}
}
Loading

0 comments on commit 321f188

Please sign in to comment.