souvikc
souvikc

Reputation: 1031

AXONIQ-4002 error while using Axon Framework with spring boot

I am invoking the CommandGateway.send method from my rest controller but the control is not going into the Aggregate class and after 5 mins 500 internal server error is coming. When i debugged the application I found the below error is thrown by Axon ->

AxonServerRemoteCommandHandlingException{message=An exception was thrown by the remote message handling component: , errorCode='AXONIQ-4002', server=''}

Below are my Java files :

The Rest controller ->

@RestController
@RequestMapping("/product")
public class ProductController {

@Autowired
private CommandGateway gateway;

@PostMapping
public ResponseEntity createProduct(@RequestBody CreateProductModel model) {
    
    CreateProductCommand command=CreateProductCommand.builder()
            .price("$123")
            .productId(UUID.randomUUID().toString())
            .product("Shoe")
            .build();
    
    String s=gateway.sendAndWait(command);
    
    return new ResponseEntity<String>(HttpStatus.CREATED);
}

The ProductCreatedEvent object ->

import lombok.Data;

@Data
public class ProductCreatedEvent {
@TargetAggregateIdentifier
private  String productId;
private  String product;
private  String price ;

}

The command class CreateProductCommand ->

@Builder
@Data
public class CreateProductCommand {
@TargetAggregateIdentifier
private final String productId;
private final String product;
private final String price ;

}

The Aggregate class ->

@Aggregate
public class ProductAggregate {

@AggregateIdentifier
private  String productId;
private  String product;
private  String price ;

public ProductAggregate() {
    
}

@CommandHandler
public ProductAggregate(CreateProductCommand command) {
    //TODO: Validation logic can be handled here
    ProductCreatedEvent event=new ProductCreatedEvent();
    
    BeanUtils.copyProperties(command, event);
    AggregateLifecycle.apply(event);
}

@EventSourcingHandler
public void on(ProductCreatedEvent event) {
    this.price=event.getPrice();
    this.productId=event.getProductId();
    this.product=event.getProduct();
    
}

}

Also i am using the below axon spring boot starter :

    <dependency>
        <groupId>org.axonframework</groupId>
        <artifactId>axon-spring-boot-starter</artifactId>
        <version>4.4.7</version>
    </dependency>

Upvotes: 2

Views: 1625

Answers (1)

souvikc
souvikc

Reputation: 1031

This is resolved. I had to exclude the axon-server-connector dependency from the below axon-spring starter

        <dependency>
        <groupId>org.axonframework</groupId>
        <artifactId>axon-spring-boot-starter</artifactId>
        <version>4.0.3</version>
        <exclusions>
            <exclusion>
                <groupId>org.axonframework</groupId>
                <artifactId>axon-server-connector</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Upvotes: 0

Related Questions