The message going out to the transport.
 /// <summary>
 /// Creates a new <see cref="MulticastTransportOperation" /> instance.
 /// </summary>
 // ReSharper disable once ParameterTypeCanBeEnumerable.Local
 public MulticastTransportOperation(OutgoingMessage message, Type messageType, DispatchConsistency requiredDispatchConsistency = DispatchConsistency.Default, List<DeliveryConstraint> deliveryConstraints = null)
 {
     Message = message;
     MessageType = messageType;
     DeliveryConstraints = deliveryConstraints ?? DeliveryConstraint.EmptyConstraints;
     RequiredDispatchConsistency = requiredDispatchConsistency;
 }
 /// <summary>
 /// Creates a new transport operation.
 /// </summary>
 /// <param name="message">The message to dispatch.</param>
 /// <param name="addressTag">The address to use when routing this message.</param>
 /// <param name="requiredDispatchConsistency">The required consistency level for the dispatch operation.</param>
 /// <param name="deliveryConstraints">The delivery constraints that must be honored by the transport.</param>
 public TransportOperation(OutgoingMessage message, AddressTag addressTag, DispatchConsistency requiredDispatchConsistency = DispatchConsistency.Default, List<DeliveryConstraint> deliveryConstraints = null)
 {
     Message = message;
     AddressTag = addressTag;
     RequiredDispatchConsistency = requiredDispatchConsistency;
     DeliveryConstraints = deliveryConstraints ?? DeliveryConstraint.EmptyConstraints;
 }
 /// <summary>
 /// Creates a new <see cref="UnicastTransportOperation" /> instance.
 /// </summary>
 public UnicastTransportOperation(OutgoingMessage message, string destination, DispatchConsistency requiredDispatchConsistency = DispatchConsistency.Default, List<DeliveryConstraint> deliveryConstraints = null)
 {
     Message = message;
     Destination = destination;
     DeliveryConstraints = deliveryConstraints ?? DeliveryConstraint.EmptyConstraints;
     RequiredDispatchConsistency = requiredDispatchConsistency;
 }
        /// <summary>
        /// Creates Transport Message.
        /// </summary>
        /// <returns>Transport Message.</returns>
        public static OutgoingMessage Create(MessageIntentEnum intent)
        {
            var message = new OutgoingMessage(CombGuid.Generate().ToString(), new Dictionary<string, string>(), new byte[0]);
            message.Headers[Headers.ControlMessageHeader] = Boolean.TrueString;
            message.Headers[Headers.MessageIntent] = intent.ToString();

            return message;
        }
        Task Send(byte[] body, string messageType, TimeSpan timeToBeReceived)
        {
            var headers = new Dictionary<string, string>();
            headers[Headers.EnclosedMessageTypes] = messageType;
            headers[Headers.ContentType] = ContentTypes.Json; //Needed for ActiveMQ transport
            headers[Headers.ReplyToAddress] = settings.LocalAddress();
            headers[Headers.MessageIntent] = sendIntent;

            var outgoingMessage = new OutgoingMessage(Guid.NewGuid().ToString(), headers, body);
            var operation = new TransportOperation(outgoingMessage, new UnicastAddressTag(serviceControlBackendAddress), deliveryConstraints: new List<DeliveryConstraint>
            {
                new DiscardIfNotReceivedBefore(timeToBeReceived)
            });
            return messageSender.Dispatch(new TransportOperations(operation), new TransportTransaction(), new ContextBag());
        }
        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);
            }
        }