当前位置: 首页>>代码示例>>C#>>正文


C# Messages.TransportMessage类代码示例

本文整理汇总了C#中Rebus.Messages.TransportMessage的典型用法代码示例。如果您正苦于以下问题:C# TransportMessage类的具体用法?C# TransportMessage怎么用?C# TransportMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TransportMessage类属于Rebus.Messages命名空间,在下文中一共展示了TransportMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleMessage

        public void HandleMessage(TransportMessage transportMessage, ITransactionContext transactionContext)
        {
            var message = transportMessage.GetMessageLabel();

            var options = new List<KeyOption>();

            if (DefaultOutputQueue != null)
            {
                options.Add(KeyOption.New('d',
                    () => { MoveMessage(transportMessage, transactionContext, DefaultOutputQueue); },
                    "Move to default queue '{0}'", DefaultOutputQueue));
            }

            if (transportMessage.Headers.ContainsKey(Headers.SourceQueue))
            {
                var sourceQueue = transportMessage.Headers[Headers.SourceQueue];

                options.Add(KeyOption.New('s',
                    () => { MoveMessage(transportMessage, transactionContext, sourceQueue); },
                    "Return to source queue '{0}'", sourceQueue));
            }

            options.Add(KeyOption.New('c', () =>
            {
                Console.Write("queue > ");
                var queueName = Console.ReadLine();
                MoveMessage(transportMessage, transactionContext, queueName);
            }, "Enter custom queue name to move message to"));

            Prompt(message, options);

            Text.PrintLine();
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:33,代码来源:ReturnToSourceQueue.cs

示例2: HandlePoisonMessage

        /// <summary>
        /// Handles the poisonous message by forwarding it to the configured error queue
        /// </summary>
        public async Task HandlePoisonMessage(TransportMessage transportMessage, ITransactionContext transactionContext, string errorDescription)
        {
            var headers = transportMessage.Headers;

            string messageId ;

            if (!headers.TryGetValue(Headers.MessageId, out messageId))
            {
                messageId = "<unknown>";
            }

            headers[Headers.ErrorDetails] = errorDescription;
            headers[Headers.SourceQueue] = _transport.Address;

            var errorQueueAddress = _simpleRetryStrategySettings.ErrorQueueAddress;

            try
            {
                _log.Error("Moving message with ID {0} to error queue '{1}' - reason: {2}", messageId, errorQueueAddress, errorDescription);

                await _transport.Send(errorQueueAddress, transportMessage, transactionContext);
            }
            catch (Exception exception)
            {
                _log.Error(exception, "Could not move message with ID {0} to error queue '{1}' - will pause {2} to avoid thrashing",
                    messageId, errorQueueAddress, MoveToErrorQueueFailedPause);

                // if we can't move to error queue, we need to avoid thrashing over and over
                await Task.Delay(MoveToErrorQueueFailedPause);
            }
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:34,代码来源:PoisonQueueErrorHandler.cs

示例3: Deserialize

        public async Task<Message> Deserialize(TransportMessage transportMessage)
        {
            string contentEncoding;

            if (!transportMessage.Headers.TryGetValue(Headers.ContentEncoding, out contentEncoding))
            {
                return await _serializer.Deserialize(transportMessage);
            }

            if (contentEncoding != GzipEncodingHeader)
            {
                var message = $"The message {transportMessage.GetMessageLabel()} has a '{Headers.ContentEncoding}' with the" +
                              $" value '{contentEncoding}', but this serializer decorator only knows how to decompress" +
                              $" '{GzipEncodingHeader}'";

                throw new ArgumentException(message);
            }

            var headers = transportMessage.Headers.Clone();
            var compressedBody = transportMessage.Body;

            headers.Remove(Headers.ContentEncoding);

            var uncompressedBody = _zipper.Unzip(compressedBody);
            var uncompressedTransportMessage = new TransportMessage(headers, uncompressedBody);

            return await _serializer.Deserialize(uncompressedTransportMessage);
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:28,代码来源:ZippingSerializerDecorator.cs

示例4: DispatchesDynamicMessageWhenDotNetTypeCannotBeFound

        public void DispatchesDynamicMessageWhenDotNetTypeCannotBeFound()
        {
            var gotTheMessage = new ManualResetEvent(false);

            string messageText = null;

            _builtinHandlerActivator.Handle<dynamic>(async message =>
            {
                Console.WriteLine("Received dynamic message: {0}", message);

                messageText = message.something.text;

                gotTheMessage.Set();
            });

            var headers = new Dictionary<string, string>
            {
                {Headers.MessageId, Guid.NewGuid().ToString()},
                {Headers.ContentType, "application/json;charset=utf-8"},
            };

            var transportMessage = new TransportMessage(headers, Encoding.UTF8.GetBytes(@"{
    ""something"": {
        ""text"": ""OMG dynamic JSON BABY!!""
    }
}"));
            _network.Deliver(InputQueueName, new InMemTransportMessage(transportMessage));

            gotTheMessage.WaitOrDie(TimeSpan.FromSeconds(2));

            Assert.That(messageText, Is.EqualTo("OMG dynamic JSON BABY!!"));
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:32,代码来源:TestDynamicJil.cs

示例5: CanMeasureTimeSpentInSteps

        public void CanMeasureTimeSpentInSteps()
        {
            var stats = new PipelineStepProfilerStats();
            var pipeline = new DefaultPipeline()
                .OnReceive(new Step300())
                .OnReceive(new Step100())
                .OnReceive(new Step200());

            var profiler = new PipelineStepProfiler(pipeline, stats);

            var receivePipeline = profiler.ReceivePipeline();
            var invoker = new DefaultPipelineInvoker();
            var transportMessage = new TransportMessage(new Dictionary<string, string>(), new byte[0]);

            using (new DefaultTransactionContextScope())
            {
                var stepContext = new IncomingStepContext(transportMessage, AmbientTransactionContext.Current);

                invoker.Invoke(stepContext, receivePipeline).Wait();

                var stepStats = stats.GetStats();

                Console.WriteLine(string.Join(Environment.NewLine, stepStats));
            }
        }
开发者ID:rebus-org,项目名称:Rebus,代码行数:25,代码来源:TestProfiler.cs

示例6: Send

        /// <summary>
        /// Sends the given <see cref="TransportMessage"/> to the queue with the specified globally addressable name
        /// </summary>
        public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context)
        {
            context.OnCommitted(async () =>
            {
                var headers = message.Headers.Clone();
                var queue = GetQueue(destinationAddress);
                var messageId = Guid.NewGuid().ToString();
                var popReceipt = Guid.NewGuid().ToString();
                var timeToBeReceivedOrNull = GetTimeToBeReceivedOrNull(headers);
                var queueVisibilityDelayOrNull = GetQueueVisibilityDelayOrNull(headers);
                var cloudQueueMessage = Serialize(messageId, popReceipt, headers, message.Body);

                try
                {
                    var options = new QueueRequestOptions {RetryPolicy = new ExponentialRetry()};
                    var operationContext = new OperationContext();

                    await queue.AddMessageAsync(cloudQueueMessage, timeToBeReceivedOrNull, queueVisibilityDelayOrNull, options, operationContext);
                }
                catch (Exception exception)
                {
                    throw new RebusApplicationException(exception, $"Could not send message with ID {cloudQueueMessage.Id} to '{destinationAddress}'");
                }
            });
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:28,代码来源:AzureStorageQueuesTransport.cs

示例7: IncomingStepContext

 /// <summary>
 /// Constructs the step context, initially stashing the given <see cref="TransportMessage"/> and <see cref="ITransactionContext"/> into its bag of objects
 /// </summary>
 public IncomingStepContext(TransportMessage message, ITransactionContext transactionContext)
 {
     Save(message);
     Save(transactionContext);
     
     transactionContext.Items[StepContextKey] = this;
 }
开发者ID:RichieYang,项目名称:Rebus,代码行数:10,代码来源:IncomingStepContext.cs

示例8: Send

        public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context)
        {
            await _innerTransport.Send(destinationAddress, message, context);

            _sentMessages.Add(message);

            MessageSent(message);
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:8,代码来源:TransportTap.cs

示例9: Send

        public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context)
        {
            if (_sendLatencyMs.HasValue)
            {
                await Task.Delay(_sendLatencyMs.Value);
            }

            await _innerTransport.Send(destinationAddress, message, context);
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:9,代码来源:In.cs

示例10: GetStringBody

        protected string GetStringBody(TransportMessage transportMessage)
        {
            if (transportMessage == null)
            {
                throw new InvalidOperationException("Cannot get string body out of null message!");
            }

            return _defaultEncoding.GetString(transportMessage.Body);
        }
开发者ID:nls75,项目名称:Rebus,代码行数:9,代码来源:SqsFixtureBase.cs

示例11: WorksWithPrefetch

        public void WorksWithPrefetch(int prefetch, int numberOfMessages)
        {
            var activator = Using(new BuiltinHandlerActivator());
            var counter = new SharedCounter(numberOfMessages);

            activator.Handle<string>(async str =>
            {
                counter.Decrement();
            });

            Console.WriteLine("Sending {0} messages", numberOfMessages);

            var transport = GetTransport();
            var tasks = Enumerable.Range(0, numberOfMessages)
                .Select(i => string.Format("THIS IS MESSAGE # {0}", i))
                .Select(async msg =>
                {
                    using (var context = new DefaultTransactionContext())
                    {
                        var headers = DefaultHeaders();
                        var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(msg));
                        var transportMessage = new TransportMessage(headers, body);

                        await transport.Send(_queueName, transportMessage, context);

                        await context.Complete();
                    }
                })
                .ToArray();

            Task.WhenAll(tasks).Wait();

            Console.WriteLine("Receiving {0} messages", numberOfMessages);

            var stopwatch = Stopwatch.StartNew();

            Configure.With(activator)
                .Transport(t =>
                {
                    t.UseAzureServiceBus(StandardAzureServiceBusTransportFactory.ConnectionString, _queueName, _mode)
                        .EnablePrefetching(prefetch);
                })
                .Options(o =>
                {
                    o.SetNumberOfWorkers(5);
                    o.SetMaxParallelism(10);
                })
                .Start();

            counter.WaitForResetEvent(timeoutSeconds: (int)(numberOfMessages * 0.1 + 3));

            var elapsedSeconds = stopwatch.Elapsed.TotalSeconds;

            Console.WriteLine("Receiving {0} messages took {1:0.0} s - that's {2:0.0} msg/s",
                numberOfMessages, elapsedSeconds, numberOfMessages / elapsedSeconds);
        }
开发者ID:ninocrudele,项目名称:Rebus,代码行数:56,代码来源:AzureServiceBusPrefetchTest.cs

示例12: Send

        async Task Send(IEnumerable<string> destinationAddressesList,
            TransportMessage transportMessage,
            ITransactionContext currentTransactionContext)
        {
            var sendTasks = destinationAddressesList
                .Select(address => _transport.Send(address, transportMessage, currentTransactionContext))
                .ToArray();

            await Task.WhenAll(sendTasks);
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:10,代码来源:SendOutgoingMessageStep.cs

示例13: MutateLegacyTransportMessage

        void MutateLegacyTransportMessage(IncomingStepContext context, Dictionary<string, string> headers, TransportMessage transportMessage)
        {
            var newHeaders = MapTrivialHeaders(headers);

            MapSpecialHeaders(newHeaders);

            newHeaders[LegacyMessageHeader] = "";

            context.Save(new TransportMessage(newHeaders, transportMessage.Body));
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:10,代码来源:MapLegacyHeadersIncomingStep.cs

示例14: Send

        public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context)
        {
            var outgoingMessages = context.GetOrAdd(OutgoingMessagesItemsKey, () =>
            {
                context.OnCommitted(async () => SendOutgoingMessages(context));

                return new ConcurrentQueue<OutgoingMessage>();
            });

            outgoingMessages.Enqueue(new OutgoingMessage(destinationAddress, message));
        }
开发者ID:netojoaop,项目名称:Rebus,代码行数:11,代码来源:RabbitMqTransport.cs

示例15: Deserialize

        public async Task<Message> Deserialize(TransportMessage transportMessage)
        {
            using (var source = new MemoryStream(transportMessage.Body))
            {
                var headers = transportMessage.Headers.Clone();

                var body = _runtimeTypeModel.Deserialize(source, null, GetMessageType(transportMessage.Headers));

                return new Message(headers, body);
            }
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:11,代码来源:ProtobufSerializer.cs


注:本文中的Rebus.Messages.TransportMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。