Skip to content

Support DelayedMessageWrapper Deserialized #9561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Stream;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.aopalliance.aop.Advice;

import org.springframework.aop.framework.ProxyFactory;
Expand Down Expand Up @@ -97,6 +99,7 @@
* @author Artem Bilan
* @author Gary Russell
* @author Christian Tzolov
* @author Youbin Wu
*
* @since 1.0.3
*/
Expand Down Expand Up @@ -689,7 +692,9 @@ public static final class DelayedMessageWrapper implements Serializable {
@SuppressWarnings("serial")
private final Message<?> original;

DelayedMessageWrapper(Message<?> original, long requestDate) {
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
DelayedMessageWrapper(@JsonProperty("original") Message<?> original,
@JsonProperty("requestDate") long requestDate) {
this.original = original;
this.requestDate = requestDate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,6 +46,7 @@
*
* @author Artem Bilan
* @author Gary Russell
* @author Youbin Wu
*
* @since 3.0
*
Expand All @@ -63,7 +64,8 @@ public final class JacksonJsonUtils {
"org.springframework.integration.support",
"org.springframework.integration.message",
"org.springframework.integration.store",
"org.springframework.integration.history"
"org.springframework.integration.history",
"org.springframework.integration.handler"
);

private JacksonJsonUtils() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import org.springframework.beans.BeanUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.NullChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.handler.DelayHandler;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.message.AdviceMessage;
import org.springframework.integration.redis.RedisContainerTest;
Expand All @@ -64,6 +66,7 @@
* @author Artem Bilan
* @author Gary Russell
* @author Artem Vozhdayenko
* @author Youbin Wu
*/
class RedisMessageGroupStoreTests implements RedisContainerTest {

Expand Down Expand Up @@ -400,11 +403,13 @@ void testJsonSerialization() {
Message<?> mutableMessage = new MutableMessage<>(UUID.randomUUID());
Message<?> adviceMessage = new AdviceMessage<>("foo", genericMessage);
ErrorMessage errorMessage = new ErrorMessage(new RuntimeException("test exception"), mutableMessage);
var delayedMessageWrapperConstructor = BeanUtils.getResolvableConstructor(DelayHandler.DelayedMessageWrapper.class);
Message<?> delayMessage = new GenericMessage<>(BeanUtils.instantiateClass(delayedMessageWrapperConstructor, genericMessage, System.currentTimeMillis()));

store.addMessagesToGroup(this.groupId, genericMessage, mutableMessage, adviceMessage, errorMessage);
store.addMessagesToGroup(this.groupId, genericMessage, mutableMessage, adviceMessage, errorMessage, delayMessage);

MessageGroup messageGroup = store.getMessageGroup(this.groupId);
assertThat(messageGroup.size()).isEqualTo(4);
assertThat(messageGroup.size()).isEqualTo(5);
List<Message<?>> messages = new ArrayList<>(messageGroup.getMessages());
assertThat(messages.get(0)).isEqualTo(genericMessage);
assertThat(messages.get(0).getHeaders()).containsKeys(MessageHistory.HEADER_NAME);
Expand All @@ -417,6 +422,7 @@ void testJsonSerialization() {
.isEqualTo(errorMessage.getOriginalMessage());
assertThat(((ErrorMessage) errorMessageResult).getPayload().getMessage())
.isEqualTo(errorMessage.getPayload().getMessage());
assertThat(messages.get(4)).isEqualTo(delayMessage);

Message<Foo> fooMessage = new GenericMessage<>(new Foo("foo"));
try {
Expand Down