Esempio n. 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);
        }
        public static EndpointDetails SendingEndpoint(IDictionary <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);
            }

            var address = Address.Undefined;

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

            if (address != Address.Undefined)
            {
                endpointDetails.Name = address.Queue;
                endpointDetails.Host = address.Machine;
                return(endpointDetails);
            }

            return(null);
        }
        public static EndpointDetails SendingEndpoint(IDictionary<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;
            }

            var address = Address.Undefined;
            DictionaryExtensions.CheckIfKeyExists(Headers.OriginatingAddress, headers, s => address = Address.Parse(s));

            if (address != Address.Undefined)
            {
                endpointDetails.Name = address.Queue;
                endpointDetails.Host = address.Machine;
                return endpointDetails;
            }

            return null;
        }
        public static EndpointDetails ReceivingEndpoint(IDictionary <string, string> headers)
        {
            var    endpoint = new EndpointDetails();
            string hostIdHeader;

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

            string hostDisplayNameHeader;

            if (headers.TryGetValue(Headers.HostDisplayName, out 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);
            }

            var address = Address.Undefined;

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

            // If we have a failed queue, then construct an endpoint from the failed queue information
            if (address != Address.Undefined)
            {
                if (string.IsNullOrEmpty(endpoint.Name))
                {
                    endpoint.Name = address.Queue;
                }

                if (string.IsNullOrEmpty(endpoint.Host))
                {
                    endpoint.Host = address.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);
        }
        public static EndpointDetails ReceivingEndpoint(IDictionary<string, string> headers)
        {
            var endpoint = new EndpointDetails();
            string hostIdHeader;

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

            string hostDisplayNameHeader;

            if (headers.TryGetValue(Headers.HostDisplayName, out 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;
            }

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

            // If we have a failed queue, then construct an endpoint from the failed queue information
            if (address != Address.Undefined)
            {
                if (string.IsNullOrEmpty(endpoint.Name))
                {
                    endpoint.Name = address.Queue;
                }

                if (string.IsNullOrEmpty(endpoint.Host))
                {
                    endpoint.Host = address.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 HandlePost45Endpoint(EndpointDetails endpointDetails)
 {
     var endpointInstanceId = DeterministicGuid.MakeId(endpointDetails.Name, endpointDetails.HostId.ToString());
     if (KnownEndpointsCache.TryAdd(endpointInstanceId))
     {
         var registerEndpoint = new RegisterEndpoint
         {
             EndpointInstanceId = endpointInstanceId,
             Endpoint = endpointDetails,
             DetectedAt = DateTime.UtcNow
         };
         Bus.SendLocal(registerEndpoint);
     }
 }
 void HandlePre45Endpoint(EndpointDetails endpointDetails)
 {
     //since for pre 4.5 endpoints we wont have a hostid then fake one
     var endpointInstanceId = DeterministicGuid.MakeId(endpointDetails.Name, endpointDetails.Host);
     if (KnownEndpointsCache.TryAdd(endpointInstanceId))
     {
         var registerEndpoint = new RegisterEndpoint
         {
             //we don't set then endpoint instance id since we don't have the host id
             Endpoint = endpointDetails,
             DetectedAt = DateTime.UtcNow
         };
         Bus.SendLocal(registerEndpoint);
     }
 }
        void TryAddEndpoint(EndpointDetails endpointDetails)
        {
            // SendingEndpoint will be null for messages that are from v3.3.x endpoints because we don't
            // have the relevant information via the headers, which were added in v4.
            // The ReceivingEndpoint will be null for messages from v3.3.x endpoints that were successfully
            // processed because we dont have the information from the relevant headers.
            if (endpointDetails == null)
            {
                return;
            }

            // for backwards compat with version before 4_5 we might not have a hostid
            if (endpointDetails.HostId == Guid.Empty)
            {
                HandlePre45Endpoint(endpointDetails);
                return;
            }

            HandlePost45Endpoint(endpointDetails);
        }