public static RabbitEventProperties Create(IBasicProperties p) { // RMQ, I dunno... properties and headers within headers and properties? if (!(p.Headers["properties"] is Dictionary <string, object> properties) || !(properties["headers"] is Dictionary <string, object> headers)) { return(new RabbitEventProperties()); } // in RMQ headers are just a bundle of strings, so this should be safe. var decodedHeaders = headers.ToDictionary( d => d.Key, d => Encoding.UTF8.GetString((byte[])d.Value)); return(new RabbitEventProperties { ContentType = DecodeHelpers.StringFromByteDictionaryOrDefault(properties, "content_type"), MessageId = DecodeHelpers.StringFromByteDictionaryOrDefault(properties, "message_id"), DeliveryMode = (int)properties["delivery_mode"], Headers = decodedHeaders, }); }
public static RabbitEvent Create(BasicDeliverEventArgs e) { var properties = e.BasicProperties; var headers = properties.Headers; return(new RabbitEvent { Channel = (int)headers["channel"], Connection = DecodeHelpers.StringFromByteDictionaryOrDefault(headers, "connection"), Exchange = DecodeHelpers.StringFromByteDictionaryOrDefault(headers, "exchange_name"), Node = DecodeHelpers.StringFromByteDictionaryOrDefault(headers, "node"), Payload = Convert.ToBase64String(e.Body), Properties = RabbitEventPropertiesCreator.Create(e.BasicProperties), User = DecodeHelpers.StringFromByteDictionaryOrDefault(headers, "user"), VHost = DecodeHelpers.StringFromByteDictionaryOrDefault(headers, "vhost"), Type = "published", Timestamp = DateTime.Now, // todo: the following is for queue capture, not yet supported Queue = UnsupportedString, RoutingKeys = new[] { UnsupportedString }, RoutedQueues = new[] { UnsupportedString }, }); }