예제 #1
0
        internal static global::Azure.Messaging.ServiceBus.ServiceBusMessage SerializeAndSend(IActorMessage msg, ServiceBusSender sender)
        {
            global::Azure.Messaging.ServiceBus.ServiceBusMessage message = BuildMessage(msg);

            sender.SendMessageAsync(message).Wait();
            return(message);
        }
예제 #2
0
        internal static global::Azure.Messaging.ServiceBus.ServiceBusMessage BuildMessage(IActorMessage msg)
        {
            byte[] msgBytes = TempSerialization.GetBytes <MsgType>(msg);

            var message = new global::Azure.Messaging.ServiceBus.ServiceBusMessage(msgBytes);

            if (msg is IServiceBusMessagePropertiesProvider)
            {
                message.ScheduledEnqueueTime = (msg as IServiceBusMessagePropertiesProvider).ScheduledEnqueueTimeUtc.HasValue ? (msg as IServiceBusMessagePropertiesProvider).ScheduledEnqueueTimeUtc.Value : message.ScheduledEnqueueTime;
                message.TimeToLive           = (msg as IServiceBusMessagePropertiesProvider).TimeToLive.HasValue ? (msg as IServiceBusMessagePropertiesProvider).TimeToLive.Value : message.TimeToLive;
                message.ContentType          = (msg as IServiceBusMessagePropertiesProvider).ContentType ?? message.ContentType;
                message.CorrelationId        = (msg as IServiceBusMessagePropertiesProvider).CorrelationId ?? message.CorrelationId;
                message.ReplyToSessionId     = (msg as IServiceBusMessagePropertiesProvider).ReplyToSessionId ?? message.ReplyToSessionId;
                message.SessionId            = (msg as IServiceBusMessagePropertiesProvider).SessionId ?? message.SessionId;
                message.MessageId            = (msg as IServiceBusMessagePropertiesProvider).MessageId ?? message.MessageId;
                message.PartitionKey         = (msg as IServiceBusMessagePropertiesProvider).PartitionKey ?? message.PartitionKey;
                if (null != (msg as IServiceBusMessagePropertiesProvider).ApplicationProperties)
                {
                    foreach (var t in (msg as IServiceBusMessagePropertiesProvider).ApplicationProperties)
                    {
                        message.ApplicationProperties.Add(t);
                    }
                }
            }

            if ((message is IActorMessageIdentifier) && String.IsNullOrWhiteSpace(message.MessageId))
            {
                message.MessageId = (msg as IActorMessageIdentifier).Id;
            }

            return(message);
        }