本文整理汇总了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());
}
示例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;
}
示例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);
}
}