Stormwaker :
I'm trying to figure out Spring Kafka. While following reference I found error in this example. There is no brokerListProperty()
method in EmbeddedKafkaRule
class. How should I refactor the code to make it work?
Code from link above:
@RunWith(SpringRunner.class)
@SpringBootTest
public class MyApplicationTests {
@ClassRule
public static EmbeddedKafkaRule broker = new EmbeddedKafkaRule(1,
false, "someTopic")
.brokerListProperty("spring.kafka.bootstrap-servers");
}
@Autowired
private KafkaTemplate<String, String> template;
@Test
public void test() {
...
}
}
Artem Bilan :
Together with the @SpringBootTest
consider to use an @EmbeddedKafka
instead.
That one has a property like:
/**
* The property name to set with the bootstrap server addresses instead of the default
* {@value org.springframework.kafka.test.EmbeddedKafkaBroker#SPRING_EMBEDDED_KAFKA_BROKERS}.
* @return the property name.
* @since 2.3
* @see org.springframework.kafka.test.EmbeddedKafkaBroker#brokerListProperty(String)
*/
String bootstrapServersProperty() default "";
The goal for an EmbeddedKafkaRule
, when we don't use Spring in tests at all.
And I agree that we are missing a propagation property from that EmbeddedKafkaRule
into a brokerListProperty()
. Please, feel free to raise a GH issue and contribute a fix on the matter.
Meanwhile you can workaround it like this:
@ClassRule
public static EmbeddedKafkaRule broker = new EmbeddedKafkaRule(1, false, "someTopic");
@BeforeAll
pubic static void setup() {
broker.getEmbeddedKafka().brokerListProperty("spring.kafka.bootstrap-servers");
}
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=416568&siteId=1