private static void Connect() { ContextFactoryProperties cfp = new ContextFactoryProperties(); cfp.SolClientLogLevel = SolLogLevel.Warning; cfp.LogToConsoleError(); ContextFactory.Instance.Init(cfp); SessionProperties sessionProps = new SessionProperties(); sessionProps.Host = "tcp://mr4yqbkp31ewl.messaging.solace.cloud:20992"; sessionProps.VPNName = "msgvpn-9xboqhaaj7p"; sessionProps.UserName = "******"; sessionProps.Password = "******"; sessionProps.ReconnectRetries = 3; IContext context = ContextFactory.Instance.CreateContext(new ContextProperties(), null); session = context.CreateSession(sessionProps, HandleMessage, HandleSession); try { ReturnCode returnCode = session.Connect(); if (returnCode == ReturnCode.SOLCLIENT_OK) { MyNickName = "Peppe"; session.Subscribe(ContextFactory.Instance.CreateTopic("test"), true); MessageBox.Show("Yes"); } } catch (OperationErrorException ex) { MessageBox.Show(ex.Message); } }
// GET: Publish public ActionResult Subscribes() { var 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 TopicSubscriber topicSubscriber = new TopicSubscriber(_vpnName, _userName, _password); // Run the application within the context and against the host topicSubscriber.Run(context, _host); } } catch (Exception ex) { Console.WriteLine("Exception thrown: {0}", ex.Message); } finally { // Dispose Solace Systems Messaging API ContextFactory.Instance.Cleanup(); } return(View()); }
public SolaceMessagingService(ILoggingService loggingService, IConfiguration config, IMessageSerializer serializer, string uniqueClientName) { this.serializer = serializer; this.uniqueClientName = uniqueClientName; this.config = config; this.loggingService = loggingService; this.log = loggingService.GetCurrentClassLogger(); ContextFactoryProperties cfp = new ContextFactoryProperties() { SolClientLogLevel = SolLogLevel.Debug }; //Direct logging to our logger // cfp.LogDelegate = (s) => log.Debug($"Solace log: {s.LogLevel}, {s.LoggerName}, {s.LogException}, {s.LogMessage}"); ContextFactory.Instance.Init(cfp); var configBasedConnectionDetails = new ConnectionDetails(config); if (!string.IsNullOrEmpty(configBasedConnectionDetails.Server)) { Init(configBasedConnectionDetails); } }
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]; // 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 TopicPublisher topicPublisher = new TopicPublisher() { VPNName = vpnname, UserName = username, Password = password }; // Run the application within the context and against the host topicPublisher.Run(context, host); } } catch (Exception ex) { Console.WriteLine("Exception thrown: {0}", ex.Message); Console.ReadKey(); } finally { // Dispose Solace Systems Messaging API ContextFactory.Instance.Cleanup(); } Console.WriteLine("Finished."); Console.ReadKey(); }
private void InitializeSolaceAPI(string logLevel) { // Initialize the API & set API logging var cfp = new ContextFactoryProperties(); // TODO: Set log level cfp.SolClientLogLevel = GetSolaceLogLevel(logLevel); // TODO: Delegate logs to the wrapper's logging factory cfp.LogDelegate = OnSolaceApiLog; // Must init the API before using any of its artifacts. ContextFactory.Instance.Init(cfp); }
static void Main(string[] args) { Console.WriteLine("Solace Systems Messaging API Tutorial, Copyright 2008-2015 Solace Systems, Inc."); 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. \"QueueConsumer 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 // 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 using (QueueConsumer queueConsumer = new QueueConsumer() { VPNName = defaultVPNName, UserName = defaultUsername, }) { // Run the application within the context and against the host queueConsumer.Run(context, host); } } } catch (Exception ex) { Console.WriteLine("Exception thrown: {0}", ex.Message); } finally { // Dispose Solace Systems Messaging API ContextFactory.Instance.Cleanup(); } Console.WriteLine("Finished."); }
/// <summary> /// Initializes the API context with a given log level /// </summary> /// <param name="logLevel"></param> public virtual void InitContext(SolLogLevel logLevel) { ContextFactoryProperties cfp = new ContextFactoryProperties(); // Set log level. cfp.SolClientLogLevel = logLevel; // Log errors to console. cfp.LogToConsoleError(); // Must init the API before using any of its artifacts. ContextFactory.Instance.Init(cfp); // Now we can print the version, after ContextFactory.Instance.Init() PrintVersion(); }
public void connect2Solace() { Console.WriteLine("In connect2Solace"); ContextFactoryProperties cfp = new ContextFactoryProperties(); // Set log level. cfp.SolClientLogLevel = SolLogLevel.Warning; // Log errors to console. cfp.LogToConsoleError(); // Must init the API before using any of its artifacts. ContextFactory.Instance.Init(cfp); ContextProperties contextProps = new ContextProperties(); SessionProperties sessionProps = new SessionProperties(); /******** Delete This ***********/ sHost = "54.219.47.90"; sUserName = "******"; sPassword = "******"; sVPNName = "default"; /********************************/ sessionProps.Host = sHost; sessionProps.UserName = sUserName; sessionProps.Password = sPassword; sessionProps.SSLValidateCertificate = false; sessionProps.VPNName = sVPNName; //Connection retry logic sessionProps.ConnectRetries = 3; //-1 means try to connect forever. sessionProps.ConnectTimeoutInMsecs = 5000; //10 seconds sessionProps.ReconnectRetries = 3; //-1 means try to reconnect forever. sessionProps.ReconnectRetriesWaitInMsecs = 5000; //wait for 5 seconds before retry // Compression is set as a number from 0-9, where 0 means "disable // compression", and 9 means max compression. The default is no // compression. // Selecting a non-zero compression level auto-selects the // compressed SMF port on the appliance, as long as no SMF port is // explicitly specified. //sessionProps.CompressionLevel = 9; #region Create the Context context = ContextFactory.Instance.CreateContext(contextProps, null); #endregion #region Create and connect the Session session = context.CreateSession(sessionProps, null, null); session.Connect(); #endregion }
/// <summary> /// Allow the RedirectLogs to initialize /// the API to redirect the logs to LogItToErrorConsole. /// </summary> public override void InitContext() { ContextFactoryProperties cfpProperties = new ContextFactoryProperties(); if (PrintLogsToConsole) { // Print to error console delegate. cfpProperties.LogDelegate += LogItToErrorConsole; } // The logging level. cfpProperties.SolClientLogLevel = SolLogLevel.Debug; // Initialize the API. ContextFactory.Instance.Init(cfpProperties); }
private void InitializeSolaceAPI(string logLevel) { // Initialize the API & set API logging var cfp = new ContextFactoryProperties(); // Set log level cfp.SolClientLogLevel = GetSolaceLogLevel(logLevel); // Delegate logs to the wrapper's logging factory cfp.LogDelegate += OnSolaceApiLog; // Must init the API before using any of its artifacts. try { ContextFactory.Instance.Init(cfp); } catch (FatalErrorException ex) { logger.Error(ex, ex.Message); throw new MessagingException("Failed to Initial Solace API", ex); } }
/// <summary> /// Initialize the Solace .NET API /// </summary> /// <param name="service"></param> public void Initialize(MatchingEngine service) { // Ignore call if we are already initialized if (this._isInitialized) { return; } this._parent = service; this._config = this._parent.ServiceConfig; // Initialize the API log.Info("Initializing Solace .NET API"); var cfp = new ContextFactoryProperties(); cfp.SolClientLogLevel = SolLogLevel.Warning; ContextFactory.Instance.Init(cfp); // Flag we are initialized this._isInitialized = true; }
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."); }
static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: TopicPublisher <host> <username>@<vpnname> <password>"); Trace.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>"); Trace.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]; // 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)) { #region Solace //host = "mr22gx8ufrq6kv.messaging.solace.cloud:20864"; //vpnname = "msgvpn-2pmh5qsq7h33"; //username = "******"; //password = "******"; #endregion // Create the application using (TopicSubscriber topicSubscriber = new TopicSubscriber() { VPNName = vpnname, UserName = username, Password = password }) { // Run the application within the context and against the host topicSubscriber.Run(context, host); } } } catch (Exception ex) { Console.WriteLine("Exception thrown: {0}", ex.Message); Trace.WriteLine("Exception thrown: " + ex.Message); } finally { // Dispose Solace Systems Messaging API ContextFactory.Instance.Cleanup(); } Console.WriteLine("Finished."); Trace.WriteLine("Finished."); }
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."); }