當前位置: 首頁>>代碼示例>>C#>>正文


C# TransportMessage.IsControlMessage方法代碼示例

本文整理匯總了C#中NServiceBus.Unicast.Transport.TransportMessage.IsControlMessage方法的典型用法代碼示例。如果您正苦於以下問題:C# TransportMessage.IsControlMessage方法的具體用法?C# TransportMessage.IsControlMessage怎麽用?C# TransportMessage.IsControlMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NServiceBus.Unicast.Transport.TransportMessage的用法示例。


在下文中一共展示了TransportMessage.IsControlMessage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ToEventData

        private static EventData ToEventData(TransportMessage transportMessage, EventStoreMessageMetadata metadata)
        {
            metadata.CorrelationId = transportMessage.CorrelationId;
            metadata.MessageId = transportMessage.Id;
            metadata.ReplyTo = transportMessage.ReplyToAddress.ToString();
            metadata.Headers = transportMessage.Headers;
            var type = transportMessage.IsControlMessage() 
                              ? "ControlMessage" 
                              : transportMessage.Headers[Headers.EnclosedMessageTypes];

            byte[] data;
            string contentType;
            if (transportMessage.Headers.TryGetValue(Headers.ContentType, out contentType))
            {
                if (contentType != ContentTypes.Json)
                {
                    throw new InvalidOperationException("Invalid content type: "+contentType);
                }
                data = transportMessage.Body;
            }
            else
            {
                data = new byte[0];
            }
            return new EventData(Guid.NewGuid(), type, true, data, metadata.ToJsonBytes());
        }
開發者ID:eric-swann-q2,項目名稱:NServiceBus.EventStore,代碼行數:26,代碼來源:TransportMessageConverter.cs

示例2: Encode

        public IMessage Encode(TransportMessage message, ISession session)
        {
            if (message.IsControlMessage())
            {
                IMessage encoded = session.CreateBytesMessage();

                if (message.Body != null)
                {
                    encoded = session.CreateBytesMessage(message.Body);
                }

                return encoded;
            }

            return null;
        }
開發者ID:afyles,項目名稱:NServiceBus,代碼行數:16,代碼來源:ControlMessageEncoder.cs

示例3: MutateOutgoing

        /// <summary>
        /// Allow for a V3.X subscriber to subscribe/unsubscribe to a V2.6 publisher
        /// Mutate outgoing subscribe/unsubscribe messages: Create and serialize a completion message into the 
        /// body of the transport message.
        /// </summary>
        /// <param name="messages"></param>
        /// <param name="transportMessage"></param>
        public void MutateOutgoing(object[] messages, TransportMessage transportMessage)
        {
            if ((transportMessage.IsControlMessage() &&
                ((transportMessage.MessageIntent == MessageIntentEnum.Subscribe) ||
                (transportMessage.MessageIntent == MessageIntentEnum.Unsubscribe) ||
                (transportMessage.MessageIntent == MessageIntentEnum.Send))))
            {
                var stream = new MemoryStream();
                var completionMessage = new CompletionMessage();
                if (transportMessage.Headers.ContainsKey(Headers.ReturnMessageErrorCodeHeader))
                    completionMessage.ErrorCode = int.Parse(transportMessage.Headers[Headers.ReturnMessageErrorCodeHeader]);

                MessageSerializer.Serialize(new object[]  { completionMessage }, stream);
                transportMessage.Body = stream.ToArray();
                Log.Debug("Added Completion message and sending message intent: " + transportMessage.MessageIntent);
            }
        }
開發者ID:nghead,項目名稱:NServiceBus,代碼行數:24,代碼來源:OutgoingSubscriptionMessageMutator.cs


注:本文中的NServiceBus.Unicast.Transport.TransportMessage.IsControlMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。