diff --git a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/properties/NarayanaProperties.java b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/properties/NarayanaProperties.java index 42959330..3e4fb8f6 100644 --- a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/properties/NarayanaProperties.java +++ b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/properties/NarayanaProperties.java @@ -45,6 +45,11 @@ public class NarayanaProperties { */ private String transactionManagerId = "1"; + /** + * Shorten transactionManagerId if necessary ( > 28 bytes). + */ + private boolean shortenTransactionManagerIdIfNecessary = false; + /** * Enable one phase commit optimization. */ @@ -146,6 +151,14 @@ public void setTransactionManagerId(String transactionManagerId) { this.transactionManagerId = transactionManagerId; } + public boolean isShortenTransactionManagerIdIfNecessary() { + return this.shortenTransactionManagerIdIfNecessary; + } + + public void setShortenTransactionManagerIdIfNecessary(boolean shortenTransactionManagerIdIfNecessary) { + this.shortenTransactionManagerIdIfNecessary = shortenTransactionManagerIdIfNecessary; + } + public boolean isOnePhaseCommit() { return this.onePhaseCommit; } diff --git a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/properties/NarayanaPropertiesInitializer.java b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/properties/NarayanaPropertiesInitializer.java index f9f0ec99..11ced3ab 100644 --- a/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/properties/NarayanaPropertiesInitializer.java +++ b/narayana-spring-boot-core/src/main/java/dev/snowdrop/boot/narayana/core/properties/NarayanaPropertiesInitializer.java @@ -47,7 +47,7 @@ public NarayanaPropertiesInitializer(NarayanaProperties narayanaProperties) { @Override public void afterPropertiesSet() { - setNodeIdentifier(this.properties.getTransactionManagerId()); + setNodeIdentifier(this.properties.getTransactionManagerId(), this.properties.isShortenTransactionManagerIdIfNecessary()); setXARecoveryNodes(this.properties.getXaRecoveryNodes()); setObjectStoreDir(this.properties.getLogDir()); setCommitOnePhase(this.properties.isOnePhaseCommit()); @@ -63,10 +63,12 @@ public void afterPropertiesSet() { setExpiryScanners(this.properties.getExpiryScanners()); } - private void setNodeIdentifier(String nodeIdentifier) { + private void setNodeIdentifier(String nodeIdentifier, boolean shortenNodeNameIfNecessary) { String verifiedNodeIdentifier = nodeIdentifier; try { - if (nodeIdentifier != null && nodeIdentifier.getBytes(StandardCharsets.UTF_8).length > 28) { + if (nodeIdentifier != null + && nodeIdentifier.getBytes(StandardCharsets.UTF_8).length > 28 + && shortenNodeNameIfNecessary) { verifiedNodeIdentifier = shortenNodeIdentifier(nodeIdentifier); } diff --git a/narayana-spring-boot-core/src/test/java/dev/snowdrop/boot/narayana/core/properties/NarayanaPropertiesInitializerTests.java b/narayana-spring-boot-core/src/test/java/dev/snowdrop/boot/narayana/core/properties/NarayanaPropertiesInitializerTests.java index f793f3d8..5a89f693 100644 --- a/narayana-spring-boot-core/src/test/java/dev/snowdrop/boot/narayana/core/properties/NarayanaPropertiesInitializerTests.java +++ b/narayana-spring-boot-core/src/test/java/dev/snowdrop/boot/narayana/core/properties/NarayanaPropertiesInitializerTests.java @@ -116,6 +116,7 @@ void shouldSetDefaultProperties() { void shouldSetModifiedProperties() { NarayanaProperties narayanaProperties = new NarayanaProperties(); narayanaProperties.setTransactionManagerId("test-id"); + narayanaProperties.setShortenTransactionManagerIdIfNecessary(true); narayanaProperties.setLogDir("test-dir"); narayanaProperties.setDefaultTimeout(1); narayanaProperties.setPeriodicRecoveryPeriod(2);