private static void SendWebTransactionsToQueue(List <WebTransaction> transactions) { Amazon.Kinesis.AmazonKinesisConfig config = new AmazonKinesisConfig(); config.RegionEndpoint = Amazon.RegionEndpoint.EUWest1; AmazonKinesisClient kinesisClient = new AmazonKinesisClient(config); String kinesisStreamName = ConfigurationManager.AppSettings["KinesisStreamName"]; foreach (WebTransaction wt in transactions) { string dataAsJson = JsonConvert.SerializeObject(wt); byte[] dataAsBytes = Encoding.UTF8.GetBytes(dataAsJson); using (MemoryStream memoryStream = new MemoryStream(dataAsBytes)) { try { //PutRecordsRequestEntry requestRecord = new PutRecordRequest(); Amazon.Kinesis.Model.PutRecordRequest requestRecord = new Amazon.Kinesis.Model.PutRecordRequest(); requestRecord.StreamName = kinesisStreamName; requestRecord.PartitionKey = "url-response-times"; requestRecord.Data = memoryStream; Amazon.Kinesis.Model.PutRecordResponse responseRecord = kinesisClient.PutRecord(requestRecord); Console.WriteLine("Successfully sent record {0} to Kinesis. Sequence number: {1}", wt.Url, responseRecord.SequenceNumber); } catch (Exception ex) { Console.WriteLine("Failed to send record {0} to Kinesis. Exception: {1}", wt.Url, ex.Message); } } } }
private static void UnmarshallResult(JsonUnmarshallerContext context,PutRecordResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; while (context.Read()) { if (context.TestExpression("ShardId", targetDepth)) { context.Read(); response.ShardId = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.TestExpression("SequenceNumber", targetDepth)) { context.Read(); response.SequenceNumber = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.CurrentDepth <= originalDepth) { return; } } return; }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { PutRecordResponse response = new PutRecordResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("ShardId", targetDepth)) { response.ShardId = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.TestExpression("SequenceNumber", targetDepth)) { response.SequenceNumber = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } } return response; }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { PutRecordResponse response = new PutRecordResponse(); context.Read(); UnmarshallResult(context,response); return response; }