Makky
Makky

Reputation: 17463

Spring Integration Message History

I have setup @EnableMessageHistory

I have created custom transformers like this

public class FileMoveTransformer implements GenericTransformer<CustomerPojo, CustomerPojo> {
    private boolean renameFile;
    private String toLocation;
    private static final Logger LOGGER = LoggerFactory.getLogger(FileMoveTransformer.class);


    public FileMoveTransformer(String toLocation, final boolean renameFile) {
        this.toLocation = toLocation;
        this.renameFile = renameFile;
    }


    @Override
    public CustomerPojo transform(CustomerPojo input) {

    return input;

    }

}

When I look at the Message history its showing like this

enter image description here

How do I change the "name" attribute to my own transformer as above will make not sense to print.

Upvotes: 2

Views: 521

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121202

The MessageHistory makes it based on the bean name:

private static Properties extractMetadata(NamedComponent component) {
    Entry entry = new Entry();
    String name = component.getComponentName();
    String type = component.getComponentType();
    if (name != null && !name.startsWith("org.springframework.integration")) {
        entry.setName(name);
        if (type != null) {
            entry.setType(type);
        }
    }
    if (!entry.isEmpty()) {
        entry.setTimestamp(Long.toString(System.currentTimeMillis()));
    }
    return entry;
}

Since you don't provide an explicit id for the endpoint which uses your FileMoveTransformer, you get that generated bean name based on the endpoint ConsumerEndpointFactoryBean class.

Since you don't show how you use this FileMoveTransformer, I only can abuse guessing that it is about an IntegrationFlow and you have something like this:

.transform(new FileMoveTransformer())

So, consider to add an id there like:

.transform(new FileMoveTransformer(), e -> e.id("fileMoveTransformer"))

https://docs.spring.io/spring-integration/reference/html/java-dsl.html#java-dsl-endpoints

Otherwise, please, share how you use it and we will let you know what need to be changed to bring your own custom id for the component and make your message history much readable.

Upvotes: 2

Related Questions