void ReportToBackend(CheckResult result, string customCheckId, string category, TimeSpan ttr) { var reportCustomCheckResult = new ReportCustomCheckResult { HostId = unicastBus.HostInformation.HostId, Host = unicastBus.HostInformation.DisplayName, EndpointName = configure.Settings.EndpointName(), CustomCheckId = customCheckId, Category = category, HasFailed = result.HasFailed, FailureReason = result.FailureReason, ReportedAt = DateTime.UtcNow }; serviceControlBackend.Send(reportCustomCheckResult, ttr); }
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); } }
public Task Send(ReportCustomCheckResult messageToSend) { return(Send(messageToSend, TimeSpan.MaxValue)); }