Skip to content

Spring modulith namastack kafka integration fails for NEW outbox_records after JVM restart because of unstable handler id (contains Lambda) #1777

Description

@gauquiebart

Using spring modulith 2.1.0, and namastack 1.7.0

Problem:

When restarting the JVM, the Spring modulith namastack > KafkaOutboxConfiguration$NamastackOutboxAutoConfiguration generates a handler id with another name (because it uses a lambda, which generates a serialized class name which changes after each JVM restart).

@AutoConfiguration
		@ConditionalOnClass(OutboxHandler.class)
		class NamastackOutboxAutoConfiguration {

			@Bean
			OutboxHandler namastackKafkaOutboxExternalizer() {

				logger.debug("Registering Namastack domain event outbox externalization to Kafka.");

				return (payload, metadata) -> externalizer.externalizeBlocking(payload);
			}
		}

In the table:
Namastack > outbox_record table > handler_id column:

org.springframework.modulith.events.kafka.KafkaEventExternalizerConfiguration$KafkaOutboxConfiguration$NamastackOutboxAutoConfiguration$$Lambda/0x0000007c025bcf38#handle(java.lang.Object,io.namastack.outbox.handler.OutboxRecordMetadata)

Exception I got :
No handler with id org.springframework.modulith.events.kafka.KafkaEventExternalizerConfiguration$KafkaOutboxConfiguration$NamastackOutboxAutoConfiguration$$Lambda/0x0000007c025bcf38#handle(java.lang.Object,io.namastack.outbox.handler.OutboxRecordMetadata)

In my handler_id column I got handler id's with different lambda hashes. These where created after JVM restart.

Any record in that table with status NEW will then fail with the no handler with id error.

Solution:
Provide a stable name for this OutboxHandler bean by not using a lambda.

Consequence
Current users will have to update their handler id's in the outbox_record tables upon update to version containing fix.

Possible workaround
Provide a bean post processor that tests for this auto created bean name, and wrap it in a spring bean with a stable class name.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions