/// <summary> /// <see cref="ISendOnlyBus.Send{T}(Action{T})"/> /// </summary> public ICallback Send <T>(Action <T> messageConstructor) { object message = messageMapper.CreateInstance(messageConstructor); var destination = GetDestinationForSend(message); return(SendMessage(new SendOptions(destination), LogicalMessageFactory.Create(message))); }
/// <summary> /// <see cref="ISendOnlyBus.Publish{T}(T)"/> /// </summary> public virtual void Publish <T>(T message) { var logicalMessage = LogicalMessageFactory.Create(message); var options = new PublishOptions(logicalMessage.MessageType); InvokeSendPipeline(options, logicalMessage); }
private List <LogicalMessage> Extract(TransportMessage physicalMessage, string contentType) { if (physicalMessage.Body == null || physicalMessage.Body.Length == 0) { return(new List <LogicalMessage>()); } string messageTypeIdentifier; var messageMetadata = new List <MessageMetadata>(); if (physicalMessage.Headers.TryGetValue(Headers.EnclosedMessageTypes, out messageTypeIdentifier)) { foreach (string messageTypeString in messageTypeIdentifier.Split(';')) { MessageMetadata metadata = _metadataRegistry.GetMessageMetadata(messageTypeString); if (metadata == null) { continue; } messageMetadata.Add(metadata); } } using (var stream = new MemoryStream(physicalMessage.Body)) { List <Type> messageTypesToDeserialize = messageMetadata.Select(metadata => metadata.MessageType).ToList(); return(serializers[contentType].Deserialize(stream, messageTypesToDeserialize) .Select(x => _logicalMessageFactory.Create(x.GetType(), x, physicalMessage.Headers)) .ToList()); } }
/// <summary> /// <see cref="IBus.Reply{T}(Action{T})"/> /// </summary> public void Reply <T>(Action <T> messageConstructor) { var instance = messageMapper.CreateInstance(messageConstructor); var options = new ReplyOptions(MessageBeingProcessed.ReplyToAddress, GetCorrelationId()); SendMessage(options, LogicalMessageFactory.Create(instance)); }
LogicalMessage Extract(TransportMessage transportMessage) { Type messageType = Type.GetType(transportMessage.MessageType, true, true); object message = serializer.Deserialize(transportMessage.Body, messageType); return(factory.Create(messageType, message, transportMessage.Headers)); }
/// <summary> /// <see cref="ISendOnlyBus.Send(object)"/> /// </summary> public ICallback SendLocal(object message) { //if we're a worker, send to the distributor data bus if (Settings.GetOrDefault <bool>("Worker.Enabled")) { return(SendMessage(new SendOptions(Settings.Get <Address>("MasterNode.Address")), LogicalMessageFactory.Create(message))); } return(SendMessage(new SendOptions(Configure.LocalAddress), LogicalMessageFactory.Create(message))); }
/// <summary> /// <see cref="ISendOnlyBus.Send{T}(Address,string,Action{T})"/> /// </summary> public ICallback Send <T>(Address address, string correlationId, Action <T> messageConstructor) { var options = new SendOptions(address) { CorrelationId = correlationId }; return(SendMessage(options, LogicalMessageFactory.Create(messageMapper.CreateInstance(messageConstructor)))); }
public ICallback Send(string destination, string correlationId, object message) { var options = new SendOptions(destination) { CorrelationId = correlationId }; return(SendMessages(options, LogicalMessageFactory.Create(message))); }
public ICallback Send <T>(string destination, string correlationId, Action <T> messageConstructor) { var options = new SendOptions(destination) { CorrelationId = correlationId }; return(SendMessages(options, LogicalMessageFactory.Create(CreateInstance(messageConstructor)))); }
/// <summary> /// <see cref="ISendOnlyBus.Send(Address,string,object)"/> /// </summary> public ICallback Send(Address address, string correlationId, object message) { var options = new SendOptions(address) { CorrelationId = correlationId }; return(SendMessage(options, LogicalMessageFactory.Create(message))); }
List <LogicalMessage> Deserialize(TransportMessage physicalMessage, List <MessageMetadata> messageMetadata) { using (MemoryStream stream = new MemoryStream(physicalMessage.Body)) { IMessageSerializer messageSerializer = serializationMapper.GetSerializer(physicalMessage.Headers); List <Type> messageTypesToDeserialize = messageMetadata.Select(metadata => metadata.MessageType).ToList(); return(messageSerializer.Deserialize(stream, messageTypesToDeserialize) .Select(x => logicalMessageFactory.Create(x.GetType(), x, physicalMessage.Headers)) .ToList()); } }
private void ExtractNative(IncomingContext context, TransportMessage transportMessage) { //assuming all inbound native messages are of the same type var serializer = new System.Xml.Serialization.XmlSerializer(typeof(TestCommand)); var memStream = new MemoryStream(transportMessage.Body); var resultingMessage = serializer.Deserialize(memStream); var logicalMessage = LogicalMessageFactory.Create(typeof(TestCommand), resultingMessage, transportMessage.Headers); context.LogicalMessages = new List <LogicalMessage> { logicalMessage }; }
List <LogicalMessage> Extract(TransportMessage physicalMessage) { if (physicalMessage.Body == null || physicalMessage.Body.Length == 0) { return(new List <LogicalMessage>()); } string messageTypeIdentifier; var messageMetadata = new List <MessageMetadata>(); if (physicalMessage.Headers.TryGetValue(Headers.EnclosedMessageTypes, out messageTypeIdentifier)) { foreach (var messageTypeString in messageTypeIdentifier.Split(';')) { var typeString = messageTypeString; if (DoesTypeHaveImplAddedByVersion3(typeString)) { continue; } if (IsV4OrBelowScheduledTask(typeString)) { typeString = typeof(ScheduledTask).AssemblyQualifiedName; } var metadata = MessageMetadataRegistry.GetMessageMetadata(typeString); if (metadata == null) { continue; } messageMetadata.Add(metadata); } if (messageMetadata.Count == 0 && physicalMessage.MessageIntent != MessageIntentEnum.Publish) { log.WarnFormat("Could not determine message type from message header '{0}'. MessageId: {1}", messageTypeIdentifier, physicalMessage.Id); } } using (var stream = new MemoryStream(physicalMessage.Body)) { var messageTypesToDeserialize = messageMetadata.Select(metadata => metadata.MessageType).ToList(); return(MessageSerializer.Deserialize(stream, messageTypesToDeserialize) .Select(x => LogicalMessageFactory.Create(x.GetType(), x, physicalMessage.Headers)) .ToList()); } }
List <LogicalMessage> Extract(IncomingMessage physicalMessage) { if (physicalMessage.Body == null || physicalMessage.Body.Length == 0) { return(new List <LogicalMessage>()); } string messageTypeIdentifier; var messageMetadata = new List <MessageMetadata>(); var headers = physicalMessage.Headers; if (headers.TryGetValue(Headers.EnclosedMessageTypes, out messageTypeIdentifier)) { foreach (var messageTypeString in messageTypeIdentifier.Split(';')) { var typeString = messageTypeString; var metadata = messageMetadataRegistry.GetMessageMetadata(typeString); if (metadata == null) { continue; } messageMetadata.Add(metadata); } if ( messageMetadata.Count == 0 && physicalMessage.GetMesssageIntent() != MessageIntentEnum.Publish) { log.Warn($"Could not determine message type from message header '{messageTypeIdentifier}'. MessageId: {physicalMessage.MessageId}"); } } using (var stream = new MemoryStream(physicalMessage.Body)) { var messageSerializer = serializationMapper.GetSerializer(headers); var typesToDeserialize = messageMetadata .Select(metadata => metadata.MessageType) .ToList(); return(messageSerializer.Deserialize(stream, typesToDeserialize) .Select(x => logicalMessageFactory.Create(x.GetType(), x)) .ToList()); } }
/// <summary> /// <see cref="IBus.Defer(DateTime,object)"/> /// </summary> public ICallback Defer(DateTime processAt, object message) { SendOptions options; if (Settings.GetOrDefault <bool>("Worker.Enabled")) { options = new SendOptions(Settings.Get <Address>("MasterNode.Address")); } else { options = new SendOptions(Configure.LocalAddress); } options.DeliverAt = processAt; options.EnforceMessagingBestPractices = false; return(SendMessage(options, LogicalMessageFactory.Create(message))); }
void InnerHandle(TransportMessage message) { var errorMessageReceived = new ImportFailedMessage(message); var logicalMessage = LogicalMessageFactory.Create(typeof(ImportFailedMessage), errorMessageReceived); using (var childBuilder = Builder.CreateChildBuilder()) { PipelineExecutor.CurrentContext.Set(childBuilder); foreach (var enricher in childBuilder.BuildAll <IEnrichImportedMessages>()) { enricher.Enrich(errorMessageReceived); } PipelineExecutor.InvokeLogicalMessagePipeline(logicalMessage); } Forwarder.Send(message, Settings.ErrorLogQueue); }
public void Raise <T>(T @event) { var messageType = typeof(T); EnsureMessageIsRegistered(messageType); var logicalMessage = LogicalMessageFactory.Create(messageType, @event); if (PipelineFactory.CurrentContext is RootContext) { using (var childBuilder = Builder.CreateChildBuilder()) { PipelineFactory.CurrentContext.Set(childBuilder); PipelineFactory.InvokeLogicalMessagePipeline(logicalMessage); } } else { PipelineFactory.InvokeLogicalMessagePipeline(logicalMessage); } }
void InnerHandle(TransportMessage message) { var receivedMessage = new ImportSuccessfullyProcessedMessage(message); using (var childBuilder = Builder.CreateChildBuilder()) { PipelineExecutor.CurrentContext.Set(childBuilder); foreach (var enricher in childBuilder.BuildAll <IEnrichImportedMessages>()) { enricher.Enrich(receivedMessage); } var logicalMessage = LogicalMessageFactory.Create(typeof(ImportSuccessfullyProcessedMessage), receivedMessage); PipelineExecutor.InvokeLogicalMessagePipeline(logicalMessage); } if (Settings.ForwardAuditMessages == true) { Forwarder.Send(message, Settings.AuditLogQueue); } }
public ICallback SendToSites(IEnumerable <string> siteKeys, object message) { Headers.SetMessageHeader(message, Headers.DestinationSites, string.Join(",", siteKeys.ToArray())); return(SendMessages(new SendOptions(MasterNodeAddress.SubScope("gateway")), LogicalMessageFactory.Create(message))); }
/// <summary> /// <see cref="ISendOnlyBus.Send(Address,object)"/> /// </summary> public ICallback Send(Address address, object message) { return(SendMessage(new SendOptions(address), LogicalMessageFactory.Create(message))); }
/// <summary> /// <see cref="ISendOnlyBus.Send(string,object)"/> /// </summary> public ICallback Send(string destination, object message) { return(SendMessage(new SendOptions(destination), LogicalMessageFactory.Create(message))); }
/// <summary> /// <see cref="ISendOnlyBus.Send{T}(Address,Action{T})"/> /// </summary> public ICallback Send <T>(Address address, Action <T> messageConstructor) { return(SendMessage(new SendOptions(address), LogicalMessageFactory.Create(messageMapper.CreateInstance(messageConstructor)))); }
/// <summary> /// <see cref="ISendOnlyBus.Send{T}(string,Action{T})"/> /// </summary> public ICallback Send <T>(string destination, Action <T> messageConstructor) { return(SendMessage(new SendOptions(destination), LogicalMessageFactory.Create(messageMapper.CreateInstance(messageConstructor)))); }
/// <summary> /// <see cref="ISendOnlyBus.Send(object)"/> /// </summary> public ICallback Send(object message) { var destination = GetDestinationForSend(message); return(SendMessage(new SendOptions(destination), LogicalMessageFactory.Create(message))); }
/// <summary> /// <see cref="IBus.Reply(object)"/> /// </summary> public void Reply(object message) { var options = new ReplyOptions(MessageBeingProcessed.ReplyToAddress, GetCorrelationId()); SendMessage(options, LogicalMessageFactory.Create(message)); }