Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit bdb85a0

Browse files
artembilansdeleuze
authored andcommitted
Add more Spring Integration native hints
* The `IntegrationFlow` interface can be proxied at runtime * The resource pattern for JDBC schemas should really be a regex pattern * The HTTP and WebFlux request mappings need a reflection access to method of their handlers to map * Process interfaces with a `@MessagingGateway` and register their proxy hints * Improve `IntegrationApplication` in the sample to cover the mentioned above cases about an `IntegrationFlow` proxy and `@MessagingGateway` * Fix `ControlBusGateway` to emit really a Control Bus command * Use `WebClient.Builder` bean from the ctx for application logic * Add reflection info for `AbstractEndpoint` to satisfy Control Bus requirements * Add some common types to satisfy common SpEL expressions * Add explicit `@TypeHint` for `Message` impls - * Add more Spring Integration types specific to `MessageStore` serialization functionality * Add programmatic scan for `IntegrationNode` impls instead of huge number of explicit types in `@TypeHint` * Add `JdbcChannelMessageStore` logic into the sample to cover its serialization functionality * Add `@SerializationHint` for messaging types * Add programmatic scan for `IntegrationNode` impls instead of huge number of explicit types in `@TypeHint` * Add `JdbcChannelMessageStore` logic into the sample to cover its serialization functionality * Add `RedisChannelMessageStore` logic into the sample to cover JSON (un)marshaling feature * Rely on Spring Integration version from parent in the sample Closes gh-894
1 parent 5a9bac0 commit bdb85a0

File tree

6 files changed

+273
-39
lines changed

6 files changed

+273
-39
lines changed
+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
version: '3.1'
22
services:
3+
redis:
4+
image: 'redis:latest'
5+
ports:
6+
- '6379:6379'
37
integration:
48
image: integration:0.0.1-SNAPSHOT
59
ports:
6-
- "8080:8080"
10+
- '8080:8080'
11+
depends_on:
12+
- redis
13+
environment:
14+
- SPRING_REDIS_HOST=redis

samples/integration/pom.xml

+18-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
<properties>
1919
<java.version>11</java.version>
20-
<spring-integration.version>5.5.0-SNAPSHOT</spring-integration.version>
2120
</properties>
2221

2322
<dependencies>
@@ -29,18 +28,35 @@
2928
<groupId>org.springframework.boot</groupId>
3029
<artifactId>spring-boot-starter-integration</artifactId>
3130
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-data-redis</artifactId>
34+
</dependency>
3235
<dependency>
3336
<groupId>org.springframework.boot</groupId>
3437
<artifactId>spring-boot-starter-webflux</artifactId>
3538
</dependency>
3639
<dependency>
3740
<groupId>org.springframework.integration</groupId>
38-
<artifactId>spring-integration-http</artifactId>
41+
<artifactId>spring-integration-webflux</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.integration</groupId>
45+
<artifactId>spring-integration-jdbc</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.integration</groupId>
49+
<artifactId>spring-integration-redis</artifactId>
3950
</dependency>
4051
<dependency>
4152
<groupId>io.micrometer</groupId>
4253
<artifactId>micrometer-core</artifactId>
4354
</dependency>
55+
<dependency>
56+
<groupId>com.h2database</groupId>
57+
<artifactId>h2</artifactId>
58+
<scope>runtime</scope>
59+
</dependency>
4460
</dependencies>
4561

4662
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.integration;
2+
3+
import org.springframework.integration.annotation.Gateway;
4+
import org.springframework.integration.annotation.MessagingGateway;
5+
6+
@MessagingGateway(defaultRequestChannel = "controlBus.input")
7+
public interface ControlBusGateway {
8+
9+
@Gateway(payloadExpression = "'@' + args[0] + '.start()'")
10+
void startEndpoint(String id);
11+
12+
}

samples/integration/src/main/java/com/example/integration/IntegrationApplication.java

+76-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
import java.util.Calendar;
55
import java.util.Date;
66

7+
import javax.sql.DataSource;
8+
79
import org.springframework.boot.SpringApplication;
810
import org.springframework.boot.autoconfigure.SpringBootApplication;
9-
import org.springframework.context.ConfigurableApplicationContext;
11+
import org.springframework.context.ApplicationContext;
1012
import org.springframework.context.annotation.Bean;
1113
import org.springframework.core.convert.converter.Converter;
14+
import org.springframework.data.redis.connection.RedisConnectionFactory;
15+
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
16+
import org.springframework.http.HttpMethod;
1217
import org.springframework.http.MediaType;
1318
import org.springframework.integration.annotation.ServiceActivator;
1419
import org.springframework.integration.channel.interceptor.WireTap;
@@ -17,12 +22,19 @@
1722
import org.springframework.integration.config.GlobalChannelInterceptor;
1823
import org.springframework.integration.config.IntegrationConverter;
1924
import org.springframework.integration.dsl.IntegrationFlow;
25+
import org.springframework.integration.dsl.IntegrationFlowDefinition;
2026
import org.springframework.integration.dsl.IntegrationFlows;
21-
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
2227
import org.springframework.integration.handler.LoggingHandler;
2328
import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice;
2429
import org.springframework.integration.http.config.EnableIntegrationGraphController;
30+
import org.springframework.integration.jdbc.store.JdbcChannelMessageStore;
31+
import org.springframework.integration.jdbc.store.channel.H2ChannelMessageStoreQueryProvider;
32+
import org.springframework.integration.redis.store.RedisChannelMessageStore;
33+
import org.springframework.integration.scheduling.PollerMetadata;
34+
import org.springframework.integration.support.json.JacksonJsonUtils;
35+
import org.springframework.integration.webflux.dsl.WebFlux;
2536
import org.springframework.messaging.MessageHandler;
37+
import org.springframework.scheduling.support.PeriodicTrigger;
2638
import org.springframework.web.reactive.function.client.WebClient;
2739

2840
import io.micrometer.core.instrument.MeterRegistry;
@@ -35,15 +47,32 @@
3547
public class IntegrationApplication {
3648

3749
public static void main(String[] args) throws InterruptedException {
38-
ConfigurableApplicationContext applicationContext = SpringApplication.run(IntegrationApplication.class, args);
39-
applicationContext.getBean("dateSourceEndpoint", SourcePollingChannelAdapter.class).start();
50+
ApplicationContext context = SpringApplication.run(IntegrationApplication.class, args);
51+
52+
WebClient webClient =
53+
context.getBean(WebClient.Builder.class)
54+
.baseUrl("http://localhost:8080")
55+
.build();
56+
57+
Thread.sleep(1000);
58+
59+
System.out.println("Starting 'dateSourceEndpoint'...");
60+
61+
webClient
62+
.get()
63+
.uri("control-bus/dateSourceEndpoint")
64+
.retrieve()
65+
.toBodilessEntity()
66+
.block(Duration.ofSeconds(10));
4067

4168
Thread.sleep(1000);
4269

70+
System.out.println("Obtaining integration graph...");
71+
4372
String integrationGraph =
44-
WebClient.create()
73+
webClient
4574
.get()
46-
.uri("http://localhost:8080/integration-graph")
75+
.uri("integration-graph")
4776
.accept(MediaType.APPLICATION_JSON)
4877
.retrieve()
4978
.bodyToMono(String.class)
@@ -58,14 +87,38 @@ MeterRegistry simpleMeterRegistry() {
5887
}
5988

6089
@Bean
61-
IntegrationFlow printFormattedSecondsFlow() {
90+
JdbcChannelMessageStore jdbcChannelMessageStore(DataSource dataSource) {
91+
JdbcChannelMessageStore jdbcChannelMessageStore = new JdbcChannelMessageStore(dataSource);
92+
jdbcChannelMessageStore.setChannelMessageStoreQueryProvider(new H2ChannelMessageStoreQueryProvider());
93+
return jdbcChannelMessageStore;
94+
}
95+
96+
@Bean
97+
RedisChannelMessageStore redisChannelMessageStore(RedisConnectionFactory connectionFactory) {
98+
RedisChannelMessageStore redisChannelMessageStore = new RedisChannelMessageStore(connectionFactory);
99+
redisChannelMessageStore.setValueSerializer(
100+
new GenericJackson2JsonRedisSerializer(JacksonJsonUtils.messagingAwareMapper()));
101+
return redisChannelMessageStore;
102+
}
103+
104+
@Bean(PollerMetadata.DEFAULT_POLLER)
105+
PollerMetadata defaultPoller() {
106+
PollerMetadata pollerMetadata = new PollerMetadata();
107+
pollerMetadata.setTrigger(new PeriodicTrigger(10));
108+
return pollerMetadata;
109+
}
110+
111+
@Bean
112+
IntegrationFlow printFormattedSecondsFlow(JdbcChannelMessageStore jdbcChannelMessageStore,
113+
RedisChannelMessageStore redisChannelMessageStore) {
62114
return IntegrationFlows
63115
.fromSupplier(Date::new,
64116
e -> e.id("dateSourceEndpoint")
65117
.poller(p -> p.fixedDelay(1000, 1000)))
66-
.channel("dateChannel")
118+
.channel(c -> c.queue("dateChannel", jdbcChannelMessageStore, "dateChannelGroup"))
67119
.gateway(subflow -> subflow.convert(Integer.class,
68120
e -> e.advice(new RequestHandlerRetryAdvice())))
121+
.channel(c -> c.queue(redisChannelMessageStore, "secondsChannelGroup"))
69122
.handle(m -> System.out.println("Current seconds: " + m.getPayload()))
70123
.get();
71124
}
@@ -99,4 +152,19 @@ public Integer convert(Date date) {
99152
};
100153
}
101154

155+
@Bean
156+
public IntegrationFlow controlBus() {
157+
return IntegrationFlowDefinition::controlBus;
158+
}
159+
160+
@Bean
161+
public IntegrationFlow controlBusControllerFlow(ControlBusGateway controlBusGateway) {
162+
return IntegrationFlows
163+
.from(WebFlux.inboundChannelAdapter("/control-bus/{endpointId}")
164+
.payloadExpression("#pathVariables.endpointId")
165+
.requestMapping(mapping -> mapping.methods(HttpMethod.GET)))
166+
.handle(controlBusGateway, "startEndpoint")
167+
.get();
168+
}
169+
102170
}

spring-native-configuration/pom.xml

+10
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@
470470
<artifactId>spring-integration-http</artifactId>
471471
<scope>provided</scope>
472472
</dependency>
473+
<dependency>
474+
<groupId>org.springframework.integration</groupId>
475+
<artifactId>spring-integration-webflux</artifactId>
476+
<scope>provided</scope>
477+
</dependency>
473478
<dependency>
474479
<groupId>org.springframework.integration</groupId>
475480
<artifactId>spring-integration-websocket</artifactId>
@@ -480,6 +485,11 @@
480485
<artifactId>spring-integration-xml</artifactId>
481486
<scope>provided</scope>
482487
</dependency>
488+
<dependency>
489+
<groupId>org.springframework.integration</groupId>
490+
<artifactId>spring-integration-file</artifactId>
491+
<scope>provided</scope>
492+
</dependency>
483493
<dependency>
484494
<groupId>org.springframework.ws</groupId>
485495
<artifactId>spring-ws-core</artifactId>

0 commit comments

Comments
 (0)