Example #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);
        }
Example #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();
        }