private void ProcessRecord(IDataRecord record, DbOperation dbOperation) { var id = record.GetInt64(0); ScaleoutMessage message = SqlPayload.FromBytes(record); _trace.TraceVerbose("{0}SqlReceiver last payload ID={1}, new payload ID={2}", _tracePrefix, _lastPayloadId, id); if (id > _lastPayloadId + 1) { _trace.TraceError("{0}Missed message(s) from SQL Server. Expected payload ID {1} but got {2}.", _tracePrefix, _lastPayloadId + 1, id); } else if (id <= _lastPayloadId) { _trace.TraceInformation("{0}Duplicate message(s) or payload ID reset from SQL Server. Last payload ID {1}, this payload ID {2}", _tracePrefix, _lastPayloadId, id); } _lastPayloadId = id; // Update the Parameter with the new payload ID dbOperation.Parameters[0].Value = _lastPayloadId; _trace.TraceVerbose("{0}Updated receive reader initial payload ID parameter={1}", _tracePrefix, _dbOperation.Parameters[0].Value); _trace.TraceVerbose("{0}Payload {1} containing {2} message(s) received", _tracePrefix, id, message.Messages.Count); Received((ulong)id, message); }
private void ProcessRecord(IDataRecord record, DbOperation dbOperation) { var id = record.GetInt64(0); var payload = SqlPayload.FromBytes(record.GetBinary(1)); if (id != _lastPayloadId + 1) { _trace.TraceError("{0}Missed message(s) from SQL Server. Expected payload ID {1} but got {2}.", _tracePrefix, _lastPayloadId + 1, id); } if (id <= _lastPayloadId) { _trace.TraceInformation("{0}Duplicate message(s) or payload ID reset from SQL Server. Last payload ID {1}, this payload ID {2}", _tracePrefix, _lastPayloadId, id); } _lastPayloadId = id; // Update the Parameter with the new payload ID dbOperation.Parameters[0].Value = _lastPayloadId; // Pass to the underlying message bus _onReceived((ulong)id, payload.Messages); _trace.TraceVerbose("{0}Payload {1} containing {2} message(s) received", _tracePrefix, id, payload.Messages.Count); }
public static SqlPayload FromBytes(byte[] data) { using (var stream = new MemoryStream(data)) { var binaryReader = new BinaryReader(stream); int count = binaryReader.ReadInt32(); var payload = new SqlPayload { Messages = new List<Message>() }; for (int i = 0; i < count; i++) { payload.Messages.Add(Message.ReadFrom(stream)); } return payload; } }
public Task Send(IList <Message> messages) { if (messages == null || messages.Count == 0) { return(TaskAsyncHelper.Empty); } var parameter = _dbProviderFactory.CreateParameter(); parameter.ParameterName = "Payload"; parameter.DbType = DbType.Binary; parameter.Value = SqlPayload.ToBytes(messages); var operation = new DbOperation(_connectionString, _insertDml, _trace, parameter); return(operation.ExecuteNonQueryAsync()); }
public static SqlPayload FromBytes(byte[] data) { using (var stream = new MemoryStream(data)) { var binaryReader = new BinaryReader(stream); int count = binaryReader.ReadInt32(); var payload = new SqlPayload { Messages = new List <Message>() }; for (int i = 0; i < count; i++) { payload.Messages.Add(Message.ReadFrom(stream)); } return(payload); } }