Esempio n. 1
0
        private PulsarSystem(ActorSystem actorSystem, PulsarClientConfigBuilder confBuilder)
        {
            _conf = confBuilder.ClientConfigurationData;
            var conf = _conf;

            _actorSystem = actorSystem;
            _conf        = conf;
            _cnxPool     = _actorSystem.ActorOf(ConnectionPool.Prop(conf), "ConnectionPool");
            _generator   = _actorSystem.ActorOf(IdGeneratorActor.Prop(), "IdGenerator");
            _lookup      = _actorSystem.ActorOf(BinaryProtoLookupService.Prop(_cnxPool, _generator, conf.ServiceUrl, conf.ListenerName, conf.UseTls, conf.MaxLookupRequest, conf.OperationTimeout), "BinaryProtoLookupService");

            if (conf.EnableTransaction)
            {
                _tcClient = _actorSystem.ActorOf(TransactionCoordinatorClient.Prop(_lookup, _cnxPool, _generator, conf));
                var cos = _tcClient.Ask <AskResponse>("Start").GetAwaiter().GetResult();
                if (cos.Failed)
                {
                    throw cos.Exception;
                }

                if ((int)cos.Data <= 0)
                {
                    throw new Exception($"Tranaction Coordinator has '{cos}' transaction handler");
                }
            }

            _client = _actorSystem.ActorOf(Props.Create <PulsarClientActor>(conf, _cnxPool, _tcClient, _lookup, _generator), "PulsarClient");
            _lookup.Tell(new SetClient(_client));
        }
Esempio n. 2
0
        public void Setup()
        {
            var clientConfig = new PulsarClientConfigBuilder()
                               .ServiceUrl("pulsar://localhost:6650");

            _pulsarSystem = PulsarSystem.GetInstance(clientConfig);

            _client = _pulsarSystem.NewClient();
        }
Esempio n. 3
0
        private PulsarSystem(PulsarClientConfigBuilder confBuilder, Action logSetup, Config confg)
        {
            _conf = confBuilder.ClientConfigurationData;
            var conf    = _conf;
            var logging = logSetup ?? _logSetup;

            logging();
            _conf = conf;
            var config = confg ?? ConfigurationFactory.ParseString(@"
            akka
            {
                loglevel = DEBUG
			    log-config-on-start = on 
                loggers=[""Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog""]
			    actor 
                {              
				      debug 
				      {
					      receive = on
					      autoreceive = on
					      lifecycle = on
					      event-stream = on
					      unhandled = on
				      }  
			    }
                coordinated-shutdown
                {
                    exit-clr = on
                }
            }"
                                                                   );

            _actorSystem = ActorSystem.Create("Pulsar", config);

            _cnxPool   = _actorSystem.ActorOf(ConnectionPool.Prop(conf), "ConnectionPool");
            _generator = _actorSystem.ActorOf(IdGeneratorActor.Prop(), "IdGenerator");
            _lookup    = _actorSystem.ActorOf(BinaryProtoLookupService.Prop(_cnxPool, _generator, conf.ServiceUrl, conf.ListenerName, conf.UseTls, conf.MaxLookupRequest, conf.OperationTimeout), "BinaryProtoLookupService");

            if (conf.EnableTransaction)
            {
                _tcClient = _actorSystem.ActorOf(TransactionCoordinatorClient.Prop(_lookup, _cnxPool, _generator, conf));
                var cos = _tcClient.Ask <AskResponse>("Start").GetAwaiter().GetResult();
                if (cos.Failed)
                {
                    throw cos.Exception;
                }

                if ((int)cos.Data <= 0)
                {
                    throw new Exception($"Tranaction Coordinator has '{cos}' transaction handler");
                }
            }
            _client = _actorSystem.ActorOf(Props.Create(() => new PulsarClientActor(conf, _cnxPool, _tcClient, _lookup, _generator)), "PulsarClient");
            _lookup.Tell(new SetClient(_client));
        }
Esempio n. 4
0
 public static PulsarSystem GetInstance(PulsarClientConfigBuilder conf, Action logSetup = null, Config config = null)
 {
     if (_instance == null)
     {
         lock (Lock)
         {
             if (_instance == null)
             {
                 _instance = new PulsarSystem(conf, logSetup, config);
             }
         }
     }
     return(_instance);
 }
Esempio n. 5
0
 public static PulsarSystem GetInstance(ActorSystem actorSystem, PulsarClientConfigBuilder conf)
 {
     if (_instance == null)
     {
         lock (Lock)
         {
             if (_instance == null)
             {
                 _instance = new PulsarSystem(actorSystem, conf);
             }
         }
     }
     return(_instance);
 }
Esempio n. 6
0
        private void SetupSystem()
        {
            var client                     = new PulsarClientConfigBuilder();
            var path                       = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var config                     = GetIConfigurationRoot(path);
            var clienConfigSetting         = config.GetSection("client");
            var serviceUrl                 = clienConfigSetting.GetSection("service-url").Value;
            var webUrl                     = clienConfigSetting.GetSection("web-url").Value;
            var authPluginClassName        = clienConfigSetting.GetSection("authPluginClassName").Value;
            var authParamsString           = clienConfigSetting.GetSection("authParamsString").Value;
            var authCertPath               = clienConfigSetting.GetSection("authCertPath").Value;
            var connectionsPerBroker       = int.Parse(clienConfigSetting.GetSection("connections-per-broker").Value);
            var statsInterval              = int.Parse(clienConfigSetting.GetSection("stats-interval").Value);
            var operationTime              = int.Parse(clienConfigSetting.GetSection("operationTime").Value);
            var allowTlsInsecureConnection = bool.Parse(clienConfigSetting.GetSection("allowTlsInsecureConnection").Value);
            var enableTls                  = bool.Parse(clienConfigSetting.GetSection("enableTls").Value);
            var enableTxn                  = bool.Parse(clienConfigSetting.GetSection("enableTransaction").Value);
            var dedicatedConnection        = bool.Parse(clienConfigSetting.GetSection("userDedicatedConnection").Value);


            client.EnableTransaction(enableTxn);
            if (operationTime > 0)
            {
                client.OperationTimeout(TimeSpan.FromMilliseconds(operationTime));
            }

            if (!string.IsNullOrWhiteSpace(authCertPath))
            {
                client.AddTrustedAuthCert(new X509Certificate2(File.ReadAllBytes(authCertPath)));
            }

            if (!string.IsNullOrWhiteSpace(authPluginClassName) && !string.IsNullOrWhiteSpace(authParamsString))
            {
                client.Authentication(authPluginClassName, authParamsString);
            }

            client.ServiceUrl(serviceUrl);
            client.WebUrl(webUrl);
            client.ConnectionsPerBroker(connectionsPerBroker);
            client.StatsInterval(statsInterval);
            client.AllowTlsInsecureConnection(allowTlsInsecureConnection);
            client.EnableTls(enableTls);
            var system = PulsarSystem.GetInstance(client);

            Client                  = system.NewClient();
            PulsarSystem            = system;
            ClientConfigurationData = client.ClientConfigurationData;
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //pulsar client settings builder
            Console.WriteLine("Please enter cmd");
            var cmd          = Console.ReadLine();
            var clientConfig = new PulsarClientConfigBuilder()
                               //.ProxyServiceUrl("pulsar+ssl://pulsar-azure-westus2.streaming.datastax.com:6551", SharpPulsar.Common.ProxyProtocol.SNI)
                               .ServiceUrl("pulsar://localhost:6650");

            //.ServiceUrl("pulsar+ssl://pulsar-azure-westus2.streaming.datastax.com:6551")
            //.Authentication(new AuthenticationToken("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjbGllbnQ7NjBlZTBjZGUtOWU3Zi00MzJmLTk3ZmEtYzA1NGFhYjgwODQwO2JXVnpkR2xqWVd3PSJ9.tIi1s_PQ6AZNxBr9rEqCoPk34mG-M6BXL8DwZpgh1Yr_nR4S5UpHG79_aYTvz902GA8PB8R7DJw6qknSdlCdXhPiDsxSPPnx4sylFz9QFCvvY6Q1JE38jVJDMMvHnm-_rggGkCPk_MFZxh1yxtamQ_QYcZQa-aq3rvFZmcJbG_jtcfmOT3TEZradN7FOiztfJDRP0YLVgnh0CJFxC36C0S4UaORllQN11i0KIgasF5dbLSidt70nwNgt6PZHDykEdhV6OC473U_4y7rM0gX7SNR3IiFMsAb7jD4CKIGG876J20aU67jXkHj08-QW2Ut38rJi5u4WxKgNTTfWOBSlQQ"));
            if (cmd.Equals("txn", StringComparison.OrdinalIgnoreCase))
            {
                clientConfig.EnableTransaction(true);
            }

            //pulsar actor system
            var pulsarSystem = PulsarSystem.GetInstance(clientConfig);

            var pulsarClient = pulsarSystem.NewClient();

            if (cmd.Equals("txn", StringComparison.OrdinalIgnoreCase))
            {
                Transaction(pulsarClient);
            }
            else if (cmd.Equals("exc", StringComparison.OrdinalIgnoreCase))
            {
                ExclusiveProduceConsumer(pulsarClient);
            }
            else if (cmd.Equals("exc2", StringComparison.OrdinalIgnoreCase))
            {
                ExclusiveProduceNoneConsumer(pulsarClient);
            }
            else if (cmd.Equals("bat", StringComparison.OrdinalIgnoreCase))
            {
                BatchProduceConsumer(pulsarClient);
            }
            else if (cmd.Equals("m", StringComparison.OrdinalIgnoreCase))
            {
                MultiConsumer(pulsarClient);
            }
            else
            {
                ProduceConsumer(pulsarClient);
            }

            Console.ReadKey();
        }
Esempio n. 8
0
        public void Start()
        {
            var clientConfig = new PulsarClientConfigBuilder()
                               .ServiceUrl(_pulsarSettings.ServiceUrl)
                               .ConnectionsPerBroker(1)
                               .UseProxy(_pulsarSettings.UseProxy)
                               .OperationTimeout(_pulsarSettings.OperationTimeout)
                               .AllowTlsInsecureConnection(false)
                               .ProxyServiceUrl(_pulsarSettings.ProxyServiceUrl, ProxyProtocol.SNI)
                               .Authentication(new AuthenticationDisabled())
                               .ClientConfigurationData;

            _pulsarSystem = PulsarSystem.GetInstance(clientConfig);
            _schema       = AvroSchema.Of(typeof(Echo.Common.Echo));
            _producer     = CreateProducer();
        }
Esempio n. 9
0
        public Worker(ILogger <Worker> logger, IHubContext <EchoHub> echo, PulsarSettings pulsarSettings)
        {
            _echo   = echo;
            _logger = logger;
            var clientConfig = new PulsarClientConfigBuilder()
                               .ServiceUrl(pulsarSettings.ServiceUrl)
                               .ConnectionsPerBroker(1)
                               .UseProxy(pulsarSettings.UseProxy)
                               .OperationTimeout(pulsarSettings.OperationTimeout)
                               .AllowTlsInsecureConnection(false)
                               .ProxyServiceUrl(pulsarSettings.ProxyServiceUrl, ProxyProtocol.SNI)
                               .Authentication(new AuthenticationDisabled())
                               .ClientConfigurationData;

            _topic        = pulsarSettings.Topic;
            _pulsarSystem = PulsarSystem.GetInstance(clientConfig);
            _schema       = AvroSchema.Of(typeof(Echo.Common.Echo));
            _consumer     = Consumer(pulsarSettings);
        }
Esempio n. 10
0
        public void Setup()
        {
            var clientConfig = new PulsarClientConfigBuilder()
                               .ServiceUrl("pulsar://localhost:6650");

            _pulsarSystem = PulsarSystem.GetInstance(clientConfig);

            _client = _pulsarSystem.NewClient();


            _consumer = _client.NewConsumer(new ConsumerConfigBuilder <byte[]>()
                                            .Topic(_benchTopic)
                                            .ForceTopicCreation(true)
                                            .SubscriptionName($"bench-sub-{Guid.NewGuid()}")
                                            .SubscriptionInitialPosition(Common.SubscriptionInitialPosition.Earliest));


            _producer = _client.NewProducer(new ProducerConfigBuilder <byte[]>()
                                            .Topic(_benchTopic));
        }