GH-296: DSL: Support inline pub/sub subscriptions
Resolves https://github.com/spring-projects/spring-integration-kafka/issues/296 * * Add generic type to specsto avoid cast to `BroadcastCapableChannel`. * * Remove unneeded fields in the abstract spec * Restore log4j config
This commit is contained in:
committed by
Artem Bilan
parent
2331eee642
commit
aaaaf86c07
@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.kafka.channel.PollableKafkaChannel;
|
||||
import org.springframework.integration.kafka.channel.PublishSubscribeKafkaChannel;
|
||||
import org.springframework.integration.kafka.channel.SubscribableKafkaChannel;
|
||||
import org.springframework.integration.kafka.inbound.KafkaMessageSource;
|
||||
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
||||
@@ -146,7 +147,7 @@ public class ChannelTests {
|
||||
public SubscribableKafkaChannel pubSub(KafkaTemplate<Integer, String> template,
|
||||
KafkaListenerContainerFactory<?> factory) {
|
||||
|
||||
SubscribableKafkaChannel channel = new SubscribableKafkaChannel(template, factory, "channel.2", true);
|
||||
SubscribableKafkaChannel channel = new PublishSubscribeKafkaChannel(template, factory, "channel.2");
|
||||
channel.setGroupId("channel.2");
|
||||
return channel;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.MessageRejectedException;
|
||||
import org.springframework.integration.channel.BroadcastCapableChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.dsl.IntegrationFlow;
|
||||
@@ -94,7 +95,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
@DirtiesContext
|
||||
@EmbeddedKafka(topics = { KafkaDslTests.TEST_TOPIC1, KafkaDslTests.TEST_TOPIC2, KafkaDslTests.TEST_TOPIC3,
|
||||
KafkaDslTests.TEST_TOPIC4, KafkaDslTests.TEST_TOPIC5, KafkaDslTests.TEST_TOPIC6, KafkaDslTests.TEST_TOPIC7,
|
||||
KafkaDslTests.TEST_TOPIC8 })
|
||||
KafkaDslTests.TEST_TOPIC8, KafkaDslTests.TEST_TOPIC9 })
|
||||
public class KafkaDslTests {
|
||||
|
||||
static final String TEST_TOPIC1 = "test-topic1";
|
||||
@@ -113,6 +114,8 @@ public class KafkaDslTests {
|
||||
|
||||
static final String TEST_TOPIC8 = "test-topic8";
|
||||
|
||||
static final String TEST_TOPIC9 = "test-topic9";
|
||||
|
||||
@Autowired
|
||||
@Qualifier("sendToKafkaFlow.input")
|
||||
private MessageChannel sendToKafkaFlowInput;
|
||||
@@ -156,7 +159,7 @@ public class KafkaDslTests {
|
||||
private Gate gate;
|
||||
|
||||
@Test
|
||||
public void testKafkaAdapters() throws Exception {
|
||||
void testKafkaAdapters() throws Exception {
|
||||
this.sendToKafkaFlowInput.send(new GenericMessage<>("foo", Collections.singletonMap("foo", "bar")));
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(this.kafkaProducer1, "headerMapper")).isSameAs(this.mapper);
|
||||
@@ -217,20 +220,25 @@ public class KafkaDslTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGateways() throws Exception {
|
||||
void testGateways() throws Exception {
|
||||
assertThat(this.config.replyContainerLatch.await(30, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(this.gate.exchange(TEST_TOPIC4, "foo")).isEqualTo("FOO");
|
||||
}
|
||||
|
||||
@Test
|
||||
void channels(@Autowired MessageChannel topic6Channel, @Autowired PollableKafkaChannel topic8Channel) {
|
||||
void channels(@Autowired MessageChannel topic6Channel, @Autowired PollableKafkaChannel topic8Channel,
|
||||
@Autowired PollableKafkaChannel topic9Channel) {
|
||||
topic6Channel.send(new GenericMessage<>("foo"));
|
||||
Message<?> received = topic8Channel.receive();
|
||||
assertThat(received)
|
||||
.isNotNull()
|
||||
.extracting("payload")
|
||||
.isEqualTo("foo");
|
||||
}
|
||||
received = topic9Channel.receive();
|
||||
assertThat(received)
|
||||
.isNotNull()
|
||||
.extracting("payload")
|
||||
.isEqualTo("foo"); }
|
||||
|
||||
@Configuration
|
||||
@EnableIntegration
|
||||
@@ -379,8 +387,9 @@ public class KafkaDslTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KafkaSubscribableChannelSpec topic6Channel(KafkaTemplate<Integer, String> template,
|
||||
public KafkaPointToPointChannelSpec topic6Channel(KafkaTemplate<Integer, String> template,
|
||||
ConcurrentKafkaListenerContainerFactory<Integer, String> containerFactory) {
|
||||
|
||||
return Kafka.channel(template, containerFactory, TEST_TOPIC6);
|
||||
}
|
||||
|
||||
@@ -400,8 +409,19 @@ public class KafkaDslTests {
|
||||
KafkaMessageSource<?, ?> channelSource) {
|
||||
|
||||
return IntegrationFlows.from(topic6Channel(template, containerFactory))
|
||||
.channel(Kafka.publishSubscribeChannel(template, containerFactory, TEST_TOPIC7))
|
||||
.channel(Kafka.pollableChannel(template, channelSource).id("topic8Channel"))
|
||||
.publishSubscribeChannel(pubSub(template, containerFactory), channel -> channel
|
||||
.subscribe(f -> f.channel(
|
||||
Kafka.pollableChannel(template, channelSource).id("topic8Channel")))
|
||||
.subscribe(f -> f.channel(
|
||||
Kafka.pollableChannel(template, channelSource).id("topic9Channel"))))
|
||||
.get();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BroadcastCapableChannel pubSub(KafkaTemplate<Integer, String> template,
|
||||
ConcurrentKafkaListenerContainerFactory<Integer, String> containerFactory) {
|
||||
|
||||
return Kafka.publishSubscribeChannel(template, containerFactory, TEST_TOPIC7)
|
||||
.get();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user