Beispiel #1
0
        /// <summary>
        /// Creates the input channel
        /// </summary>
        /// <param name="subscription">The subscription parameters with which to create the channel</param>
        /// <returns></returns>
        public IAmAChannel CreateChannel(Subscription subscription)
        {
            KafkaSubscription rmqSubscription = subscription as KafkaSubscription;

            if (rmqSubscription == null)
            {
                throw new ConfigurationException("We expect an KafkaSubscription or KafkaSubscription<T> as a parameter");
            }

            return(new Channel(
                       subscription.ChannelName,
                       _kafkaMessageConsumerFactory.Create(subscription),
                       subscription.BufferSize));
        }
Beispiel #2
0
            public void ReturnsTopicFromSource()
            {
                // Arrange
                var sourceMock = new Mock <IKafkaSubscriptionSource <long, string> >(MockBehavior.Strict);

                sourceMock.SetupGet(e => e.Topic).Returns("Some topic");

                var sut = new KafkaSubscription <long, string>(sourceMock.Object);

                // Act
                var actual = sut.Topic;

                // Assert
                Assert.That(actual, Is.EqualTo("Some topic"));
            }
Beispiel #3
0
        public static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .CreateLogger();

            var host = new HostBuilder()
                       .ConfigureServices((hostContext, services) =>
            {
                var subscriptions = new KafkaSubscription[]
                {
                    new KafkaSubscription <GreetingEvent>(
                        new SubscriptionName("paramore.example.greeting"),
                        channelName: new ChannelName("greeting.event"),
                        routingKey: new RoutingKey("greeting.event"),
                        groupId: "kafka-GreetingsReceiverConsole-Sample",
                        timeoutInMilliseconds: 100,
                        offsetDefault: AutoOffsetReset.Earliest,
                        commitBatchSize: 5)
                };

                //create the gateway
                var consumerFactory = new KafkaMessageConsumerFactory(
                    new KafkaMessagingGatewayConfiguration {
                    Name = "paramore.brighter", BootStrapServers = new[] { "localhost:9092" }
                }
                    );

                services.AddServiceActivator(options =>
                {
                    options.Subscriptions  = subscriptions;
                    options.ChannelFactory = new ChannelFactory(consumerFactory);
                }).AutoFromAssemblies();


                services.AddHostedService <ServiceActivatorHostedService>();
            })
                       .UseConsoleLifetime()
                       .UseSerilog()
                       .Build();

            await host.RunAsync();
        }