コード例 #1
0
        /// <summary>
        /// Fetches a business data snapshot from blob storage.
        /// </summary>
        /// <param name="cancellationToken">the CancellationToken.</param>
        /// <returns>the most recent snapshot.</returns>
        public async Task <FSharpResult <BusinessData <TBusinessData>, BusinessDataUpdateError> > FetchBusinessDataSnapshot(CancellationToken cancellationToken)
        {
            try
            {
                FSharpOption <(Watermark, string)> someWatermarkAndName = await this.GetLatestSnapshotID(cancellationToken);

                if (FSharpOption <(Watermark, string)> .get_IsNone(someWatermarkAndName))
                {
                    var emptyBusinessData = new BusinessData <TBusinessData>(
                        data: this.createEmptyBusinessData(),
                        watermark: Watermark.NewWatermark(-1));

                    return(FSharpResult <BusinessData <TBusinessData>, BusinessDataUpdateError> .NewOk(emptyBusinessData));
                }

                var(watermark, blobName) = someWatermarkAndName.Value;
                await Console.Out.WriteLineAsync($"Loading snapshot watermark {watermark.Item} from {blobName}");

                var blobClient = this.snapshotContainerClient.GetBlobClient(blobName: blobName);
                var result     = await blobClient.DownloadAsync(cancellationToken : cancellationToken);

                var val = await result.Value.Content.ReadJSON <BusinessData <TBusinessData> >();

                return(FSharpResult <BusinessData <TBusinessData>, BusinessDataUpdateError> .NewOk(val));
            }
            catch (Exception ex)
            {
                return(FSharpResult <BusinessData <TBusinessData>, BusinessDataUpdateError> .NewError(
                           BusinessDataUpdateError.NewSnapshotDownloadError(ex)));
            }
        }
コード例 #2
0
        public void TestGenericUpdates2()
        {
            var data = new UpdateableData(
                watermark: Watermark.NewWatermark(0),
                data: new FSharpMap <string, FSharpMap <string, string> >(
                    Array.Empty <Tuple <string, FSharpMap <string, string> > >()));

            Assert.AreEqual(0, data.Data.Count);
コード例 #3
0
 IObservable <WatermarkMessage <TMessagePayload> > IWatermarkMessageClient <TMessagePayload> .CreateWatermarkObervable(SeekPosition startingPosition, CancellationToken cancellationToken)
 {
     return(CreateObservable(
                consumer: this.consumer,
                tp: this.topicPartition.Value,
                startingPosition: startingPosition,
                cancellationToken: cancellationToken)
            .Select(consumeResult => new WatermarkMessage <TMessagePayload>(
                        watermark: Watermark.NewWatermark(consumeResult.Offset.Value),
                        payload: consumeResult.Message.Value.DeserializeJSON <TMessagePayload>())));
 }
コード例 #4
0
        private async Task <Watermark> SendMessage(TMessagePayload messagePayload, string requestId, CancellationToken cancellationToken = default)
        {
            var kafkaMessage = new Message <Null, string>
            {
                Key     = null,
                Value   = messagePayload.AsJSON(),
                Headers = new Headers(),
            };

            if (!string.IsNullOrEmpty(requestId))
            {
                SetRequestID(kafkaMessage.Headers, requestId);
            }

            var report = await this.producer.ProduceAsync(
                topicPartition : this.topicPartition.Value,
                message : kafkaMessage);

            await Console.Out.WriteLineAsync($"Sent {report.Topic}#{report.Partition.Value}#{report.Offset.Value} {messagePayload}");

            return(Watermark.NewWatermark(report.Offset.Value));
        }
コード例 #5
0
        public async Task <(Watermark, FashionBusinessData)> Post(FashionBusinessDataUpdate bdu)
        {
            await Task.Delay(TimeSpan.FromSeconds(1));

            return(Watermark.NewWatermark(-1), null);
        }
コード例 #6
0
 private static FSharpOption <Watermark> ParseWatermarkFromBlobName(string n)
 => long.TryParse(n.Replace(".json", string.Empty), out long watermark)
        ? FSharpOption <Watermark> .Some(Watermark.NewWatermark(watermark))
        : FSharpOption <Watermark> .None;