Example #1
0
        public static EndpointDetails SendingEndpoint(IReadOnlyDictionary <string, string> headers)
        {
            var endpointDetails = new EndpointDetails();

            DictionaryExtensions.CheckIfKeyExists(Headers.OriginatingEndpoint, headers, s => endpointDetails.Name      = s);
            DictionaryExtensions.CheckIfKeyExists("NServiceBus.OriginatingMachine", headers, s => endpointDetails.Host = s);
            DictionaryExtensions.CheckIfKeyExists(Headers.OriginatingHostId, headers, s => endpointDetails.HostId      = Guid.Parse(s));

            if (!string.IsNullOrEmpty(endpointDetails.Name) && !string.IsNullOrEmpty(endpointDetails.Host))
            {
                return(endpointDetails);
            }

            string address = null;

            DictionaryExtensions.CheckIfKeyExists(Headers.OriginatingAddress, headers, s => address = s);

            if (address != null)
            {
                var queueAndMachinename = ExtractQueueAndMachineName(address);
                endpointDetails.Name = queueAndMachinename.Queue;
                endpointDetails.Host = queueAndMachinename.Machine;
                return(endpointDetails);
            }

            return(null);
        }
Example #2
0
        public static EndpointDetails ReceivingEndpoint(IReadOnlyDictionary <string, string> headers)
        {
            var endpoint = new EndpointDetails();

            if (headers.TryGetValue(Headers.HostId, out var hostIdHeader))
            {
                endpoint.HostId = Guid.Parse(hostIdHeader);
            }

            if (headers.TryGetValue(Headers.HostDisplayName, out var hostDisplayNameHeader))
            {
                endpoint.Host = hostDisplayNameHeader;
            }
            else
            {
                DictionaryExtensions.CheckIfKeyExists("NServiceBus.ProcessingMachine", headers, s => endpoint.Host = s);
            }

            DictionaryExtensions.CheckIfKeyExists(Headers.ProcessingEndpoint, headers, s => endpoint.Name = s);

            if (!string.IsNullOrEmpty(endpoint.Name) && !string.IsNullOrEmpty(endpoint.Host))
            {
                return(endpoint);
            }

            string address = null;

            //use the failed q to determine the receiving endpoint
            DictionaryExtensions.CheckIfKeyExists("NServiceBus.FailedQ", headers, s => address = s);

            // If we have a failed queue, then construct an endpoint from the failed queue information
            if (address != null)
            {
                var queueAndMachinename = ExtractQueueAndMachineName(address);

                if (string.IsNullOrEmpty(endpoint.Name))
                {
                    endpoint.Name = queueAndMachinename.Queue;
                }

                if (string.IsNullOrEmpty(endpoint.Host))
                {
                    endpoint.Host = queueAndMachinename.Machine;
                }

                // If we've been now able to get the endpoint details, return the new info.
                if (!string.IsNullOrEmpty(endpoint.Name) && !string.IsNullOrEmpty(endpoint.Host))
                {
                    return(endpoint);
                }
            }

            return(null);
        }
        void TryAddEndpoint(EndpointDetails endpointDetails, AuditEnricherContext context)
        {
            // for backwards compat with version before 4_5 we might not have a hostid
            if (endpointDetails.HostId == Guid.Empty)
            {
                return;
            }

            if (monitoring.IsNewInstance(endpointDetails))
            {
                context.AddForSend(new RegisterNewEndpoint
                {
                    DetectedAt = DateTime.UtcNow,
                    Endpoint   = endpointDetails
                });
            }
        }
        public bool IsNewInstance(EndpointDetails newEndpointDetails)
        {
            var endpointInstanceId = DeterministicGuid.MakeId(newEndpointDetails.Name, newEndpointDetails.HostId.ToString());

            return(endpoints.TryAdd(endpointInstanceId, null));
        }