示例#1
0
        public Task <JobResult> RunAsync(Int32 count)
        {
            var connection = Broker.Connect();
            var tasks      = new Task[count];

            _stopwatch.Start();

            for (var i = 0; i < count; i++)
            {
                tasks[i] = connection.PublishAsync(BuildMessage(i), _exchange, _routingKey);
            }

            return(Task.WhenAll(tasks)
                   .ContinueWith(_ =>
            {
                _stopwatch.Stop();

                for (var i = 0; i < count; i++)
                {
                    tasks[i] = null;
                }

                tasks = null;

                var elapsed = _stopwatch.Elapsed;
                _stopwatch.Reset();
                connection.Dispose();
                return JobResult.New(elapsed, this, count);
            }));
        }
示例#2
0
        public RequestConsumer(String endpointUrl)
        {
            _broker = Broker.New(_ =>
            {
                _.Endpoint(new Uri(endpointUrl, UriKind.Absolute));
                _.ResolveMessageTypeBy(_resolver);
            });

            _connection = _broker.Connect();
        }
示例#3
0
        private static void Connect()
        {
            _producer = _broker.GetProducer(new KafkaProducerEndpoint("Topic1")
            {
                Configuration = new KafkaProducerConfig
                {
                    BootstrapServers = "PLAINTEXT://localhost:9092"
                }
            });

            _broker.Connect();

            Console.CancelKeyPress += (_, e) => { _broker.Disconnect(); };
        }
示例#4
0
        public MoveMessageErrorPolicyTests()
        {
            var services = new ServiceCollection();

            services.AddSingleton <ILoggerFactory, NullLoggerFactory>();
            services.AddSingleton(typeof(ILogger <>), typeof(NullLogger <>));

            services.AddSilverback().WithConnectionTo <TestBroker>(options => { });

            var serviceProvider = services.BuildServiceProvider(new ServiceProviderOptions {
                ValidateScopes = true
            });

            _errorPolicyBuilder = new ErrorPolicyBuilder(serviceProvider, NullLoggerFactory.Instance);

            _broker = serviceProvider.GetRequiredService <IBroker>();
            _broker.Connect();
        }
示例#5
0
        private static void Connect()
        {
            var messageKeyProvider = new MessageKeyProvider(new[] { new DefaultPropertiesMessageKeyProvider() });

            _broker = new KafkaBroker(messageKeyProvider, GetLoggerFactory(), new MessageLogger(messageKeyProvider));

            _consumer = _broker.GetConsumer(new KafkaConsumerEndpoint("Topic1")
            {
                Configuration = new KafkaConsumerConfig
                {
                    BootstrapServers = "PLAINTEXT://kafka:9092",
                    GroupId          = "silverback-consumer",
                    AutoOffsetReset  = Confluent.Kafka.AutoOffsetReset.Earliest
                }
            });

            _consumer.Received += OnMessageReceived;

            _broker.Connect();
        }
示例#6
0
        private static void Connect()
        {
            _consumer = _broker.GetConsumer(new KafkaConsumerEndpoint("Topic1")
            {
                Configuration = new KafkaConsumerConfig
                {
                    BootstrapServers = "PLAINTEXT://localhost:9092",
                    GroupId          = "silverback-consumer",
                    AutoOffsetReset  = Confluent.Kafka.AutoOffsetReset.Earliest
                },
                Serializer = new JsonMessageSerializer <TestMessage>()
            });

            _consumer.Received += OnMessageReceived;

            _broker.Connect();

            Console.CancelKeyPress += (_, e) =>
            {
                _broker.Disconnect();
                _activity.Stop();
            };
        }