0

As described in the docs, I am associating my Saga object with a specific event property. The SagaLifecycle.associateWith method is called from within the starting saga event handler method:

@StartSaga
@SagaEventHandler(associationProperty = "orderId")
public void handle(OrderCreatedEvent event) {
    // ...
    SagaLifecycle.associateWith("shipmentId", shipmentId); //fails
    // ...
}

The call however fails because no scope is active. I don't see any instructions in the docs that would tell me to activate a scope. Any leads?

java.lang.IllegalStateException: Cannot request current Scope if none is active
    at org.axonframework.messaging.Scope.getCurrentScope(Scope.java:57) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.modelling.saga.SagaLifecycle.getInstance(SagaLifecycle.java:118) ~[axon-modelling-4.0.jar:4.0]
    at org.axonframework.modelling.saga.SagaLifecycle.associateWith(SagaLifecycle.java:57) ~[axon-modelling-4.0.jar:4.0]
    at org.axonframework.modelling.saga.SagaLifecycle.associateWith(SagaLifecycle.java:35) ~[axon-modelling-4.0.jar:4.0]
    at com.example.sagas.OrderSaga.handle(OrderSaga.java:56) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
    at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMember.handle(AnnotatedMessageHandlingMember.java:127) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.modelling.saga.SagaMethodMessageHandlingMember.handle(SagaMethodMessageHandlingMember.java:80) ~[axon-modelling-4.0.jar:4.0]
    at org.axonframework.eventhandling.AnnotationEventHandlerAdapter.handle(AnnotationEventHandlerAdapter.java:81) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.SimpleEventHandlerInvoker.handle(SimpleEventHandlerInvoker.java:111) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.MultiEventHandlerInvoker.handle(MultiEventHandlerInvoker.java:79) [axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.AbstractEventProcessor.lambda$null$1(AbstractEventProcessor.java:141) [axon-messaging-4.0.jar:4.0]
    at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:57) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.messaging.interceptors.CorrelationDataInterceptor.handle(CorrelationDataInterceptor.java:65) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:55) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.TrackingEventProcessor.lambda$new$1(TrackingEventProcessor.java:132) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:55) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.AbstractEventProcessor.lambda$processInUnitOfWork$2(AbstractEventProcessor.java:148) [axon-messaging-4.0.jar:4.0]
    at org.axonframework.messaging.unitofwork.BatchingUnitOfWork.executeWithResult(BatchingUnitOfWork.java:86) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.AbstractEventProcessor.processInUnitOfWork(AbstractEventProcessor.java:136) [axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.TrackingEventProcessor.processBatch(TrackingEventProcessor.java:258) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.TrackingEventProcessor.processingLoop(TrackingEventProcessor.java:181) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:661) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:771) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.eventhandling.TrackingEventProcessor$CountingRunnable.run(TrackingEventProcessor.java:588) ~[axon-messaging-4.0.jar:4.0]
    at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_191]
Double M
  • 1,449
  • 1
  • 12
  • 29

1 Answers1

4

The Saga needs to be annotated with @Saga in Spring.

Double M
  • 1,449
  • 1
  • 12
  • 29
  • That is completely correct @Double M. Might ne nice to be more specific in this response that this is the answer to your solution, maybe even mark it as so if you're happy with it. – Steven Dec 04 '18 at 08:56
  • 1
    @Steven I will, but it won't let me until a few more hours have passed ;) Could you add a note to the docs? I spent quite a while looking for this solution. – Double M Dec 04 '18 at 17:54
  • Definitely will @Double M, we are making plans to rigorously update the Reference Guide to overcome the problems you're encountering right now...I am very sorry you hti them though :-( – Steven Dec 05 '18 at 08:29
  • @Steven Not a problem, as long as it works at the end of the day. Would you like me to report any findings regarding the docs to you via email or similar? – Double M Dec 06 '18 at 14:10
  • Any suggestions would definitely be much appreciated @Double M! Feel free to contact me. I believe you're also on the Axon Framework User Group from time to time, right? You should be able to trace my email address from there I think. – Steven Dec 14 '18 at 07:55