Skip to content
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

spring-modulith: spring.modulith.republish-outstanding-events-on-restart=true unable #526

Open
PetricHwang opened this issue Mar 15, 2024 · 4 comments
Assignees
Labels
in: event publication registry Event publication registry meta: waiting for feedback Waiting for feedback of the original reporter

Comments

@PetricHwang
Copy link

PetricHwang commented Mar 15, 2024

I set spring.modulith.republish-outstanding-events-on-restart=true, @ApplicationModuleListener sleep 30s, and I restart springboot, but it is unable republish.

  • publisher
ApplicationEventPublisher applicationEventPublisher;
...
List<AdminCreateEvent> events=...;
applicationEventPublisher.publishEvent(new ListenerEvent<>(this, events));

  • listener
@ApplicationModuleListener
public void listener(ListenerEvent<List<AdminCreateEvent>> event)  {
    log.debug("listener: {}", event);
    Thread.sleep(30_000)
}
  • ListenerEvent
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

@Getter
public class ListenerEvent<T> extends ApplicationEvent {

    private final transient T data;

    public ListenerEvent(Object source, T data) {
        super(source);
        this.data = data;
    }
}
  • mysql record:
ID LISTENER_ID EVENT_TYPE SERIALIZED_EVENT PUBLICATION_DATE COMPLETION_DATE
6a969ce-5aa8-43ce-bcce-5da833fbe981 com.admin.event.AdminEventListener.listener(com.admin.event.ListenerEvent) com.admin.event.ListenerEvent {"timestamp":1710505254886,"data":[{"eventId":"c883e482-013a-4237-bdec-d6c1f0d7f403"}],"source":{}} 2024-03-15 20:20:54.887171
@odrotbohm
Copy link
Member

It's not clear what “unable to republish” means. Would you mind creating a minimal reproducer to show what's going wrong?

@odrotbohm odrotbohm self-assigned this Mar 17, 2024
@odrotbohm odrotbohm added in: event publication registry Event publication registry meta: waiting for feedback Waiting for feedback of the original reporter labels Mar 17, 2024
@PetricHwang
Copy link
Author

PetricHwang commented Mar 19, 2024

It's not clear what “unable to republish” means. Would you mind creating a minimal reproducer to show what's going wrong?

Unconsumed records(ID:6a969ce-5aa8-43ce-bcce-5da833fbe981) cannot be consumed after springboot restarts.

@ApplicationModuleListener
public void listener(ListenerEvent<List<AdminCreateEvent>> event)  {
    log.debug("listener: {}", event);
   // Thread.sleep(30_000)
}

@odrotbohm
Copy link
Member

By default, Jackson is used to serialize the event objects to String so that they can be persisted into the database. Given you have generics and a complex type arrangement involved here, I assume that Jackson does not properly serialize that into the database so that it cannot reconstitute the object instance later.

Please either make sure that Jackson can fully serialize and deserialize all event instances properly, or replace the default EventSerializer with one that uses a different format, not losing the type information.

@matiwinnetou
Copy link

I think this is quite common. I also encountered these problems and it forced me to use simple types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: event publication registry Event publication registry meta: waiting for feedback Waiting for feedback of the original reporter
Projects
None yet
Development

No branches or pull requests

3 participants