/// <inheritdoc/> protected override async Task <PutRecordBatchResponse> SendRequestAsync(PutRecordBatchRequest putDataRequest) { // Failover if (_failoverSinkEnabled) { // Failover to Secondary Region _ = FailOverToSecondaryRegion(_throttle); } return(await FirehoseClient.PutRecordBatchAsync(putDataRequest)); }
static async Task Main(string[] args) { Console.WriteLine("Enter API Key:"); var apiKey = Console.ReadLine(); Console.WriteLine("Creating channel..."); ChannelCredentials channelCredentials = new SslCredentials(System.IO.File.ReadAllText("CA.pem")); Channel channel = new Channel("partners.dnaspaces.io:443", channelCredentials); var client = new FirehoseClient(channel); var eventsStreamRequest = new EventsStreamRequest(); Metadata metadata = new Metadata(); metadata.Add(new Metadata.Entry("X-API-KEY", apiKey)); var callOptions = new CallOptions(metadata); Console.WriteLine("Requesting records..."); AsyncServerStreamingCall <EventRecord> records = client.GetEvents(eventsStreamRequest, callOptions); try { while (await records.ResponseStream.MoveNext()) { var current = records.ResponseStream.Current; Console.Write(current.ToString()); } } catch (Exception e) { Console.WriteLine("Exception thrown!"); Console.WriteLine(e.ToString()); } finally { Console.WriteLine("Shutting down channel."); channel.ShutdownAsync().Wait(); Console.ReadLine(); } }
/// <inheritdoc/> public AmazonKinesisFirehoseClient FailOverToSecondaryRegion(Throttle throttle) { var _firehoseClient = _failoverSink.FailOverToSecondaryRegion(_throttle); if (_firehoseClient is not null) { // Jittered Delay var delay = _throttle.GetDelayMilliseconds(new long[] { 1, Utility.Random.Next(1, _maxRecordsPerSecond), Utility.Random.Next(1, (int)_maxBytesPerSecond) }); if (delay > 0) { Task.Delay((int)(delay * (1.0d + Utility.Random.NextDouble() * ConfigConstants.DEFAULT_JITTING_FACTOR))).Wait(); } // Dispose FirehoseClient.Dispose(); // Override client FirehoseClient = _firehoseClient; } return(null); }