0
votes

I am very new to axon. I have the following query. I am running 2 micro-services viz Payment and Order using Cassandra as an Event Store and Kafka . From the payment micro-service. I am dispatching an event from eventGateway

    @Component
    @ProcessingGroup("OrderProcessor")
    public class OrderEventHandler {
        @Inject
        private EventGateway eventGateway;
        public void createOrder() {
            OrderCreatedEvent orderCreatedEvent = new OrderCreatedEvent("orderId",
                100,
                "CREATED");
            eventGateway.publish(orderCreatedEvent);
        }

Also, I have configured the sagaStore and repository components SagaViewRepository

@Repository
 public interface SagaViewRepository extends CassandraRepository<SagaView, String> {
}

SagaStore

public CassandraSagaStore sagaStoreStore() {
    return  CassandraSagaStore(...);
}

How do I listen the above event (OrderCreatedEvent ) in SagaEvent Listener present in Order microservice. Below is the implementation

    @Saga(sagaStore = "sagaStoreStore")
    public class OrderManagementSaga {

        @Inject
        private transient CommandGateway commandGateway;

        @StartSaga
        @SagaEventHandler(associationProperty = "orderId")
        public void handle(OrderCreatedEvent orderCreatedEvent){
            //Saga invoked;
        }

Any hints in the are much appreciated Thank You.

1

1 Answers

1
votes

In virtually any project, I would not immediately go for the microservices route. If you are taking that route, it means you are stuck in infrastructure work, like how to send a message from one service to another, instead of providing business functionality.

That doesn't mean I would not use messaging already in your application. It is the usages of commands, events and queries which allows you to change the distance of your message buses to whatever length.

Anyhow, this is more so a recommendation than an answer to your question. To be honest, I am unsure what you are looking for. You already stated you are using Cassandra (not supported from within Axon at any means by the way) and Kafka. That makes it so that Kafka is your means to publish events between services, right? That is what Axon provides the Kafka Extension for, for example.

Do note that taking this route will require you to define different pieces of infrastructure for command, event and query dispatching, as well as event storage. Furthermore, as already shortly pointed out, Axon doesn't view Cassandra as an optimal Event Store. If you want to know why I'd recommend you take a look at this presentation.

Instead of going for "segregated infrastructure customization , I would recommend giving Axon Server a try. It is a one-stop-shop to distribute commands, events and queries, as well as a fully optimized event store. One thing is for certain, you wouldn't have to really think about "how to dispatch an event from your Payment service to your Order service. It would simply do it as long as your Axon application is connected to Axon Server (which is also a breeze). If you want to learn more about Axon Server, Axon's Reference Guide has a dedicated section on it you can read here.

If you feel Kafka is the way to go, that's also fine of course. It will mean more work from you or your team. So you will have to account for those manhours. For more info on how to set up Axon's Kafka Extensions for event distribution, you can check this Reference Guide page. Note that Kafka will only bring you event distribution. You are thus still left with solving the problem of command distribution, query distribution and event storage.