Represents a message on the transport level, already serialized, ready to be sent or processed.
コード例 #1
0
 public RedisMessageTransaction(TransportMessage message, int deliveryCount, Func<Task> onCommit, Func<Task> onFail)
 {
     this.message = message;
     this.deliveryCount = deliveryCount;
     this.onCommit = onCommit;
     this.onFail = onFail;
 }
コード例 #2
0
 public QueueMessageTransaction(TransportMessage message, int retryCount, Func<Task> onCommit, Func<Task> onFail)
 {
     this.message = message;
     this.retryCount = retryCount;
     this.onCommit = onCommit;
     this.onFail = onFail;
 }
コード例 #3
0
ファイル: MessageBus.cs プロジェクト: jamesholcomb/NDomain
        private TransportMessage BuildTransportMessage(Message message, Subscription subscription)
        {
            JObject jsonPayload = message.Payload is JObject ? 
                                    (JObject)message.Payload
                                    : JObject.FromObject(message.Payload);

            var transportMessage = new TransportMessage();
            // reuse existing Id or create a new one
            transportMessage.Id = message.Headers.GetOrDefault(MessageHeaders.Id) ?? Guid.NewGuid().ToString();
            transportMessage.Name = message.Name;
            transportMessage.Body = jsonPayload;

            // copy original headers
            foreach (var header in message.Headers)
            {
                transportMessage.Headers[header.Key] = header.Value;
            }
            
            // add subscription headers
            transportMessage.Headers[MessageHeaders.Endpoint] = subscription.Endpoint; // destination queue / processor
            transportMessage.Headers[MessageHeaders.Component] = subscription.Component; //handler within the processor

            Console.WriteLine("Sending {0} to {1}", transportMessage.Name, subscription.Endpoint);

            return transportMessage;
        }
コード例 #4
0
        public async Task Send(TransportMessage message)
        {
            var endpoint = message.Headers[MessageHeaders.Endpoint];
            var queue = await GetQueue(endpoint);

            var queueMsg = BuildCloudQueueMessage(message);
            await queue.AddMessageAsync(queueMsg);
        }
コード例 #5
0
        public Task Send(TransportMessage message)
        {
            var endpoint = message.Headers[MessageHeaders.Endpoint];
            var queue = GetQueue(endpoint);

            var msg = BuildBrokeredMessage(message);
            return queue.SendAsync(msg);
        }
コード例 #6
0
        protected BrokeredMessage BuildBrokeredMessage(TransportMessage message)
        {
            var brokeredMessage = new BrokeredMessage(Serializer.Serialize(message.Body));
            brokeredMessage.MessageId = message.Id;
            brokeredMessage.Label = message.Name;

            foreach (var header in message.Headers)
            {
                brokeredMessage.Properties[header.Key] = header.Value;
            }

            return brokeredMessage;
        }
コード例 #7
0
        protected TransportMessage BuildMessage(BrokeredMessage brokeredMessage)
        {
            var message = new TransportMessage();
            message.Body = Serializer.Deserialize(brokeredMessage.GetBody<Stream>());
            message.Id = brokeredMessage.MessageId;
            message.Name = brokeredMessage.Label;

            foreach (var property in brokeredMessage.Properties)
            {
                message.Headers[property.Key] = property.Value.ToString();
            }

            return message;
        }
コード例 #8
0
        public async Task ProcessMessage(TransportMessage message)
        {

            var sw = Stopwatch.StartNew();
            await this.innerDispatcher.ProcessMessage(message);
            sw.Stop();

            var key = string.Format("{0}:{1}", message.Name, message.Headers[MessageHeaders.Component]);
            var counter = this.metrics.GetOrAdd(key, k => new Counter());
            Interlocked.Increment(ref counter.NMessages);
            Interlocked.Add(ref counter.TotalMS, sw.ElapsedMilliseconds);

            Trace.WriteLine(string.Format("Processed {0} in {1}ms with avg {2}ms", key, sw.ElapsedMilliseconds, counter.GetAvg().TotalMilliseconds));
        }
コード例 #9
0
ファイル: MessageContext.cs プロジェクト: mfelicio/NDomain
 public MessageContext(TransportMessage message, IDependencyResolver resolver)
 {
     this.Message = message;
     this.Resolver = resolver;
 }
コード例 #10
0
        private CloudQueueMessage BuildCloudQueueMessage(TransportMessage message)
        {
            var jsonMsg = JObject.FromObject(message);
            var msgBytes = (Serializer.Serialize(jsonMsg) as MemoryStream).ToArray();

            var queueMessage = new CloudQueueMessage(message.Id, "");
            queueMessage.SetMessageContent(msgBytes);

            return queueMessage;
        }
コード例 #11
0
ファイル: RedisTransport.cs プロジェクト: mfelicio/NDomain
 public Task Send(TransportMessage message)
 {
     return SendMultiple(new TransportMessage[] { message });
 }
コード例 #12
0
ファイル: LocalTransport.cs プロジェクト: mfelicio/NDomain
        public Task Send(TransportMessage message)
        {
            var endpoint = message.Headers[MessageHeaders.Endpoint];
            var endpointQueue = this.bus.GetEndpointQueue(endpoint);

            endpointQueue.Add(new LocalMessage(message));
            return Task.FromResult(true);
        }
コード例 #13
0
ファイル: LocalTransport.cs プロジェクト: mfelicio/NDomain
 public LocalMessage(TransportMessage message)
 {
     this.message = message;
     this.deliveryCount = 1;
 }
コード例 #14
0
 public LocalMessage(TransportMessage message)
 {
     this.message = message;
     this.retryCount = 0;
 }
コード例 #15
0
 public BrokeredMessageTransaction(BrokeredMessage source, TransportMessage message)
 {
     this.source = source;
     this.message = message;
 }
コード例 #16
0
ファイル: TransportSpecs.cs プロジェクト: mfelicio/NDomain
        private static TransportMessage CreateMessageFor(string endpoint)
        {
            var msg = new TransportMessage
                        {
                            Id = "id1",
                            Name = "msg",
                            Body = new Newtonsoft.Json.Linq.JObject()
                        };

            return msg.ForEndpoint(endpoint);
        }
コード例 #17
0
 public LocalMessage(TransportMessage message)
 {
     this.message       = message;
     this.deliveryCount = 1;
 }