I know you can view the association_value_entry table in the DB but this only allows you to see it for a point in time.
What is the best way we can retrieve a Saga’s associations programmatically from within a @SagaEventHandler?
Reasons for wanting to do this:
make debugging easier during Saga development
log a DEBUG or TRACE message with these values.
We have SagaLifecycle.associateWith(...), is it worth having a SagaLifecycle.associatedWith() which returns the association values (maybe a List<AssociationValue>)?
The associated values currently not easily retrievable. We have a Github issue on this, and this might be picked up. in a following release.
For now, the best way to do this is using a Handler Enhancer to access the Saga instance and put the values in the resources of the unit of work. This way you can access them later.
For example, you could do this:
public class AssociationPropertyHandlerEnhancer<T> extends WrappedMessageHandlingMember<T> {
protected AssociationPropertyHandlerEnhancer(MessageHandlingMember<T> delegate) {
super(delegate);
}
@Override
public Object handle(Message<?> message, T target) throws Exception {
if (target instanceof Saga<?>) {
CurrentUnitOfWork.get().resources().put("associations", ((Saga<?>) target).getAssociationValues());
}
return super.handle(message, target);
}
}
Now in your handlers you can access the association values: