public static AmqpMessage BrokerGetMessage(BrokeredMessage brokeredMessage) { AmqpMessage messageId = null; bool flag = true; if (brokeredMessage.MessageFormat == BrokeredMessageFormat.PassthroughAmqp) { flag = false; messageId = AmqpMessage.CreateAmqpStreamMessage((BufferListStream)brokeredMessage.BodyStream, true); } else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.Amqp) { messageId = AmqpMessage.CreateAmqpStreamMessage(brokeredMessage.RawHeaderStream, brokeredMessage.BodyStream, true); } else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.AmqpEventData) { flag = false; BufferListStream bufferListStream = BufferListStream.Create(brokeredMessage.BodyStream, 512, true); messageId = AmqpMessage.CreateOutputMessage(bufferListStream, true); MessageAnnotations messageAnnotations = messageId.MessageAnnotations; messageAnnotations.Map["x-opt-sequence-number"] = brokeredMessage.SequenceNumber; Annotations map = messageAnnotations.Map; AmqpSymbol amqpSymbol = "x-opt-offset"; long offset = brokeredMessage.Offset; map[amqpSymbol] = offset.ToString(NumberFormatInfo.InvariantInfo); messageAnnotations.Map["x-opt-enqueued-time"] = brokeredMessage.EnqueuedTimeUtc; if (!string.IsNullOrEmpty(brokeredMessage.Publisher)) { messageAnnotations.Map["x-opt-publisher"] = brokeredMessage.Publisher; messageAnnotations.Map["x-opt-partition-key"] = brokeredMessage.Publisher; } } else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.Sbmp) { brokeredMessage.SetPropertiesAsModifiedByBroker(); messageId = MessageConverter.CreateAmqpMessageFromSbmpMessage(brokeredMessage); messageId.Properties.MessageId = brokeredMessage.MessageId; messageId.Properties.CorrelationId = brokeredMessage.CorrelationId; messageId.Properties.ContentType = brokeredMessage.ContentType; messageId.Properties.Subject = brokeredMessage.Label; messageId.Properties.To = brokeredMessage.To; messageId.Properties.ReplyTo = brokeredMessage.ReplyTo; messageId.Properties.GroupId = brokeredMessage.SessionId; messageId.Properties.ReplyToGroupId = brokeredMessage.ReplyToSessionId; } if (flag) { MessageConverter.UpdateAmqpMessageHeadersAndProperties(messageId, brokeredMessage, true); } return(messageId); }
public static AmqpMessage ClientGetMessage(BrokeredMessage brokeredMessage) { AmqpMessage messageId = MessageConverter.CreateAmqpMessageFromSbmpMessage(brokeredMessage); messageId.Properties.MessageId = brokeredMessage.MessageId; messageId.Properties.CorrelationId = brokeredMessage.CorrelationId; messageId.Properties.ContentType = brokeredMessage.ContentType; messageId.Properties.Subject = brokeredMessage.Label; messageId.Properties.To = brokeredMessage.To; messageId.Properties.ReplyTo = brokeredMessage.ReplyTo; messageId.Properties.GroupId = brokeredMessage.SessionId; messageId.Properties.ReplyToGroupId = brokeredMessage.ReplyToSessionId; if ((int)(brokeredMessage.InitializedMembers & BrokeredMessage.MessageMembers.TimeToLive) != 0) { messageId.Header.Ttl = new uint?((uint)brokeredMessage.TimeToLive.TotalMilliseconds); messageId.Properties.CreationTime = new DateTime?(DateTime.UtcNow); if ((AmqpConstants.MaxAbsoluteExpiryTime - messageId.Properties.CreationTime.Value) <= brokeredMessage.TimeToLive) { messageId.Properties.AbsoluteExpiryTime = new DateTime?(AmqpConstants.MaxAbsoluteExpiryTime); } else { Microsoft.ServiceBus.Messaging.Amqp.Framing.Properties properties = messageId.Properties; DateTime?creationTime = messageId.Properties.CreationTime; properties.AbsoluteExpiryTime = new DateTime?(creationTime.Value + brokeredMessage.TimeToLive); } } if ((int)(brokeredMessage.InitializedMembers & BrokeredMessage.MessageMembers.ScheduledEnqueueTimeUtc) != 0 && brokeredMessage.ScheduledEnqueueTimeUtc > DateTime.MinValue) { messageId.MessageAnnotations.Map.Add("x-opt-scheduled-enqueue-time", brokeredMessage.ScheduledEnqueueTimeUtc); } if ((int)(brokeredMessage.InitializedMembers & BrokeredMessage.MessageMembers.Publisher) != 0 && brokeredMessage.Publisher != null) { messageId.MessageAnnotations.Map.Add("x-opt-publisher", brokeredMessage.Publisher); } if ((int)(brokeredMessage.InitializedMembers & BrokeredMessage.MessageMembers.PartitionKey) != 0 && brokeredMessage.PartitionKey != null) { messageId.MessageAnnotations.Map.Add("x-opt-partition-key", brokeredMessage.PartitionKey); } foreach (KeyValuePair <string, object> property in brokeredMessage.Properties) { object obj = null; if (!MessageConverter.TryGetAmqpObjectFromNetObject(property.Value, MappingType.ApplicationProperty, out obj)) { continue; } messageId.ApplicationProperties.Map.Add(property.Key, obj); } return(messageId); }