Beispiel #1
0
        /// <summary>
        /// Get message payload.
        /// </summary>
        /// <param name="eventArgs">Message event args.</param>
        /// <param name="converters">A collection of json converters <see cref="JsonConverter"/>.</param>
        /// <typeparam name="T">Type of a message body.</typeparam>
        /// <returns>Object of type <see cref="T"/>.</returns>
        public static T GetPayload <T>(this BasicDeliverEventArgs eventArgs, IEnumerable <JsonConverter> converters)
        {
            eventArgs.EnsureIsNotNull();
            var messageString = Encoding.UTF8.GetString(eventArgs.Body.ToArray());

            return(JsonConvert.DeserializeObject <T>(messageString, converters.ToArray()));
        }
Beispiel #2
0
        /// <summary>
        /// Get message payload as an anonymous object.
        /// </summary>
        /// <param name="eventArgs">Message event args.</param>
        /// <param name="anonymousTypeObject">An anonymous object base.</param>
        /// <param name="settings">Serializer settings <see cref="JsonSerializerSettings"/>.</param>
        /// <typeparam name="T">Type of an anonymous object.</typeparam>
        /// <returns>Anonymous object.</returns>
        public static T GetAnonymousPayload <T>(this BasicDeliverEventArgs eventArgs, T anonymousTypeObject, JsonSerializerSettings settings)
        {
            eventArgs.EnsureIsNotNull();
            var messageString = Encoding.UTF8.GetString(eventArgs.Body.ToArray());

            return(JsonConvert.DeserializeAnonymousType <T>(messageString, anonymousTypeObject, settings));
        }
Beispiel #3
0
 /// <summary>
 /// Get message from BasicDeliverEventArgs body.
 /// </summary>
 /// <param name="eventArgs">Message event args.</param>
 /// <returns>Message as a string.</returns>
 public static string GetMessage(this BasicDeliverEventArgs eventArgs)
 {
     eventArgs.EnsureIsNotNull();
     return(Encoding.UTF8.GetString(eventArgs.Body.ToArray()));
 }