Example #1
0
 public EventSourceTests(ITestOutputHelper output, PulsarStandaloneClusterFixture fixture)
 {
     _output                  = output;
     _client                  = fixture.Client;
     _pulsarSystem            = fixture.PulsarSystem;
     _clientConfigurationData = fixture.ClientConfigurationData;
 }
Example #2
0
        public void Setup()
        {
            var clientConfig = new PulsarClientConfigBuilder()
                               .ServiceUrl("pulsar://localhost:6650");

            _pulsarSystem = PulsarSystem.GetInstance(clientConfig);

            _client = _pulsarSystem.NewClient();
        }
Example #3
0
        public virtual void TestQuerySql()
        {
            var topic = $"query_topics_avro_{Guid.NewGuid()}";

            PublishMessages(topic, 5);
            var option = new ClientOptions {
                Server = "http://127.0.0.1:8081", Execute = @$ "select * from " "{topic}" "", Catalog = "pulsar", Schema = "public/default"
            };

            var sql = PulsarSystem.Sql(option);

            var receivedCount = 0;

            Thread.Sleep(TimeSpan.FromSeconds(10));
            var response = sql.Execute(TimeSpan.FromSeconds(30));

            if (response != null)
            {
                var data = response.Response;
                switch (data)
                {
                case DataResponse dr:
                {
                    for (var i = 0; i < dr.Data.Count; i++)
                    {
                        var ob = dr.Data.ElementAt(i)["text"].ToString();
                        _output.WriteLine(ob);
                        receivedCount++;
                    }
                    _output.WriteLine(JsonSerializer.Serialize(dr.StatementStats, new JsonSerializerOptions {
                            WriteIndented = true
                        }));
                }
                break;

                case StatsResponse sr:
                    _output.WriteLine(JsonSerializer.Serialize(sr.Stats, new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                    break;

                case ErrorResponse er:
                    _output.WriteLine(JsonSerializer.Serialize(er, new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                    break;
                }
            }

            Assert.True(receivedCount > 1);
        }
Example #4
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;
        }
Example #5
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();
        }
        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();
        }
Example #7
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);
        }
Example #8
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));
        }