public Message ToMessage(object obj, MessageProperties messageProperties) { try { if (obj is Message) { var embeddedMessage = obj as Message; if (embeddedMessage.Content is string) { embeddedMessage.MessageProperties.ContentType = "text/string"; return(embeddedMessage); } else if (embeddedMessage.Content is JObject) { var message = new Message(Encoding.UTF8.GetBytes(embeddedMessage.Content.ToString()), embeddedMessage.MessageProperties); message.MessageProperties.ContentType = _contentType; message.MessageProperties.MessageBodyNativeType = messageProperties.MessageBodyNativeType; return(message); } } else if (obj is JObject) { var message = new Message(Encoding.UTF8.GetBytes(obj.ToString()), messageProperties); message.MessageProperties.ContentType = _contentType; return(message); } else { messageProperties.MessageBodyNativeType = obj.GetType().AssemblyQualifiedName; var message = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)), messageProperties); message.MessageProperties.ContentType = _contentType; return(message); } throw new ApplicationException("Do not know how to convert message."); } catch (Exception ex) { log.Error(ex); return(null); } }
public Message(object content, MessageProperties messageProperties) { this.MessageProperties = messageProperties; this.Content = content; }
public Message ToMessage(object obj, MessageProperties messageProperties) { var message = new Message(obj, messageProperties); return(message); }
public Message() { this.MessageProperties = new MessageProperties(); }
public Message ToMessage(object obj, MessageProperties messageProperties) { return(new Message(obj, messageProperties)); }