void HandleDatabusProperty(CallInfo callInfo) { if (DataBus == null) { throw new InvalidOperationException("Databus transmission received without a databus configured"); } //todo TimeSpan timeToBeReceived = TimeSpan.FromDays(1); string newDatabusKey; using (var stream = new MemoryStream(callInfo.Buffer)) newDatabusKey = DataBus.Put(stream, timeToBeReceived); using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TimeSpan.FromSeconds(30) })) { persister.UpdateHeader(callInfo.ClientId, callInfo.Headers[GatewayHeaders.DatabusKey], newDatabusKey); scope.Complete(); } }
public void Invoke(OutgoingContext context, Action next) { if (context.OutgoingLogicalMessage.IsControlMessage()) { next(); return; } var timeToBeReceived = context.OutgoingLogicalMessage.Metadata.TimeToBeReceived; var message = context.OutgoingLogicalMessage.Instance; foreach (var property in Conventions.GetDataBusProperties(message)) { var propertyValue = property.GetValue(message, null); if (propertyValue == null) { continue; } using (var stream = new MemoryStream()) { var dataBusProperty = propertyValue as IDataBusProperty; if (dataBusProperty != null) { propertyValue = dataBusProperty.GetValue(); } DataBusSerializer.Serialize(propertyValue, stream); stream.Position = 0; string headerValue; using (new TransactionScope(TransactionScopeOption.Suppress)) { headerValue = DataBus.Put(stream, timeToBeReceived); } string headerKey; if (dataBusProperty != null) { dataBusProperty.Key = headerValue; //we use the headers to in order to allow the infrastructure (eg. the gateway) to modify the actual key headerKey = headerValue; } else { property.SetValue(message, null, null); headerKey = String.Format("{0}.{1}", message.GetType().FullName, property.Name); } //we use the headers to in order to allow the infrastructure (eg. the gateway) to modify the actual key context.OutgoingLogicalMessage.Headers["NServiceBus.DataBus." + headerKey] = headerValue; } } next(); }