Exemplo n.º 1
0
        private void SetDefaultClientProperties(IDictionary <string, object> clientProperties)
        {
            var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            var applicationNameAndPath = Environment.GetCommandLineArgs()[0];
            var applicationName        = Path.GetFileName(applicationNameAndPath);
            var applicationPath        = Path.GetDirectoryName(applicationNameAndPath);
            var hostname = Environment.MachineName;
            var product  = Product ?? applicationName;
            var platform = Platform ?? hostname;

            clientProperties.Add("client_api", "EasyNetQ");
            clientProperties.Add("product", product);
            clientProperties.Add("platform", platform);
            clientProperties.Add("version", version);
            clientProperties.Add("easynetq_version", version);
            clientProperties.Add("application", applicationName);
            clientProperties.Add("application_location", applicationPath);
            clientProperties.Add("machine_name", hostname);
            clientProperties.Add("user", UserName);
            clientProperties.Add("connected", DateTime.Now.ToString("MM/dd/yy HH:mm:ss"));
            clientProperties.Add("requested_heartbeat", RequestedHeartbeat.ToString());
            clientProperties.Add("timeout", Timeout.ToString());
            clientProperties.Add("publisher_confirms", PublisherConfirms.ToString());
            clientProperties.Add("persistent_messages", PersistentMessages.ToString());
        }
Exemplo n.º 2
0
        private void SetDefaultClientProperties(IDictionary <string, object> clientProperties)
        {
            string applicationNameAndPath = null;

#if NET_CORE
            var version = this.GetType().GetTypeInfo().Assembly.GetName().Version.ToString();
#else
            var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            applicationNameAndPath = Environment.GetCommandLineArgs()[0];
#endif



            var applicationName = "unknown";
            var applicationPath = "unknown";
            if (!string.IsNullOrWhiteSpace(applicationNameAndPath))
            {
                // Note: When running the application in an Integration Services Package (SSIS) the
                // Environment.GetCommandLineArgs()[0] can return null, and therefor it is not possible to get
                // the filename or directory name.
                try
                {
                    // Will only throw an exception if the applicationName contains invalid characters, is empty, or too long
                    // Silently catch the exception, as we will just leave the application name and path to "unknown"
                    applicationName = Path.GetFileName(applicationNameAndPath);
                    applicationPath = Path.GetDirectoryName(applicationNameAndPath);
                }
                catch (ArgumentException) { }
                catch (PathTooLongException) { }
            }

#if NET_CORE
            var hostname = System.Net.Dns.GetHostName();
#else
            var hostname = Environment.MachineName;
#endif

            var product  = Product ?? applicationName;
            var platform = Platform ?? hostname;

            clientProperties.Add("client_api", "EasyNetQ");
            clientProperties.Add("product", product);
            clientProperties.Add("platform", platform);
            clientProperties.Add("version", version);
            clientProperties.Add("easynetq_version", version);
            clientProperties.Add("application", applicationName);
            clientProperties.Add("application_location", applicationPath);
            clientProperties.Add("machine_name", hostname);
            clientProperties.Add("user", UserName);
            clientProperties.Add("connected", DateTime.UtcNow.ToString("u")); // UniversalSortableDateTimePattern: yyyy'-'MM'-'dd HH':'mm':'ss'Z'
            clientProperties.Add("requested_heartbeat", RequestedHeartbeat.ToString());
            clientProperties.Add("timeout", Timeout.ToString());
            clientProperties.Add("publisher_confirms", PublisherConfirms.ToString());
            clientProperties.Add("persistent_messages", PersistentMessages.ToString());
        }
 private static IPublisherConfirms ConfigureChannel(ChannelConfiguration configuration, IModel channel)
 {
     if (configuration.PublisherConfirmsOn)
     {
         channel.ConfirmSelect();
         var publisherConfirms = new PublisherConfirms();
         channel.BasicAcks  += publisherConfirms.SuccessfulPublish;
         channel.BasicNacks += publisherConfirms.FailedPublish;
         return(publisherConfirms);
     }
     return(null);
 }