Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: TopicPublisher <host> <username>@<vpnname> <password>");
                Environment.Exit(1);
            }

            string[] split = args[1].Split('@');
            if (split.Length != 2)
            {
                Console.WriteLine("Usage: TopicPublisher <host> <username>@<vpnname> <password>");
                Environment.Exit(1);
            }

            string    host     = args[0]; // Solace messaging router host name or IP address
            string    username = split[0];
            string    vpnname  = split[1];
            string    password = args[2];
            const int defaultTimeoutSeconds = 10; // request timeout

            // Initialize Solace Systems Messaging API with logging to console at Warning level
            ContextFactoryProperties cfp = new ContextFactoryProperties()
            {
                SolClientLogLevel = SolLogLevel.Warning
            };

            cfp.LogToConsoleError();
            ContextFactory.Instance.Init(cfp);

            try
            {
                // Context must be created first
                using (IContext context = ContextFactory.Instance.CreateContext(new ContextProperties(), null))
                {
                    // Create the application
                    BasicRequestor basicRequestor = new BasicRequestor()
                    {
                        VPNName        = vpnname,
                        UserName       = username,
                        Password       = password,
                        TimeoutSeconds = defaultTimeoutSeconds
                    };

                    // Run the application within the context and against the host
                    basicRequestor.Run(context, host);

                    // Write out the received reply
                    if (string.IsNullOrWhiteSpace(basicRequestor.Reply))
                    {
                        Console.WriteLine("Reply was not received in {0} seconds.", defaultTimeoutSeconds);
                    }
                    else
                    {
                        Console.WriteLine("Received reply: {0}", basicRequestor.Reply);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }
            finally
            {
                // Dispose Solace Systems Messaging API
                ContextFactory.Instance.Cleanup();
            }
            Console.WriteLine("Finished.");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if ((args.Length < 1) || string.IsNullOrWhiteSpace(args[0]))
            {
                Console.WriteLine("Please provide a parameter: non-empty value for the Solace messaging router host name or IP address, e.g. \"BasicRequestor 192.168.1.111\"");
                Environment.Exit(1);
            }

            string host = args[0];                           // Solace messaging router host name or IP address

            const string defaultVPNName        = "default";  // Solace messaging router VPN name
            const string defaultUsername       = "******"; // client username on the Solace messaging router VPN
            const int    defaultTimeoutSeconds = 10;         // request timeout

            // Initialize Solace Systems Messaging API with logging to console at Warning level
            ContextFactoryProperties cfp = new ContextFactoryProperties()
            {
                SolClientLogLevel = SolLogLevel.Warning
            };

            cfp.LogToConsoleError();
            ContextFactory.Instance.Init(cfp);

            try
            {
                // Context must be created first
                using (IContext context = ContextFactory.Instance.CreateContext(new ContextProperties(), null))
                {
                    // Create the application
                    BasicRequestor basicRequestor = new BasicRequestor()
                    {
                        VPNName        = defaultVPNName,
                        UserName       = defaultUsername,
                        TimeoutSeconds = defaultTimeoutSeconds
                    };

                    // Run the application within the context and against the host
                    basicRequestor.Run(context, host);

                    // Write out the received reply
                    if (string.IsNullOrWhiteSpace(basicRequestor.Reply))
                    {
                        Console.WriteLine("Reply was not received in {0} seconds.", defaultTimeoutSeconds);
                    }
                    else
                    {
                        Console.WriteLine("Received reply: {0}", basicRequestor.Reply);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception thrown: {0}", ex.Message);
            }
            finally
            {
                // Dispose Solace Systems Messaging API
                ContextFactory.Instance.Cleanup();
            }
            Console.WriteLine("Finished.");
        }