public async Task Send(ReportCustomCheckResult result, TimeSpan timeToBeReceived) { result.Apply(settings); byte[] body; using (var stream = new MemoryStream()) { var resultAsObject = new object[] { result }; serializer.WriteObject(stream, resultAsObject); body = stream.ToArray(); } //hack to remove the type info from the json var bodyString = Encoding.UTF8.GetString(body); var toReplace = "\"__type\":\"ReportCustomCheckResult:#ServiceControl.Plugin.CustomChecks.Messages\""; bodyString = bodyString.Replace(toReplace, "\"$type\":\"ServiceControl.Plugin.CustomChecks.Messages.ReportCustomCheckResult, ServiceControl\""); body = Encoding.UTF8.GetBytes(bodyString); // end hack var headers = new Dictionary<string, string>(); headers[Headers.EnclosedMessageTypes] = result.GetType().FullName; headers[Headers.ContentType] = ContentTypes.Json; //Needed for ActiveMQ transport headers[Headers.ReplyToAddress] = settings.LocalAddress(); headers[Headers.MessageIntent] = sendIntent; try { var outgoingMessage = new OutgoingMessage(Guid.NewGuid().ToString(), headers, body); var operation = new TransportOperation(outgoingMessage, new UnicastAddressTag(serviceControlBackendAddress), deliveryConstraints: new List<DeliveryConstraint> { new DiscardIfNotReceivedBefore(timeToBeReceived) }); await messageSender.Dispatch(new TransportOperations(operation), new TransportTransaction(), new ContextBag()).ConfigureAwait(false); circuitBreaker.Success(); } catch (Exception ex) { await circuitBreaker.Failure(ex).ConfigureAwait(false); } }