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

Commit 0e875a4

Browse files
committed
* 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
1 parent 8e06a8a commit 0e875a4

File tree

5 files changed

+80
-15
lines changed

5 files changed

+80
-15
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

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
<groupId>org.springframework.boot</groupId>
3030
<artifactId>spring-boot-starter-integration</artifactId>
3131
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-data-redis</artifactId>
35+
</dependency>
3236
<dependency>
3337
<groupId>org.springframework.boot</groupId>
3438
<artifactId>spring-boot-starter-webflux</artifactId>
@@ -41,6 +45,10 @@
4145
<groupId>org.springframework.integration</groupId>
4246
<artifactId>spring-integration-jdbc</artifactId>
4347
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.integration</groupId>
50+
<artifactId>spring-integration-redis</artifactId>
51+
</dependency>
4452
<dependency>
4553
<groupId>io.micrometer</groupId>
4654
<artifactId>micrometer-core</artifactId>

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.springframework.context.ApplicationContext;
1212
import org.springframework.context.annotation.Bean;
1313
import org.springframework.core.convert.converter.Converter;
14+
import org.springframework.data.redis.connection.RedisConnectionFactory;
15+
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
1416
import org.springframework.http.HttpMethod;
1517
import org.springframework.http.MediaType;
1618
import org.springframework.integration.annotation.ServiceActivator;
@@ -27,7 +29,9 @@
2729
import org.springframework.integration.http.config.EnableIntegrationGraphController;
2830
import org.springframework.integration.jdbc.store.JdbcChannelMessageStore;
2931
import org.springframework.integration.jdbc.store.channel.H2ChannelMessageStoreQueryProvider;
32+
import org.springframework.integration.redis.store.RedisChannelMessageStore;
3033
import org.springframework.integration.scheduling.PollerMetadata;
34+
import org.springframework.integration.support.json.JacksonJsonUtils;
3135
import org.springframework.integration.webflux.dsl.WebFlux;
3236
import org.springframework.messaging.MessageHandler;
3337
import org.springframework.scheduling.support.PeriodicTrigger;
@@ -89,6 +93,14 @@ JdbcChannelMessageStore jdbcChannelMessageStore(DataSource dataSource) {
8993
return jdbcChannelMessageStore;
9094
}
9195

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+
92104
@Bean(PollerMetadata.DEFAULT_POLLER)
93105
PollerMetadata defaultPoller() {
94106
PollerMetadata pollerMetadata = new PollerMetadata();
@@ -97,14 +109,16 @@ PollerMetadata defaultPoller() {
97109
}
98110

99111
@Bean
100-
IntegrationFlow printFormattedSecondsFlow(JdbcChannelMessageStore jdbcChannelMessageStore) {
112+
IntegrationFlow printFormattedSecondsFlow(JdbcChannelMessageStore jdbcChannelMessageStore,
113+
RedisChannelMessageStore redisChannelMessageStore) {
101114
return IntegrationFlows
102115
.fromSupplier(Date::new,
103116
e -> e.id("dateSourceEndpoint")
104117
.poller(p -> p.fixedDelay(1000, 1000)))
105118
.channel(c -> c.queue("dateChannel", jdbcChannelMessageStore, "dateChannelGroup"))
106119
.gateway(subflow -> subflow.convert(Integer.class,
107120
e -> e.advice(new RequestHandlerRetryAdvice())))
121+
.channel(c -> c.queue(redisChannelMessageStore, "secondsChannelGroup"))
108122
.handle(m -> System.out.println("Current seconds: " + m.getPayload()))
109123
.get();
110124
}

spring-native-configuration/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@
480480
<artifactId>spring-integration-xml</artifactId>
481481
<scope>provided</scope>
482482
</dependency>
483+
<dependency>
484+
<groupId>org.springframework.integration</groupId>
485+
<artifactId>spring-integration-file</artifactId>
486+
<scope>provided</scope>
487+
</dependency>
483488
<dependency>
484489
<groupId>org.springframework.ws</groupId>
485490
<artifactId>spring-ws-core</artifactId>

spring-native-configuration/src/main/java/org/springframework/integration/IntegrationHints.java

+43-13
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@
1717
package org.springframework.integration;
1818

1919
import java.util.ArrayList;
20+
import java.util.HashMap;
21+
import java.util.Hashtable;
2022
import java.util.List;
23+
import java.util.Properties;
24+
import java.util.UUID;
2125

2226
import org.springframework.integration.jdbc.store.JdbcMessageStore;
2327
import org.springframework.nativex.hint.AccessBits;
2428
import org.springframework.nativex.hint.InitializationHint;
2529
import org.springframework.nativex.hint.InitializationTime;
26-
import org.springframework.nativex.hint.NativeHint;
2730
import org.springframework.nativex.hint.JdkProxyHint;
31+
import org.springframework.nativex.hint.NativeHint;
2832
import org.springframework.nativex.hint.ResourceHint;
33+
import org.springframework.nativex.hint.SerializationHint;
2934
import org.springframework.nativex.hint.TypeHint;
3035
import org.springframework.nativex.type.AccessDescriptor;
3136
import org.springframework.nativex.type.HintDeclaration;
@@ -52,17 +57,12 @@
5257
org.springframework.integration.dsl.IntegrationFlow.class,
5358
org.springframework.integration.gateway.RequestReplyExchanger.class,
5459
org.springframework.integration.graph.Graph.class,
60+
org.springframework.integration.graph.LinkNode.class,
5561
org.springframework.integration.graph.SendTimers.class,
5662
org.springframework.integration.graph.TimerStats.class,
63+
org.springframework.integration.graph.ReceiveCounters.class,
5764
org.springframework.integration.http.management.IntegrationGraphController.class,
58-
org.springframework.integration.handler.AbstractReplyProducingMessageHandler.RequestHandler.class,
59-
org.springframework.messaging.support.GenericMessage.class,
60-
org.springframework.messaging.support.ErrorMessage.class,
61-
org.springframework.integration.message.AdviceMessage.class,
62-
org.springframework.integration.support.MutableMessage.class,
63-
org.springframework.integration.store.MessageGroupMetadata.class,
64-
org.springframework.integration.store.MessageHolder.class,
65-
org.springframework.integration.store.MessageMetadata.class
65+
org.springframework.integration.handler.AbstractReplyProducingMessageHandler.RequestHandler.class
6666
}),
6767
@TypeHint(access = AccessBits.CLASS | AccessBits.PUBLIC_METHODS,
6868
types = {
@@ -74,6 +74,30 @@
7474
org.springframework.integration.core.Pausable.class
7575
})
7676
},
77+
serializables = {
78+
@SerializationHint(
79+
types = {
80+
Number.class,
81+
ArrayList.class,
82+
HashMap.class,
83+
Properties.class,
84+
Hashtable.class,
85+
Exception.class,
86+
UUID.class,
87+
org.springframework.messaging.support.GenericMessage.class,
88+
org.springframework.messaging.support.ErrorMessage.class,
89+
org.springframework.messaging.MessageHeaders.class,
90+
org.springframework.integration.message.AdviceMessage.class,
91+
org.springframework.integration.support.MutableMessage.class,
92+
org.springframework.integration.support.MutableMessageHeaders.class,
93+
org.springframework.integration.store.MessageGroupMetadata.class,
94+
org.springframework.integration.store.MessageHolder.class,
95+
org.springframework.integration.store.MessageMetadata.class,
96+
org.springframework.integration.history.MessageHistory.class,
97+
org.springframework.integration.history.MessageHistory.Entry.class,
98+
org.springframework.integration.handler.DelayHandler.DelayedMessageWrapper.class
99+
})
100+
},
77101
jdkProxies = {
78102
@JdkProxyHint(
79103
types = {
@@ -113,6 +137,12 @@
113137
kotlin.Unit.class
114138
},
115139
access = AccessBits.CLASS | AccessBits.PUBLIC_METHODS))
140+
@NativeHint(trigger = org.springframework.integration.file.splitter.FileSplitter.class,
141+
serializables =
142+
@SerializationHint(types = {
143+
org.springframework.integration.file.splitter.FileSplitter.FileMarker.class,
144+
org.springframework.integration.file.splitter.FileSplitter.FileMarker.Mark.class,
145+
}))
116146
@NativeHint(trigger = org.springframework.integration.xml.transformer.XsltPayloadTransformer.class,
117147
types =
118148
@TypeHint(types = org.springframework.web.context.support.ServletContextResource.class,
@@ -157,8 +187,8 @@ public List<HintDeclaration> computeHints(TypeSystem typeSystem) {
157187
hints.addAll(computeMessagingGatewayHints(typeSystem));
158188
hints.addAll(computeAbstractEndpointHints(typeSystem));
159189
hints.addAll(computeIntegrationNodeHints(typeSystem));
160-
// TODO Fails with 'Unable to find class file for org/springframework/web/server/WebFilter' on 'spring-aot-maven-plugin:test-generate'
161-
// hints.addAll(computeMessageHints(typeSystem));
190+
// TODO Fails with 'Unable to find class file for org/springframework/web/server/WebFilter' on 'spring-aot-maven-plugin:test-generate'
191+
// hints.addAll(computeMessageHints(typeSystem));
162192
return hints;
163193
}
164194

@@ -188,8 +218,8 @@ private static List<HintDeclaration> computeAbstractEndpointHints(TypeSystem typ
188218
.skipConstructorInspection()
189219
.filter(type -> type.extendsClass(ABSTRACT_ENDPOINT_TYPE))
190220
.onTypeDiscovered((type, context) ->
191-
context.addReflectiveAccess(type,
192-
new AccessDescriptor(AccessBits.CLASS | AccessBits.PUBLIC_METHODS)))
221+
context.addReflectiveAccess(type,
222+
new AccessDescriptor(AccessBits.CLASS | AccessBits.PUBLIC_METHODS)))
193223
.use(typeSystem)
194224
.processTypes();
195225
}

0 commit comments

Comments
 (0)