/// <summary> /// Get message json body /// </summary> /// <param name="message"></param> /// <returns></returns> public static string GetJson(this Message message) { // https://github.com/Azure/azure-service-bus/issues/114 as is Server EnqueuedTimeUtc we use this to serialize the message //message.TimeToLive = TimeSpan.FromSeconds(10); var systemProperties = new Message.SystemPropertiesCollection(); // systemProperties.EnqueuedTimeUtc = DateTime.UtcNow.AddMinutes(1); var bindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetProperty; systemProperties.GetType().InvokeMember("EnqueuedTimeUtc", bindings, Type.DefaultBinder, systemProperties, new object[] { }); // workaround "ThrowIfNotReceived" by setting "SequenceNumber" value null systemProperties.GetType().InvokeMember("SequenceNumber", bindings, Type.DefaultBinder, systemProperties, new object[] { }); // message.systemProperties = systemProperties; bindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetProperty; message.GetType().InvokeMember("SystemProperties", bindings, Type.DefaultBinder, message, new object[] { systemProperties }); var json = JsonConvert.SerializeObject(message); return(json); }
public MessageBuilder WithLockToken(Guid lockToken) { Message.SystemPropertiesCollection systemProperties = _message.SystemProperties; Type type = systemProperties.GetType(); type.GetMethod("set_LockTokenGuid", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(systemProperties, new object[] { lockToken }); type.GetMethod("set_SequenceNumber", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(systemProperties, new object[] { 0 }); return(this); }