Esempio n. 1
0
        public void TestTlsCertsFromDynamicStreamExpiredAndRenewCert()
        {
            AtomicInteger       certIndex    = new AtomicInteger(1);
            AtomicInteger       keyIndex     = new AtomicInteger(0);
            MemoryStream        certStream   = CreateByteInputStream(TlsClientCertFilePath);
            MemoryStream        keyStream    = CreateByteInputStream(TlsClientKeyFilePath);
            Func <MemoryStream> certProvider = () => GetStream(certIndex, certStream, keyStream);
            Func <MemoryStream> keyProvider  = () => GetStream(keyIndex, keyStream);
            AuthenticationTls   auth         = new AuthenticationTls(certProvider, keyProvider);

            _common.GetPulsarSystem(auth, 1000, enableTls: true, brokerService: "pulsar.BrokerServiceUrlTls");


            _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", "TestTlsCertsFromDynamicStreamExpiredAndRenewCert", "my-subscriber-name"));


            certIndex.SetValue(0);
            _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", "TestTlsCertsFromDynamicStreamExpiredAndRenewCert", "my-subscriber-name"));
        }
Esempio n. 2
0
        public void TestTlsCertsFromDynamicStream()
        {
            string topicName = "persistent://my-property/use/my-ns/my-topic1";

            AtomicInteger index = new AtomicInteger(0);

            MemoryStream certStream = CreateByteInputStream(TlsClientCertFilePath);
            MemoryStream keyStream  = CreateByteInputStream(TlsClientKeyFilePath);

            Func <MemoryStream> certProvider = () => GetStream(index, certStream);
            Func <MemoryStream> keyProvider  = () => GetStream(index, keyStream);
            AuthenticationTls   auth         = new AuthenticationTls(certProvider, keyProvider);

            _common.GetPulsarSystem(auth, 1000, enableTls: true, brokerService: "pulsar.BrokerServiceUrlTls");


            _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), topicName, "TestTlsCertsFromDynamicStream", "my-subscriber-name"));

            // unload the topic so, new connection will be made and read the cert streams again

            var producer = _common.PulsarSystem.PulsarProducer(_common.CreateProducer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", ""));

            for (int i = 0; i < 10; i++)
            {
                var send = new Send(("test" + i).GetBytes(), ImmutableDictionary <string, object> .Empty);
                _common.PulsarSystem.Send(send, producer.Producer);
            }

            ConsumedMessage msg = null;

            for (var i = 0; i < 10; i++)
            {
                msg = _common.PulsarSystem.Receive("TestTlsCertsFromDynamicStream", 5000);
                var exepctedMsg = "test" + i;
                var data        = (byte[])(object)msg.Message.Data;
                Assert.Equal(exepctedMsg.GetBytes(), data);
            }
            // Acknowledge the consumption of all messages at once
            _common.PulsarSystem.AcknowledgeCumulative(msg);
        }