I have saga for sending command from order service to payment service. In following code you will see code example:
@StartSaga
@SagaEventHandler(associationProperty = “orderId”)
private void handle(OrderCreateEvent event) {
String paymentId = UUID.randomUUID().toString();
SagaLifecycle.associateWith(“paymentId”, paymentId);
CompletePaymentCommand command = CompletePaymentCommand.builder()
.orderId(event.getOrderId())
.paymentId(paymentId)
.price(event.getPrice())
.userId(event.getUserId())
.build();
commandGateway.send(command);
}
and following is my code that will actually consume command:
@CommandHandler
public PaymentAggregate(CompletePaymentCommand command) {
System.out.println("payment command: " + command.getUserId());
CompletePaymentEvent event = CompletePaymentEvent.builder()
.orderId(command.getOrderId())
.paymentId(command.getPaymentId())
.paymentStatus(command.getPaymentStatus())
.userId(command.getUserId())
.price(command.getPrice())
.build();
AggregateLifecycle.apply(event);
}
I am getting following error after saga sends comment for complete payment:
2025-02-03 16:39:32.110 WARN 60188 — [agaProcessor]-0] o.a.c.gateway.DefaultCommandGateway : Command ‘com.demo.saga.core.commands.CompletePaymentCommand’ resulted in org.axonframework.commandhandling.NoHandlerForCommandException(No handler was subscribed for command [com.demo.saga.core.commands.CompletePaymentCommand].)
Hi Arif,
What is your command bus configuration (I’m assuming you’re only using Axon Framework and that the order and payment services are separate processes, in which case you’d have to use a DistributedCommandBus)?
/Marc
what I have used for distributed command bus is as follows. I also tried to use jackson instead of XStream
axon.kafka.bootstrap-servers=localhost:9092
axon.eventhandling.processors.default.mode=tracking
axon.eventhandling.processors.default.source=kafkaMessageSource
Command bus configuration
axon.distributed.command-bus.enabled=true
axon.distributed.command-bus.type=kafka
axon.serializer.general=jackson
axon.serializer.events=jackson
axon.serializer.messages=jackson
axon.serializer.snapshot=jackson
spring.kafka.producer.bootstrap-servers=localhost:9092
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
spring.kafka.consumer.bootstrap-servers=localhost:9092
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
spring.kafka.consumer.properties.spring.json.trusted.packages=*
Hi Arif,
There is no distributed command bus based on Kafka in Axon Framework - you have to choose between one of the available options such as the SpringCloud extension, see more here:
https://docs.axoniq.io/axon-framework-reference/development/axon-framework-commands/infrastructure/#DistributedCommandBus
/Marc