I’m facing issues related to Saga configuration with clustered-event bus (with amqp-rabbit).
Issue 1:
Any SagaEventHandler configured after the first type (in this case com.test.EventHandler1) is not consuming the events.They are remaining in the rabbit-queues with status ‘ready’.
If i switch com.test.EventHandler2 with com.test.EventHandler1 then com.test.EventHandler2 gets triggered.
Not sure if there is any mistake in the below configuration.
The eventlistener is throwing below exception when persisting the saga in MongoDB.
`
[WARN] org.axonframework.saga.annotation.AsyncAnnotatedSagaManager$LoggingExceptionHandler - A fatal exception occurred while processing an Event for a Saga. Processing will continue with the next Event
org.axonframework.serializer.SerializationException: An exception occurred writing serialized data to the output stream
at org.axonframework.serializer.JavaSerializer.serialize(JavaSerializer.java:72) ~[axon-core-2.3.2.jar:2.3.2]
at org.axonframework.saga.repository.mongo.SagaEntry.(SagaEntry.java:65) ~[axon-mongo-2.3.2.jar:2.3.2]
at org.axonframework.saga.repository.mongo.MongoSagaRepository.storeSaga(MongoSagaRepository.java:117) ~[axon-mongo-2.3.2.jar:2.3.2]
at org.axonframework.saga.repository.AbstractSagaRepository.add(AbstractSagaRepository.java:51) ~[axon-core-2.3.2.jar:2.3.2]
at org.axonframework.saga.annotation.AsyncSagaEventProcessor.persistProcessedSagas(AsyncSagaEventProcessor.java:219) ~[axon-core-2.3.2.jar:2.3.2]
at org.axonframework.saga.annotation.AsyncSagaEventProcessor.doProcessEvent(AsyncSagaEventProcessor.java:147) ~[axon-core-2.3.2.jar:2.3.2]
at org.axonframework.saga.annotation.AsyncSagaEventProcessor.onEvent(AsyncSagaEventProcessor.java:118) ~[axon-core-2.3.2.jar:2.3.2]
at org.axonframework.saga.annotation.AsyncSagaEventProcessor.onEvent(AsyncSagaEventProcessor.java:49) ~[axon-core-2.3.2.jar:2.3.2]
at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:133) ~[disruptor-3.2.0.jar:na]
at org.axonframework.saga.annotation.AsyncAnnotatedSagaManager$StartDetectingRunnable.run(AsyncAnnotatedSagaManager.java:481) [axon-core-2.3.2.jar:2.3.2]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_25]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]
Caused by: java.io.NotSerializableException: org.axonframework.eventhandling.ClusteringEventBus
Both the issues are apparently configuration issues. Just posting on this thread for future reference:
Issue1 (Any SagaEventHandler configured after the first type is not consuming the events)
SagaManager is essentially an EventListener and hence while subscribing it is wired to a single cluster which by default is using the first axon-type.
Fix: For 2 clusters, configuring 2 separate SagaManagers with corresponding axon-types resolves this.
Issue2 (The eventlistener is throwing below exception when persisting the saga in MongoDB.)
For persistent saga, missed marking the resources as ‘transient’.
Axon was trying to persist the Eventbus which was injected by spring-resource injector (which is definitely not what i wanted).
thanks for posting the solution.
The first issue looks weird though. It should be perfectly fine to use multiple saga types in the same Saga Manager.
Which Axon version do you use?
We are seeing the ‘ResourceInjector’ is working only for the first event and the second event (OrderSaved) is failing with ‘NullPtrException’ as the ‘repository’ is not injected.
Scenario 2 (Reprocess of event for which Saga is Open)
The same behavior appears when the second time a new OrderCreatedEvent repeats(say reprocessed) when the persisted-saga (which is still open) is deserialized. This also doesn’t have the resources injected. Is this by-design or is there a mis-configuration.
Which repository are you injecting? I don’t see a repository defined in your Spring context (other than the Saga one, which you should never have to inject).
You don’t have to specify the resoucre injector, as the Spring one is the default when using the element.
Not clear on your question. The Saga has 2 attributes (eventBus, repository - JPA repo). Both are injected via @Autowired. Now, both the resources are available for the first event (based event triggered). But both the attributes are null when subsequent events are fired from the base-event (scenario 1) OR existing Saga is processed (scenario 2)
Just to clarify, is there any convention/config required by the resource-injector to inject the resources every time the Saga is invoked?