This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new c4efd9018fb7 CAMEL-25725: camel-iggy - send messageExpiry to Iggy in
microseconds (#28033)
c4efd9018fb7 is described below
commit c4efd9018fb7ee412059865db943e0b4aca500b6
Author: allthingssecurity <[email protected]>
AuthorDate: Sun Oct 18 21:00:57 2026 +0530
CAMEL-25725: camel-iggy - send messageExpiry to Iggy in microseconds
(#28033)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/component/iggy/IggyEndpoint.java | 21 +++++-
.../component/iggy/IggyTopicMessageExpiryTest.java | 85 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 8 ++
3 files changed, 113 insertions(+), 1 deletion(-)
diff --git
a/components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyEndpoint.java
b/components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyEndpoint.java
index 6491d58a51eb..a8a68f9b6b64 100644
---
a/components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyEndpoint.java
+++
b/components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyEndpoint.java
@@ -52,6 +52,9 @@ import org.slf4j.LoggerFactory;
category = { Category.MESSAGING }, headersClass =
IggyConstants.class)
public class IggyEndpoint extends DefaultEndpoint implements
HeaderFilterStrategyAware {
+ private static final BigInteger MICROS_PER_SECOND =
BigInteger.valueOf(1_000_000L);
+ private static final BigInteger U64_MAX =
BigInteger.ONE.shiftLeft(64).subtract(BigInteger.ONE);
+
private static final Logger LOG =
LoggerFactory.getLogger(IggyEndpoint.class);
@UriParam
@@ -122,7 +125,7 @@ public class IggyEndpoint extends DefaultEndpoint
implements HeaderFilterStrateg
TopicDetails topicDetails =
client.topics().createTopic(StreamId.of(stream),
iggyConfiguration.getPartitionsCount(),
iggyConfiguration.getCompressionAlgorithm(),
-
BigInteger.valueOf(iggyConfiguration.getMessageExpiry()),
+
toIggyExpiry(iggyConfiguration.getMessageExpiry()),
BigInteger.valueOf(iggyConfiguration.getMaxTopicSize()),
topic,
options);
@@ -134,6 +137,22 @@ public class IggyEndpoint extends DefaultEndpoint
implements HeaderFilterStrateg
}
}
+ /**
+ * Converts the messageExpiry option, in seconds, to the message expiry of
an Iggy topic, which is in microseconds.
+ * 0 is passed as 0 (no expiry is set on the topic) and a negative value
is passed unchanged, as before; a value too
+ * large for an unsigned 64-bit number of microseconds becomes u64::MAX,
which Iggy reads as never expire.
+ */
+ static BigInteger toIggyExpiry(Long seconds) {
+ if (seconds == null) {
+ return BigInteger.ZERO;
+ }
+ if (seconds <= 0) {
+ return BigInteger.valueOf(seconds);
+ }
+ BigInteger micros =
BigInteger.valueOf(seconds).multiply(MICROS_PER_SECOND);
+ return micros.compareTo(U64_MAX) >= 0 ? U64_MAX : micros;
+ }
+
public void initializeTopic(IggyBaseClient client) throws Exception {
initializeTopic(client, null, null);
}
diff --git
a/components/camel-iggy/src/test/java/org/apache/camel/component/iggy/IggyTopicMessageExpiryTest.java
b/components/camel-iggy/src/test/java/org/apache/camel/component/iggy/IggyTopicMessageExpiryTest.java
new file mode 100644
index 000000000000..3bb077160e14
--- /dev/null
+++
b/components/camel-iggy/src/test/java/org/apache/camel/component/iggy/IggyTopicMessageExpiryTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.iggy;
+
+import java.math.BigInteger;
+import java.util.Optional;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.iggy.client.blocking.IggyBaseClient;
+import org.apache.iggy.identifier.StreamId;
+import org.apache.iggy.identifier.TopicId;
+import org.apache.iggy.topic.CompressionAlgorithm;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * The messageExpiry option is documented in seconds, and Iggy reads the
message expiry of a topic in microseconds. The
+ * Iggy client is a mock, no Iggy server is needed.
+ */
+public class IggyTopicMessageExpiryTest {
+
+ private static final BigInteger U64_MAX = new
BigInteger("18446744073709551615");
+
+ @Test
+ void testOneHourIsSentAsMicroseconds() throws Exception {
+ assertEquals(BigInteger.valueOf(3_600_000_000L),
createdTopicExpiry("messageExpiry=3600"));
+ }
+
+ @Test
+ void testOneSecondIsSentAsMicroseconds() throws Exception {
+ assertEquals(BigInteger.valueOf(1_000_000L),
createdTopicExpiry("messageExpiry=1"));
+ }
+
+ @Test
+ void testNoExpiryStaysZero() throws Exception {
+ assertEquals(BigInteger.ZERO, createdTopicExpiry("messageExpiry=0"));
+ }
+
+ @Test
+ void testTooLargeExpiryNeverExpires() throws Exception {
+ assertEquals(U64_MAX, createdTopicExpiry("messageExpiry=" +
Long.MAX_VALUE));
+ }
+
+ private static BigInteger createdTopicExpiry(String option) throws
Exception {
+ IggyBaseClient client = mock(IggyBaseClient.class, RETURNS_DEEP_STUBS);
+ when(client.topics().getTopic(any(StreamId.class),
any(TopicId.class))).thenReturn(Optional.empty());
+
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.start();
+ IggyEndpoint endpoint = context.getEndpoint(
+ "iggy:topic?streamName=stream&autoCreateStream=false&" +
option, IggyEndpoint.class);
+ endpoint.initializeTopic(client);
+ }
+
+ ArgumentCaptor<BigInteger> expiry =
ArgumentCaptor.forClass(BigInteger.class);
+ verify(client.topics()).createTopic(any(StreamId.class), anyLong(),
any(CompressionAlgorithm.class),
+ expiry.capture(), any(BigInteger.class), anyString(),
anyMap());
+ return expiry.getValue();
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 5d31b92772b7..1016dd2e366d 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -786,6 +786,14 @@ registered.
To restore the previous behaviour, set `webhookSecretTokenEnabled=false`: the
webhook is then registered without a
secret token, and webhook requests are not verified.
+=== camel-iggy - messageExpiry is sent to Iggy in microseconds
+
+The `messageExpiry` option is in seconds, but its value was passed unchanged
to Iggy, which reads the message expiry
+of a topic in microseconds, so a topic created by Camel
(`autoCreateTopic=true`) expired its messages a million times
+too early (`messageExpiry=3600` gave 3.6 ms instead of one hour). The value is
now converted to microseconds. Topics
+created before keep their expiry: change it on the Iggy server. If you set
`messageExpiry` in microseconds to work
+around this, set it in seconds now, or newly created topics keep their
messages a million times longer than intended.
+
=== camel-hashicorp-vault - properties without engine use the `secret` engine
A `hashicorp:` property without an engine, such as `{{hashicorp:mysecret}}` or
`{{hashicorp:mysecret#field}}`, now