public static void UpdateAmqpMessageHeadersAndProperties(AmqpMessage message, EventData eventData, bool copyUserProeperties = true) { if (!string.IsNullOrEmpty(eventData.Publisher)) { message.MessageAnnotations.Map["x-opt-publisher"] = eventData.Publisher; } if (eventData.PartitionKey != null) { message.MessageAnnotations.Map["x-opt-partition-key"] = eventData.PartitionKey; } if (copyUserProeperties && eventData.Properties.Count > 0) { if (message.ApplicationProperties == null) { message.ApplicationProperties = new ApplicationProperties(); } foreach (KeyValuePair <string, object> property in eventData.Properties) { object obj = null; if (!MessageConverter.TryGetAmqpObjectFromNetObject(property.Value, MappingType.ApplicationProperty, out obj)) { continue; } message.ApplicationProperties.Map[property.Key] = obj; } } }
private static AmqpMessage CreateAmqpMessageFromSbmpMessage(BrokeredMessage brokeredMessage) { AmqpMessage amqpMessage; object obj = brokeredMessage.ClearBodyObject(); object obj1 = null; if (obj != null) { MessageConverter.TryGetAmqpObjectFromNetObject(obj, MappingType.MessageBody, out obj1); } if (obj1 != null) { AmqpValue amqpValue = new AmqpValue() { Value = obj1 }; amqpMessage = AmqpMessage.Create(amqpValue); } else if (brokeredMessage.BodyStream == null) { amqpMessage = AmqpMessage.Create(); } else { if (brokeredMessage.BodyStream.CanSeek && brokeredMessage.BodyStream.Position != (long)0) { throw new InvalidOperationException(SRClient.CannotSerializeMessageWithPartiallyConsumedBodyStream); } amqpMessage = AmqpMessage.Create(brokeredMessage.BodyStream, false); } return(amqpMessage); }
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); }
public static void UpdateAmqpMessageHeadersAndProperties(AmqpMessage message, BrokeredMessage brokeredMessage, bool amqpClient) { BrokeredMessage.MessageMembers initializedMembers = brokeredMessage.InitializedMembers; if ((int)(initializedMembers & BrokeredMessage.MessageMembers.DeliveryCount) != 0) { message.Header.DeliveryCount = new uint?((uint)(brokeredMessage.DeliveryCount - (amqpClient ? 1 : 0))); } if ((int)(initializedMembers & BrokeredMessage.MessageMembers.TimeToLive) != 0 && brokeredMessage.TimeToLive != TimeSpan.MaxValue) { message.Header.Ttl = new uint?((uint)brokeredMessage.TimeToLive.TotalMilliseconds); } if ((int)(initializedMembers & BrokeredMessage.MessageMembers.EnqueuedTimeUtc) != 0) { message.MessageAnnotations.Map["x-opt-enqueued-time"] = brokeredMessage.EnqueuedTimeUtc; } if ((int)(initializedMembers & BrokeredMessage.MessageMembers.SequenceNumber) != 0) { message.MessageAnnotations.Map["x-opt-sequence-number"] = brokeredMessage.SequenceNumber; } if (amqpClient && (int)(initializedMembers & BrokeredMessage.MessageMembers.LockedUntilUtc) != 0) { message.MessageAnnotations.Map["x-opt-locked-until"] = brokeredMessage.LockedUntilUtc; } if (amqpClient && (int)(initializedMembers & BrokeredMessage.MessageMembers.Publisher) != 0) { message.MessageAnnotations.Map["x-opt-publisher"] = brokeredMessage.Publisher; } if (amqpClient && (int)(initializedMembers & BrokeredMessage.MessageMembers.PartitionKey) != 0) { message.MessageAnnotations.Map["x-opt-partition-key"] = brokeredMessage.PartitionKey; } if (brokeredMessage.ArePropertiesModifiedByBroker && brokeredMessage.Properties.Count > 0) { if (message.ApplicationProperties == null) { message.ApplicationProperties = new ApplicationProperties(); } foreach (KeyValuePair <string, object> property in brokeredMessage.Properties) { object obj = null; if (!MessageConverter.TryGetAmqpObjectFromNetObject(property.Value, MappingType.ApplicationProperty, out obj)) { continue; } message.ApplicationProperties.Map[property.Key] = obj; } } }
private Outcome GetModifiedOutcome(IDictionary <string, object> propertiesToModify, bool undeliverableHere) { object obj; Modified modified = new Modified(); if (undeliverableHere) { modified.UndeliverableHere = new bool?(true); } if (propertiesToModify != null) { modified.MessageAnnotations = new Fields(); foreach (KeyValuePair <string, object> keyValuePair in propertiesToModify) { if (!MessageConverter.TryGetAmqpObjectFromNetObject(keyValuePair.Value, MappingType.ApplicationProperty, out obj)) { continue; } modified.MessageAnnotations.Add(keyValuePair.Key, obj); } } return(modified); }
private Rejected GetRejectedOutcome(IDictionary <string, object> propertiesToModify, string deadLetterReason, string deadLetterErrorDescription) { object obj; Rejected rejectedOutcome = AmqpConstants.RejectedOutcome; if (deadLetterReason != null || deadLetterErrorDescription != null || propertiesToModify != null) { Rejected rejected = new Rejected(); Microsoft.ServiceBus.Messaging.Amqp.Framing.Error error = new Microsoft.ServiceBus.Messaging.Amqp.Framing.Error() { Condition = ClientConstants.DeadLetterName, Info = new Fields() }; rejected.Error = error; rejectedOutcome = rejected; if (deadLetterReason != null) { rejectedOutcome.Error.Info.Add("DeadLetterReason", deadLetterReason); } if (deadLetterErrorDescription != null) { rejectedOutcome.Error.Info.Add("DeadLetterErrorDescription", deadLetterErrorDescription); } if (propertiesToModify != null) { foreach (KeyValuePair <string, object> keyValuePair in propertiesToModify) { if (!MessageConverter.TryGetAmqpObjectFromNetObject(keyValuePair.Value, MappingType.ApplicationProperty, out obj)) { continue; } rejectedOutcome.Error.Info.Add(keyValuePair.Key, obj); } } } return(rejectedOutcome); }