davsclaus commented on code in PR #18583: URL: https://github.com/apache/camel/pull/18583#discussion_r2198164456
########## components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyConfiguration.java: ########## @@ -0,0 +1,247 @@ +/* + * 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 org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.iggy.message.Partitioning; +import org.apache.iggy.topic.CompressionAlgorithm; + +@UriParams +public class IggyConfiguration implements Cloneable { + + @UriParam(defaultValue = "localhost", description = "Iggy server hostname or IP address") + private String host = "localhost"; + @UriParam(defaultValue = "8090", description = "Iggy server port number") + private int port = 8090; + @UriParam(description = "Iggy username") + private String username; + @UriParam(secret = true, description = "Iggy password") + private String password; + @UriParam(defaultValue = "true", + description = "Whether to automatically create stream if it doesn't exist") + private boolean autoCreateStream = true; + @UriParam(defaultValue = "true", + description = "Whether to automatically create topic if it doesn't exist") Review Comment: avoid using ' in text but say does not exists ########## components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyEndpoint.java: ########## @@ -0,0 +1,169 @@ +/* + * 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.util.Objects; +import java.util.Optional; +import java.util.concurrent.ExecutorService; + +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.DefaultEndpoint; +import org.apache.iggy.client.blocking.tcp.IggyTcpClient; +import org.apache.iggy.consumergroup.ConsumerGroupDetails; +import org.apache.iggy.identifier.ConsumerId; +import org.apache.iggy.identifier.StreamId; +import org.apache.iggy.identifier.TopicId; +import org.apache.iggy.stream.StreamDetails; +import org.apache.iggy.topic.TopicDetails; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static java.util.Optional.empty; + +@UriEndpoint(firstVersion = "4.14.0-SNAPSHOT", scheme = "iggy", title = "Iggy", syntax = "iggy:topicName", Review Comment: there is some kind of headerClass=xxx which you can use to point to a class with marked up constant for headers that gets included in the docs and tooling. Take a look at some of the other components ########## components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyConfiguration.java: ########## @@ -0,0 +1,247 @@ +/* + * 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 org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.iggy.message.Partitioning; +import org.apache.iggy.topic.CompressionAlgorithm; + +@UriParams +public class IggyConfiguration implements Cloneable { + + @UriParam(defaultValue = "localhost", description = "Iggy server hostname or IP address") + private String host = "localhost"; + @UriParam(defaultValue = "8090", description = "Iggy server port number") + private int port = 8090; + @UriParam(description = "Iggy username") + private String username; + @UriParam(secret = true, description = "Iggy password") + private String password; + @UriParam(defaultValue = "true", + description = "Whether to automatically create stream if it doesn't exist") + private boolean autoCreateStream = true; + @UriParam(defaultValue = "true", + description = "Whether to automatically create topic if it doesn't exist") + private boolean autoCreateTopic = true; + @UriParam(description = "Stream identifier") + private Long streamId; + @UriParam(description = "Stream name") + private String streamName; + @UriParam(defaultValue = "1", description = "Number of partitions for the topic") + private Long partitionsCount = 1L; + @UriParam(defaultValue = "None", enums = "None,Gzip", + description = "Compression algorithm for message payload") + private CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm.None; + @UriParam(defaultValue = "0", description = "Message expiry time in seconds (0 means no expiry)") + private BigInteger messageExpiry = BigInteger.ZERO; Review Comment: Is BigInteger really needed can it be a long instead ########## components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyConfiguration.java: ########## @@ -0,0 +1,247 @@ +/* + * 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 org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.iggy.message.Partitioning; +import org.apache.iggy.topic.CompressionAlgorithm; + +@UriParams +public class IggyConfiguration implements Cloneable { + + @UriParam(defaultValue = "localhost", description = "Iggy server hostname or IP address") + private String host = "localhost"; + @UriParam(defaultValue = "8090", description = "Iggy server port number") + private int port = 8090; + @UriParam(description = "Iggy username") Review Comment: secret = true label=security for these kind of options. Only secret if it should be hidden like a password or api key etc ########## components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyProducer.java: ########## @@ -0,0 +1,133 @@ +/* + * 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.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.camel.AsyncCallback; +import org.apache.camel.Exchange; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.support.DefaultAsyncProducer; +import org.apache.iggy.client.blocking.tcp.IggyTcpClient; +import org.apache.iggy.identifier.StreamId; +import org.apache.iggy.identifier.TopicId; +import org.apache.iggy.message.Message; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class IggyProducer extends DefaultAsyncProducer { + private static final Logger LOG = LoggerFactory.getLogger(IggyProducer.class); + + private final IggyEndpoint endpoint; + private IggyTcpClient client; + + public IggyProducer(IggyEndpoint endpoint) { + super(endpoint); + this.endpoint = endpoint; + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + client = new IggyTcpClient(endpoint.getConfiguration().getHost(), endpoint.getConfiguration().getPort()); + + if (endpoint.getConfiguration().getUsername() != null) { + client.users().login(endpoint.getConfiguration().getUsername(), endpoint.getConfiguration().getPassword()); + } + + endpoint.initializeTopic(client); + } + + @Override + public boolean process(Exchange exchange, AsyncCallback callback) { + // TODO overrides from headers and reinitialize topic if topic/stream was updated + IggyConfiguration iggyConfiguration = endpoint.getConfiguration(); + + try { + Object body = exchange.getIn().getBody(); + + if (body instanceof List bodyAsList) { + List<Message> messages; + + if (isListOfStrings(bodyAsList)) { + messages = (List<Message>) bodyAsList.stream() + .map(s -> Message.of((String) s)) + .collect(Collectors.toList()); + } else if (isListOfMessages(bodyAsList)) { + messages = bodyAsList; + } else { + throw new RuntimeCamelException( + String.format( + "Unsupported List body type: %s, only List<String> or List<org.apache.iggy.message.Message> are supported", + body.getClass().toString())); + } + + client.messages().sendMessages( + StreamId.of(iggyConfiguration.getStreamName()), + TopicId.of(endpoint.getTopicName()), + iggyConfiguration.getPartitioning(), + messages); + } else if (body instanceof byte[] bodyAsByteArray) { + client.messages().sendMessages( + StreamId.of(iggyConfiguration.getStreamName()), + TopicId.of(endpoint.getTopicName()), + iggyConfiguration.getPartitioning(), + Collections.singletonList(Message.of(new String(bodyAsByteArray)))); + } else if (body instanceof String bodyAsString) { + client.messages().sendMessages( + StreamId.of(iggyConfiguration.getStreamName()), + TopicId.of(endpoint.getTopicName()), + iggyConfiguration.getPartitioning(), + Collections.singletonList(Message.of(bodyAsString))); + } else if (body instanceof Message bodyAsMessage) { + client.messages().sendMessages( + StreamId.of(iggyConfiguration.getStreamName()), + TopicId.of(endpoint.getTopicName()), + iggyConfiguration.getPartitioning(), + Collections.singletonList(bodyAsMessage)); + } else { + throw new RuntimeCamelException( + """ + Unsupported body type: %s. + + Supported body types are List<org.apache.iggy.message.Message>, java.lang.String, byte[], org.apache.iggy.message.Message + """ + .formatted(body.getClass().toString())); + } + + LOG.debug("message sent"); + } catch (Exception e) { + LOG.error(e.getMessage(), e); Review Comment: no need to log and set exception ########## components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyProducer.java: ########## @@ -0,0 +1,133 @@ +/* + * 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.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.camel.AsyncCallback; +import org.apache.camel.Exchange; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.support.DefaultAsyncProducer; +import org.apache.iggy.client.blocking.tcp.IggyTcpClient; +import org.apache.iggy.identifier.StreamId; +import org.apache.iggy.identifier.TopicId; +import org.apache.iggy.message.Message; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class IggyProducer extends DefaultAsyncProducer { + private static final Logger LOG = LoggerFactory.getLogger(IggyProducer.class); + + private final IggyEndpoint endpoint; + private IggyTcpClient client; + + public IggyProducer(IggyEndpoint endpoint) { + super(endpoint); + this.endpoint = endpoint; + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + client = new IggyTcpClient(endpoint.getConfiguration().getHost(), endpoint.getConfiguration().getPort()); + + if (endpoint.getConfiguration().getUsername() != null) { + client.users().login(endpoint.getConfiguration().getUsername(), endpoint.getConfiguration().getPassword()); + } + + endpoint.initializeTopic(client); + } + + @Override + public boolean process(Exchange exchange, AsyncCallback callback) { + // TODO overrides from headers and reinitialize topic if topic/stream was updated + IggyConfiguration iggyConfiguration = endpoint.getConfiguration(); + + try { + Object body = exchange.getIn().getBody(); + + if (body instanceof List bodyAsList) { + List<Message> messages; + + if (isListOfStrings(bodyAsList)) { + messages = (List<Message>) bodyAsList.stream() + .map(s -> Message.of((String) s)) + .collect(Collectors.toList()); + } else if (isListOfMessages(bodyAsList)) { + messages = bodyAsList; + } else { + throw new RuntimeCamelException( + String.format( + "Unsupported List body type: %s, only List<String> or List<org.apache.iggy.message.Message> are supported", + body.getClass().toString())); + } + + client.messages().sendMessages( + StreamId.of(iggyConfiguration.getStreamName()), + TopicId.of(endpoint.getTopicName()), + iggyConfiguration.getPartitioning(), + messages); + } else if (body instanceof byte[] bodyAsByteArray) { + client.messages().sendMessages( + StreamId.of(iggyConfiguration.getStreamName()), + TopicId.of(endpoint.getTopicName()), + iggyConfiguration.getPartitioning(), + Collections.singletonList(Message.of(new String(bodyAsByteArray)))); + } else if (body instanceof String bodyAsString) { + client.messages().sendMessages( + StreamId.of(iggyConfiguration.getStreamName()), + TopicId.of(endpoint.getTopicName()), + iggyConfiguration.getPartitioning(), + Collections.singletonList(Message.of(bodyAsString))); + } else if (body instanceof Message bodyAsMessage) { + client.messages().sendMessages( + StreamId.of(iggyConfiguration.getStreamName()), + TopicId.of(endpoint.getTopicName()), + iggyConfiguration.getPartitioning(), + Collections.singletonList(bodyAsMessage)); + } else { + throw new RuntimeCamelException( Review Comment: Probably better to convert body via camel to String then you can also send other things like a file / xml / json etc. ########## components/camel-iggy/src/main/java/org/apache/camel/component/iggy/IggyConfiguration.java: ########## @@ -0,0 +1,247 @@ +/* + * 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 org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.iggy.message.Partitioning; +import org.apache.iggy.topic.CompressionAlgorithm; + +@UriParams +public class IggyConfiguration implements Cloneable { + + @UriParam(defaultValue = "localhost", description = "Iggy server hostname or IP address") + private String host = "localhost"; + @UriParam(defaultValue = "8090", description = "Iggy server port number") + private int port = 8090; + @UriParam(description = "Iggy username") + private String username; + @UriParam(secret = true, description = "Iggy password") + private String password; + @UriParam(defaultValue = "true", + description = "Whether to automatically create stream if it doesn't exist") + private boolean autoCreateStream = true; + @UriParam(defaultValue = "true", + description = "Whether to automatically create topic if it doesn't exist") + private boolean autoCreateTopic = true; + @UriParam(description = "Stream identifier") + private Long streamId; + @UriParam(description = "Stream name") + private String streamName; + @UriParam(defaultValue = "1", description = "Number of partitions for the topic") + private Long partitionsCount = 1L; + @UriParam(defaultValue = "None", enums = "None,Gzip", + description = "Compression algorithm for message payload") + private CompressionAlgorithm compressionAlgorithm = CompressionAlgorithm.None; + @UriParam(defaultValue = "0", description = "Message expiry time in seconds (0 means no expiry)") + private BigInteger messageExpiry = BigInteger.ZERO; + @UriParam(defaultValue = "0", description = "Maximum topic size in bytes (0 means unlimited)") + private BigInteger maxTopicSize = BigInteger.ZERO; + @UriParam(description = "Replication factor for the topic") + private Short replicationFactor; + @UriParam(defaultValue = "balanced", description = "Partitioning strategy for message distribution") + private Partitioning partitioning = Partitioning.balanced(); + @UriParam(label = "consumer", description = "The name of the consumer group") + private String consumerGroupName; + @UriParam(label = "consumer", description = "The consumer's poll batch size", defaultValue = "10") + private Long pollBatchSize = 10L; + @UriParam(label = "consumer", description = "The consumer's partition id (optional)") + private Long partitionId; + @UriParam(label = "consumer", defaultValue = "1", description = "Camel Iggy consumers count") + private int consumersCount = 1; + @UriParam(label = "common", defaultValue = "30000", description = "Camel Iggy's shutdown timeout") Review Comment: is there no producer only options, if there is then remember label=producer also consider options that are not commuly used to mark them with label advanced -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
