Esempio n. 1
0
        public void GetMessagePartition()
        {
            // arrange
            var publisherA = new ProducerSettings();

            new ProducerBuilder <MessageA>(publisherA)
            .PartitionProvider((m, t) => 10);

            var publisherB = new ProducerSettings();

            new ProducerBuilder <MessageB>(publisherB);

            MbSettings.Producers.Add(publisherA);
            MbSettings.Producers.Add(publisherB);

            var msgA = new MessageA();
            var msgB = new MessageB();

            // act
            var msgAPartition = KafkaMb.Value.Public_GetMessagePartition(msgA.GetType(), msgA, "topic1");
            var msgBPartition = KafkaMb.Value.Public_GetMessagePartition(msgB.GetType(), msgB, "topic1");

            // assert
            msgAPartition.Should().Be(10);
            msgBPartition.Should().Be(-1);
        }
Esempio n. 2
0
        public void GetMessageKey()
        {
            // arrange
            var producerA = new ProducerSettings();

            new ProducerBuilder <MessageA>(producerA)
            .KeyProvider((m, t) => m.Key);

            var producerB = new ProducerSettings();

            new ProducerBuilder <MessageB>(producerB);

            MbSettings.Producers.Add(producerA);
            MbSettings.Producers.Add(producerB);

            var msgA = new MessageA();
            var msgB = new MessageB();

            // act
            var msgAKey = KafkaMb.Value.Public_GetMessageKey(msgA.GetType(), msgA, "topic1");
            var msgBKey = KafkaMb.Value.Public_GetMessageKey(msgB.GetType(), msgB, "topic1");

            // assert
            msgAKey.Should().BeSameAs(msgA.Key);
            msgBKey.Should().BeNull();
        }
        public async Task PublishCorrelatingMessage()
        {
            this.logger.LogInformation($"The correlationId from scopedCache is: [{this.scopedCache.ConversationId}].");

            var msg = new MessageB();

            await this.publishEndpoint.Publish(msg, msg.GetType(), context =>
            {
                context.ConversationId = this.scopedCache.ConversationId;
            }).ConfigureAwait(false);
        }
        public async Task Consume(ConsumeContext <MessageA> context)
        {
            this.logger.LogInformation($"The correlationId from scopedCache is: [{this.scopedCache.ConversationId}].");

            var msg = new MessageB();

            await context.Publish(msg, msg.GetType(), context =>
            {
                context.ConversationId = this.scopedCache.ConversationId;
            }).ConfigureAwait(false);
        }