Пример #1
0
        public IConsumer Create(string topic, ConsumerConfig configuration)
        {
            if (string.IsNullOrWhiteSpace(topic))
            {
                throw new ArgumentNullException(nameof(topic), "Topic must be not null or empty");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var connectionConfiguration = new NatsStreamingConnectionConfigurationBuilder()
                                          .WithClusterId(configuration.ClusterId)
                                          .WithNatsUrl(configuration.Urls)
                                          .Build();

            var factory = new NatsStreamingConsumerFactory(connectionConfiguration);

            return(new NatsConsumer(topic, configuration.Environment, factory));
        }
Пример #2
0
        public async Task Test2()
        {
            var port    = 4222;
            var subPort = 8222;

            using var container = Containers.CreateNatsStreamingContainer(port, subPort);

            container.Start();

            await Task.Delay(1000); //StartingNats

            var connectionConfiguration = new NatsStreamingConnectionConfigurationBuilder()
                                          .WithClusterId("test-cluster")
                                          .WithNatsUrl($"http://localhost:{port}/")
                                          .Build();

            var factory = new NatsStreamingConsumerFactory(connectionConfiguration);

            var natsConsumer = new NatsConsumer("test", "test", factory);

            Action act = () => natsConsumer.Connect();

            act.Should().NotThrow();
        }