All my @SagaEventHandler methods not triggered

Hi,

I have made a Saga, and the method annotated with both @StartSaga and @SagaEventHandler is triggered when I from the class looking like this:

public class RunSupplierSaga {

static Logger log = LoggerFactory.getLogger(RunSupplierSaga.class);

@SuppressWarnings(“unchecked”)
public static void main(String[] args) throws InterruptedException {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(“spring-context.xml”);

EventBus eventBus = applicationContext.getBean(EventBus.class);

log.debug(“About to pubish a TransportOrderSentEvent”);
eventBus.publish(asEventMessage(new TransportOrderSentEvent(“123”)));

applicationContext.close();
}
}

The event fired when the CreateSupplierOrderCommand is handled is not handled by the SupplierSaga, and I don’t understand why. Here are all the classes involoved: http://pastie.org/9131603

and here is the log output when I also print debug for axon framework:

2014-05-01 21:40:44,596 [main] INFO - ContentTypeConverter of type [class org.axonframework.serializer.xml.Dom4JToByteArrayConverter] is ignored. It seems to rely on a class that is not available in the class loader: org/dom4j/Document
2014-05-01 21:40:44,598 [main] INFO - ContentTypeConverter of type [class org.axonframework.serializer.xml.InputStreamToDom4jConverter] is ignored. It seems to rely on a class that is not available in the class loader: org/dom4j/Document
2014-05-01 21:40:45,085 [main] DEBUG - Mongo Options
2014-05-01 21:40:45,085 [main] DEBUG - Connections per host :100
2014-05-01 21:40:45,085 [main] DEBUG - Connection timeout : 10000
2014-05-01 21:40:45,085 [main] DEBUG - Max wait timeout : 120000
2014-05-01 21:40:45,085 [main] DEBUG - Threads allowed to block : 5
2014-05-01 21:40:45,085 [main] DEBUG - Autoconnect retry : false
2014-05-01 21:40:45,085 [main] DEBUG - Socket timeout : 0
2014-05-01 21:40:45,119 [main] INFO - ContentTypeConverter of type [class org.axonframework.serializer.xml.Dom4JToByteArrayConverter] is ignored. It seems to rely on a class that is not available in the class loader: org/dom4j/Document
2014-05-01 21:40:45,119 [main] INFO - ContentTypeConverter of type [class org.axonframework.serializer.xml.InputStreamToDom4jConverter] is ignored. It seems to rely on a class that is not available in the class loader: org/dom4j/Document
2014-05-01 21:40:45,198 [main] DEBUG - About to pubish a TransportOrderSentEvent
2014-05-01 21:40:45,199 [main] DEBUG - Looking for IdentifierFactory implementation using the context class loader
2014-05-01 21:40:45,199 [main] DEBUG - Looking for IdentifierFactory implementation using the IdentifierFactory class loader.
2014-05-01 21:40:45,200 [main] DEBUG - Using default UUID-based IdentifierFactory
2014-05-01 21:40:45,265 [main] DEBUG - ***** TransportOrderSentEvent FIRED, id: 123
2014-05-01 21:40:45,344 [main] DEBUG - L1 - Starting SupplierSaga for purchaseOrderId ‘123’ -> ‘supplier-order-id-1’ (supplierOrderId)
2014-05-01 21:40:45,344 [main] DEBUG - Dispatching command [com.navarsete.stand012.supplier.command.CreateSupplierOrderCommand]
2014-05-01 21:40:45,347 [main] DEBUG - Starting Unit Of Work.
2014-05-01 21:40:45,348 [main] DEBUG - Registering Unit Of Work as CurrentUnitOfWork
2014-05-01 21:40:45,348 [main] DEBUG - handle CreateSupplierOrderCommand for purchaseOrderId ‘supplier-order-id-1’
2014-05-01 21:40:45,356 [main] DEBUG - Registering listener: org.axonframework.repository.LockingRepository$LockCleaningListener
2014-05-01 21:40:45,356 [main] DEBUG - Committing Unit Of Work
2014-05-01 21:40:45,356 [main] DEBUG - Notifying listeners of commit request
2014-05-01 21:40:45,357 [main] DEBUG - Notifying listener [org.axonframework.repository.LockingRepository$LockCleaningListener] of upcoming commit
2014-05-01 21:40:45,357 [main] DEBUG - Listeners successfully notified
2014-05-01 21:40:45,357 [main] DEBUG - Persisting changes to aggregates
2014-05-01 21:40:45,357 [main] DEBUG - Persisting changes to [com.navarsete.stand012.supplier.SupplierOrder], identifier: [supplier-order-id-1]
2014-05-01 21:40:45,388 [main] DEBUG - 1 events appended
2014-05-01 21:40:45,389 [main] DEBUG - Aggregates successfully persisted
2014-05-01 21:40:45,389 [main] DEBUG - This Unit Of Work is not nested. Finalizing commit…
2014-05-01 21:40:45,389 [main] DEBUG - Publishing events to the event bus
2014-05-01 21:40:45,389 [main] DEBUG - Publishing event [com.navarsete.stand012.supplier.event.SupplierOrderCreatedEvent] to event bus [org.axonframework.eventhandling.ClusteringEventBus@3ff5022b]
2014-05-01 21:40:45,390 [main] DEBUG - Registering listener: org.axonframework.eventhandling.SimpleCluster$MonitorInvoker
2014-05-01 21:40:45,391 [main] DEBUG - All events successfully published.
2014-05-01 21:40:45,391 [main] DEBUG - Notifying listeners after commit
2014-05-01 21:40:45,391 [main] DEBUG - Notifying listener [org.axonframework.eventhandling.SimpleCluster$MonitorInvoker] after commit
2014-05-01 21:40:45,391 [main] DEBUG - Notifying listener [org.axonframework.repository.LockingRepository$LockCleaningListener] after commit
2014-05-01 21:40:45,391 [main] DEBUG - Stopping Unit Of Work
2014-05-01 21:40:45,391 [main] DEBUG - Notifying listeners of cleanup
2014-05-01 21:40:45,391 [main] DEBUG - Notifying listener [org.axonframework.eventhandling.SimpleCluster$MonitorInvoker] of cleanup
2014-05-01 21:40:45,391 [main] DEBUG - Notifying listener [org.axonframework.repository.LockingRepository$LockCleaningListener] of cleanup
2014-05-01 21:40:45,391 [main] DEBUG - Listeners successfully notified
2014-05-01 21:40:45,391 [main] DEBUG - Clearing resources of this Unit Of Work.
2014-05-01 21:40:45,391 [main] INFO - Command executed successfully: com.navarsete.stand012.supplier.command.CreateSupplierOrderCommand

I thought that since my Saga in spring config gets the eventBus wired/injected it should also subscribe to all events published, meaning that the SupplierOrderCreatedEvent fired from my CommandHandler in SupplierOrder would be picked up by my saga when annotating the method with @SagaEventHandler like this:

@SagaEventHandler(associationProperty = “supplierOrderId”)
public void handle(SupplierOrderCreatedEvent event) {

but this is never triggered. First I also had a separate class with @EventHandler for all these events, but I assume it’s cleaner to have the handling of events as part of my saga. I’m still a newbie to Axon, so I most likely have misunderstood some of the concepts here…)

Best regards,
Viggo

Hi Viggo,

an event will only trigger a specific saga instance, if it has been associated with a property on that event. The name of that property is defined in the @SagaEventHandler annotation. By default, a StartSaga will automatically associate the saga with the property mentioned on the @SagaEventHandler. In the event handler that is nit triggered, you provide another key. The saga instance has no association with that key, so it is not triggered. To resolve this, you must call associateWith(key, value) before sending the command that triggers the event you send. The key is the name of the property, the value is the value that property must have for the saga to trigger.

Hope this clarifies a bit.
Cheers,

Allard

Hi Allard:)

It made sense, and it worked, thanks a lot!!!

Regards,
Viggo

Hi Viggo,

aggregates don’t get created as the result of events. They are created as result of a command, after which the corresponding event is published. It seems you’re sending the “xxxCreatedEvent” directly to the bus. That’s most likely why the aggregate can’t be found.

Cheers,

Allard

Hi Allard,

I just realized it when I had posted the question, so I deleted it:) Sometimes the answer comes to you automatically when you’ve fired the question to a forum:)

Thanks anyway for the clarification:)

Regards,
Viggo

So, I basically had to use the CommandGateway and send a command and it worked:)