Strange EventBus behavior and multiple Beans with Spring Autoconfig?

I am again having some very strange behavior. I am using Spring Boot, Flyway for database migration, Axon Server(Docker) and Kotlin.

Currently the when I publish on the eventBus I get no log messages and the EventHandler is not entered. However after I shut down my program in intellj, delete token_entry table from postgres, restart my program in intellj (Flyway auto generates the table again), then all the EventHandlers are called from the previous run? This is very strange to me…

Lastly, EventSourcingHandler and EventHandlers seem to be working fine when using the CommandHandler and AggregateLifecycle.apply(event)

Here is my code / config :

	    <dependency>
			<groupId>org.axonframework</groupId>
			<artifactId>axon-spring-boot-starter</artifactId>
			<version>4.4.2</version>
		</dependency>
    @PostMapping
    @RequestMapping("/testEb")
    fun testEB() {
        eb.publish(GenericEventMessage.asEventMessage<CreateContractEvent>(CreateContractCommand(
                contractId = UUID.randomUUID().toString()
        )))
    }
    @EventHandler
    fun handle(createContractEvent: CreateContractEvent) {
        print("\ninside Event Handler")
    }
}
@Configuration
class AxonConfig {

    @Autowired
    lateinit var transactionManager: PlatformTransactionManager

    @Bean
    fun eventScheduler(eventBus: EventBus): SimpleEventScheduler {
        return SimpleEventScheduler.builder()
                .eventBus(eventBus)
                .scheduledExecutorService(Executors.newSingleThreadScheduledExecutor())
                .build()
    }
}

Hi @tieu,

Let me repeat the following snippet you’ve shared:

@PostMapping
@RequestMapping("/testEb")
fun testEB() {
    eb.publish(GenericEventMessage.asEventMessage<CreateContractEvent>(
        CreateContractCommand(contractId = UUID.randomUUID().toString())
    ))
}

So, yes you are publishing a GenericEventMessage, but you are putting in a CreateContractCommand. Due to this I would be pretty certain you wouldn’t see any of your @EventHandler annotated methods reacting to the CreateContractEvent to be invoked ever. More exactly Axon looks for handlers with a matching payload type. In your sample the EventMessage will have a payloadType of CreateContractCommand, whilst your event handler has a payloadType of CreateContractEvent.

What typically helps to overcome such errors, is to use current tense for commands and past tense for events. It further changes the naming of your messages making it more evident if you accidentally use a command as an event. Additionally it resembles what Commands and Events are more closely: “expressions of intent to perform something” (current tense) and “notification that something has happened” (past tense).

Hope this helps you out @tieu!

Cheers,
Steven

Thank you. That makes a lot of sense.

However, I forgot to explain the screenshot. I was trying to set up an EventScheduler with AxonServer. I ran into 2 eventBus beans that seem to be Auto Configured. Is there one I should be using over the other? Why would there be two eventBus beans auto configured?

Two beans sounds interesting really.
Can you provide the exact types of both configured beans?

I know there are some other frameworks which also create beans with the name eventBus, but with different fully qualified class names. Might be this is a clash with another framework, although I’m not a 100% sure there.