All events replayed on JVM startup

I am trying to use the Kafka extension with Axon server 4.3.

I have a very simple test application:
The producer side generates an Event in response to a Command.
The consumer side (in another JVM) has an @EventHandler to handle the event.

The producer is using a subscribing event processor.
The consumer is using a tracking event processor.

I have JPA with an H2 database configured as the Token store.

When I start the producer and publish a few messages, everything is fine and I can see the messages on the consumer side.

However, if I restart either the producer or the consumer JVM, all the events are “replayed” again to Kafka…even though the token store (H2) has the correct “globalIndex” for each token.

The same topic name is used on both producer and consumer.
I have a unique Processing Group for my EventHandler.

Do I need to set the “group.id” property on the consumer side??

Any help would be greatly appreciated!

Thanks!

  • Avinash

Some more details on my setup:

On the producer Spring Boot application, I force the use of subscribing processors in my Axon configuration:

@Autowired
public void configureEventSubscribers(EventProcessingConfigurer configurer) {
    configurer.usingSubscribingEventProcessors();
}

application.properties for the producer:

spring:
  application:
    name: producer
  datasource:
    url: jdbc:h2:tcp://${H2_DB_HOST:localhost}:9090/./axondb;DB_CLOSE_ON_EXIT=FALSE;IFEXISTS=TRUE;

axon:
  serializer:
    general: jackson
    events: jackson
    messages: jackson

  kafka:
    client-id: producer
    default-topic: axon.topic
    bootstrap-servers: localhost:9092

    producer:
       event-processor-mode: subscribing

On the consumer side, I use a TRACKING event processor. This is my Spring Boot application.properties.

spring:
  application:
    name: consumer
  datasource:
    url: jdbc:h2:tcp://${H2_DB_HOST:localhost}:9090/./axondb;DB_CLOSE_ON_EXIT=FALSE;IFEXISTS=TRUE;

axon:
  serializer:
    general: jackson
    events: jackson
    messages: jackson
    eventhandling:
      processors:
        "[myGroup]":
          source: streamableKafkaMessageSource
          mode: TRACKING

  kafka:
    client-id: consumer
    default-topic: axon.topic
    bootstrap-servers: localhost:9092
    consumer:
      client-id: consumer
      event-processor-mode: TRACKING
      properties:
        "group.id": "myGroup"

The database is a H2 database server running on port 9090 as a Windows service (always running, NOT in-memory).

The consumer has only a single EventHandler:

@Component
@ProcessingGroup("myGroup")
public class ConsumerEvents {
    @EventHandler
    public void on(SomeEvent event) {
        log.info("event: {}", event);
    }
}

With the above setup, if I only start the “producer” app (consumer is NOT running), and publish an event, I can see the message in the Kafka topic (i.e. message count is 1).

Then if I start the “consumer” app, it reads the event stream from the beginning and consumes the event (@EventHandler gets invoked) BUT I see the Kafka message count is now 2… it appears that the consumer also publishes ANOTHER copy of the event message to Kafka when the EventHandler gets called.

Also, in the Token store, I see TWO event processors registered:

  1. org.axonframework.extensions.kafka.eventhandling.producer
  2. myGroup

I do not have any configuration for a TRACKING Kafka producer, so how did the org.axonframework.extensions.kafka.eventhandling.producer EVENT processor get registered??

Ideally, what I need is a SUBSCRIBING producer and a TRACKING consumer. Am I doing anything wrong? Any help would be greatly appreciated!

Thanks!

Hi Avinash,

Do you by any chance have Spring Boot Devtools on the classpath as well?

I have quite recently seen such weird inconsistent behaviour as events being republished by a subscribing producer, which doesn’t make sense.
Only tracking producers should be able to do that, so I am guessing it’s a wiring issue.

Cheers,
Steven

PS. It is important to note that this mailing list will be discontinued as specified in this thread.
The thread also specifies where to look further for help when it comes to Axon as soon as this mailing list is closed.