davsclaus commented on code in PR #8820: URL: https://github.com/apache/camel/pull/8820#discussion_r1038750577
########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQComponent.java: ########## @@ -0,0 +1,216 @@ +/* + * 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.rocketmq; + +import java.util.Map; + +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; + +@Component("rocketmq") +public class RocketMQComponent extends DefaultComponent { + + @Metadata(label = "producer") + private String producerGroup; + + @Metadata(label = "consumer") + private String consumerGroup; + + @Metadata(label = "consumer", defaultValue = "*") + private String subscribeTags = "*"; + + @Metadata(label = "common") + private String sendTag = ""; + + @Metadata(label = "common", defaultValue = "localhost:9876") + private String namesrvAddr = "localhost:9876"; + + @Metadata(label = "producer") + private String replyToTopic; + + @Metadata(label = "producer") + private String replyToConsumerGroup; + + @Metadata(label = "advance", defaultValue = "10000") Review Comment: advanced ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQComponent.java: ########## @@ -0,0 +1,216 @@ +/* + * 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.rocketmq; + +import java.util.Map; + +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; + +@Component("rocketmq") +public class RocketMQComponent extends DefaultComponent { + + @Metadata(label = "producer") + private String producerGroup; + + @Metadata(label = "consumer") + private String consumerGroup; + + @Metadata(label = "consumer", defaultValue = "*") + private String subscribeTags = "*"; + + @Metadata(label = "common") + private String sendTag = ""; + + @Metadata(label = "common", defaultValue = "localhost:9876") + private String namesrvAddr = "localhost:9876"; + + @Metadata(label = "producer") + private String replyToTopic; + + @Metadata(label = "producer") + private String replyToConsumerGroup; + + @Metadata(label = "advance", defaultValue = "10000") + private long requestTimeoutMillis = 10000L; + + @Metadata(label = "advance", defaultValue = "1000") + private long requestTimeoutCheckerIntervalMillis = 1000L; + + @Metadata(label = "producer", defaultValue = "false") + private boolean waitForSendResult; + + @Metadata(label = "accessKey") Review Comment: label = secret, secure = true ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQEndpoint.java: ########## @@ -0,0 +1,242 @@ +/* + * 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.rocketmq; + +import org.apache.camel.AsyncEndpoint; +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Exchange; +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.camel.support.DefaultMessage; + +/** + * Send and receive messages from <a href="https://rocketmq.apache.org/">RocketMQ</a> cluster. + */ +@UriEndpoint(firstVersion = "3.20.0", scheme = "rocketmq", syntax = "rocketmq:topicName", title = "RocketMQ", + category = Category.MESSAGING, headersClass = RocketMQConstants.class) +public class RocketMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { + + @UriPath + @Metadata(required = true) + private String topicName; + @UriParam(label = "producer") + private String producerGroup; + @UriParam(label = "consumer") + private String consumerGroup; + @UriParam(label = "consumer", defaultValue = "*") + private String subscribeTags = "*"; + @UriParam(label = "producer") + private String sendTag = ""; + @UriParam(label = "producer") + private String replyToTopic; + @UriParam(label = "producer") + private String replyToConsumerGroup; + @UriParam(label = "common", defaultValue = "localhost:9876") + private String namesrvAddr = "localhost:9876"; + @UriParam(label = "advance", defaultValue = "10000") + private long requestTimeoutMillis = 10000L; + @UriParam(label = "advance", defaultValue = "1000") + private long requestTimeoutCheckerIntervalMillis = 1000L; + @UriParam(label = "producer", defaultValue = "false") + private boolean waitForSendResult; + @UriParam(label = "accessKey") Review Comment: label = security, secret = true ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQConsumer.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.rocketmq; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.Suspendable; +import org.apache.camel.support.DefaultConsumer; +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.message.MessageExt; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RocketMQConsumer extends DefaultConsumer implements Suspendable { + + private static final Logger LOG = LoggerFactory.getLogger(RocketMQConsumer.class); + + private final RocketMQEndpoint endpoint; + + private DefaultMQPushConsumer mqPushConsumer; + + public RocketMQConsumer(RocketMQEndpoint endpoint, Processor processor) { + super(endpoint, processor); + this.endpoint = endpoint; + } + + private void startConsumer() throws MQClientException { + if (mqPushConsumer != null) { + LOG.warn("Overriding RocketMQ Consumer! {}", mqPushConsumer); + } + mqPushConsumer = new DefaultMQPushConsumer( + null, endpoint.getConsumerGroup(), + AclUtils.getAclRPCHook(getEndpoint().getAccessKey(), getEndpoint().getSecretKey())); + mqPushConsumer.setNamesrvAddr(endpoint.getNamesrvAddr()); + mqPushConsumer.subscribe(endpoint.getTopicName(), endpoint.getSubscribeTags()); + mqPushConsumer.registerMessageListener((MessageListenerConcurrently) (msgs, context) -> { + MessageExt messageExt = msgs.get(0); + Exchange exchange = endpoint.createRocketExchange(messageExt.getBody()); + new RocketMQMessageConverter().setExchangeHeadersByMessageExt(exchange, messageExt); + try { + getProcessor().process(exchange); + } catch (Exception e) { + LOG.error(e.getLocalizedMessage()); Review Comment: The consumer has exception handler to deal with this instead of hardcoded LOG Something ala: getExceptionHandler().handle ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQEndpoint.java: ########## @@ -0,0 +1,242 @@ +/* + * 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.rocketmq; + +import org.apache.camel.AsyncEndpoint; +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Exchange; +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.camel.support.DefaultMessage; + +/** + * Send and receive messages from <a href="https://rocketmq.apache.org/">RocketMQ</a> cluster. + */ +@UriEndpoint(firstVersion = "3.20.0", scheme = "rocketmq", syntax = "rocketmq:topicName", title = "RocketMQ", + category = Category.MESSAGING, headersClass = RocketMQConstants.class) +public class RocketMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { + + @UriPath + @Metadata(required = true) + private String topicName; + @UriParam(label = "producer") + private String producerGroup; + @UriParam(label = "consumer") + private String consumerGroup; + @UriParam(label = "consumer", defaultValue = "*") + private String subscribeTags = "*"; + @UriParam(label = "producer") + private String sendTag = ""; + @UriParam(label = "producer") + private String replyToTopic; + @UriParam(label = "producer") + private String replyToConsumerGroup; + @UriParam(label = "common", defaultValue = "localhost:9876") + private String namesrvAddr = "localhost:9876"; + @UriParam(label = "advance", defaultValue = "10000") + private long requestTimeoutMillis = 10000L; + @UriParam(label = "advance", defaultValue = "1000") + private long requestTimeoutCheckerIntervalMillis = 1000L; + @UriParam(label = "producer", defaultValue = "false") + private boolean waitForSendResult; + @UriParam(label = "accessKey") + private String accessKey; + @UriParam(label = "secretKey") + private String secretKey; + + public RocketMQEndpoint() { + } + + public RocketMQEndpoint(String endpointUri, RocketMQComponent component) { + super(endpointUri, component); + } + + @Override + public Producer createProducer() { + return new RocketMQProducer(this); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + RocketMQConsumer consumer = new RocketMQConsumer(this, processor); + configureConsumer(consumer); + return consumer; + } + + @Override + public boolean isSingleton() { Review Comment: This is default so can be removed ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQComponent.java: ########## @@ -0,0 +1,216 @@ +/* + * 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.rocketmq; + +import java.util.Map; + +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; + +@Component("rocketmq") +public class RocketMQComponent extends DefaultComponent { + + @Metadata(label = "producer") + private String producerGroup; + + @Metadata(label = "consumer") + private String consumerGroup; + + @Metadata(label = "consumer", defaultValue = "*") + private String subscribeTags = "*"; + + @Metadata(label = "common") + private String sendTag = ""; + + @Metadata(label = "common", defaultValue = "localhost:9876") + private String namesrvAddr = "localhost:9876"; + + @Metadata(label = "producer") + private String replyToTopic; + + @Metadata(label = "producer") + private String replyToConsumerGroup; + + @Metadata(label = "advance", defaultValue = "10000") + private long requestTimeoutMillis = 10000L; + + @Metadata(label = "advance", defaultValue = "1000") + private long requestTimeoutCheckerIntervalMillis = 1000L; + + @Metadata(label = "producer", defaultValue = "false") + private boolean waitForSendResult; + + @Metadata(label = "accessKey") + private String accessKey; + + @Metadata(label = "secretKey") Review Comment: label = secret, secure = true ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQComponent.java: ########## @@ -0,0 +1,216 @@ +/* + * 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.rocketmq; + +import java.util.Map; + +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; + +@Component("rocketmq") +public class RocketMQComponent extends DefaultComponent { + + @Metadata(label = "producer") + private String producerGroup; + + @Metadata(label = "consumer") + private String consumerGroup; + + @Metadata(label = "consumer", defaultValue = "*") + private String subscribeTags = "*"; + + @Metadata(label = "common") + private String sendTag = ""; + + @Metadata(label = "common", defaultValue = "localhost:9876") + private String namesrvAddr = "localhost:9876"; + + @Metadata(label = "producer") + private String replyToTopic; + + @Metadata(label = "producer") + private String replyToConsumerGroup; + + @Metadata(label = "advance", defaultValue = "10000") + private long requestTimeoutMillis = 10000L; + + @Metadata(label = "advance", defaultValue = "1000") Review Comment: advanced ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQConstants.java: ########## @@ -0,0 +1,73 @@ +/* + * 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.rocketmq; + +import org.apache.camel.spi.Metadata; + +public final class RocketMQConstants { Review Comment: Are some of these headers ONLY used on consumer or producer, then we need to mark this as well. @essobedo can help with this ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQConsumer.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.rocketmq; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.Suspendable; +import org.apache.camel.support.DefaultConsumer; +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.message.MessageExt; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RocketMQConsumer extends DefaultConsumer implements Suspendable { + + private static final Logger LOG = LoggerFactory.getLogger(RocketMQConsumer.class); + + private final RocketMQEndpoint endpoint; + + private DefaultMQPushConsumer mqPushConsumer; + + public RocketMQConsumer(RocketMQEndpoint endpoint, Processor processor) { + super(endpoint, processor); + this.endpoint = endpoint; + } + + private void startConsumer() throws MQClientException { + if (mqPushConsumer != null) { + LOG.warn("Overriding RocketMQ Consumer! {}", mqPushConsumer); + } + mqPushConsumer = new DefaultMQPushConsumer( + null, endpoint.getConsumerGroup(), + AclUtils.getAclRPCHook(getEndpoint().getAccessKey(), getEndpoint().getSecretKey())); + mqPushConsumer.setNamesrvAddr(endpoint.getNamesrvAddr()); + mqPushConsumer.subscribe(endpoint.getTopicName(), endpoint.getSubscribeTags()); + mqPushConsumer.registerMessageListener((MessageListenerConcurrently) (msgs, context) -> { + MessageExt messageExt = msgs.get(0); + Exchange exchange = endpoint.createRocketExchange(messageExt.getBody()); + new RocketMQMessageConverter().setExchangeHeadersByMessageExt(exchange, messageExt); Review Comment: Do you really need to create a new instance per message of this converter? ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQConsumer.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.rocketmq; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.Suspendable; +import org.apache.camel.support.DefaultConsumer; +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.message.MessageExt; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RocketMQConsumer extends DefaultConsumer implements Suspendable { + + private static final Logger LOG = LoggerFactory.getLogger(RocketMQConsumer.class); + + private final RocketMQEndpoint endpoint; + + private DefaultMQPushConsumer mqPushConsumer; + + public RocketMQConsumer(RocketMQEndpoint endpoint, Processor processor) { + super(endpoint, processor); + this.endpoint = endpoint; + } + + private void startConsumer() throws MQClientException { + if (mqPushConsumer != null) { + LOG.warn("Overriding RocketMQ Consumer! {}", mqPushConsumer); Review Comment: When will this happen? eg the state of a consumer should that it handles start/stop correctly ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQEndpoint.java: ########## @@ -0,0 +1,242 @@ +/* + * 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.rocketmq; + +import org.apache.camel.AsyncEndpoint; +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Exchange; +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.camel.support.DefaultMessage; + +/** + * Send and receive messages from <a href="https://rocketmq.apache.org/">RocketMQ</a> cluster. + */ +@UriEndpoint(firstVersion = "3.20.0", scheme = "rocketmq", syntax = "rocketmq:topicName", title = "RocketMQ", + category = Category.MESSAGING, headersClass = RocketMQConstants.class) +public class RocketMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { + + @UriPath + @Metadata(required = true) + private String topicName; + @UriParam(label = "producer") + private String producerGroup; + @UriParam(label = "consumer") + private String consumerGroup; + @UriParam(label = "consumer", defaultValue = "*") + private String subscribeTags = "*"; + @UriParam(label = "producer") + private String sendTag = ""; + @UriParam(label = "producer") + private String replyToTopic; + @UriParam(label = "producer") + private String replyToConsumerGroup; + @UriParam(label = "common", defaultValue = "localhost:9876") + private String namesrvAddr = "localhost:9876"; + @UriParam(label = "advance", defaultValue = "10000") + private long requestTimeoutMillis = 10000L; + @UriParam(label = "advance", defaultValue = "1000") Review Comment: advanced ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQEndpoint.java: ########## @@ -0,0 +1,242 @@ +/* + * 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.rocketmq; + +import org.apache.camel.AsyncEndpoint; +import org.apache.camel.Category; +import org.apache.camel.Consumer; +import org.apache.camel.Exchange; +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.camel.support.DefaultMessage; + +/** + * Send and receive messages from <a href="https://rocketmq.apache.org/">RocketMQ</a> cluster. + */ +@UriEndpoint(firstVersion = "3.20.0", scheme = "rocketmq", syntax = "rocketmq:topicName", title = "RocketMQ", + category = Category.MESSAGING, headersClass = RocketMQConstants.class) +public class RocketMQEndpoint extends DefaultEndpoint implements AsyncEndpoint { + + @UriPath + @Metadata(required = true) + private String topicName; + @UriParam(label = "producer") + private String producerGroup; + @UriParam(label = "consumer") + private String consumerGroup; + @UriParam(label = "consumer", defaultValue = "*") + private String subscribeTags = "*"; + @UriParam(label = "producer") + private String sendTag = ""; + @UriParam(label = "producer") + private String replyToTopic; + @UriParam(label = "producer") + private String replyToConsumerGroup; + @UriParam(label = "common", defaultValue = "localhost:9876") + private String namesrvAddr = "localhost:9876"; + @UriParam(label = "advance", defaultValue = "10000") + private long requestTimeoutMillis = 10000L; + @UriParam(label = "advance", defaultValue = "1000") + private long requestTimeoutCheckerIntervalMillis = 1000L; + @UriParam(label = "producer", defaultValue = "false") + private boolean waitForSendResult; + @UriParam(label = "accessKey") + private String accessKey; + @UriParam(label = "secretKey") Review Comment: label = security, secret = true ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQProducer.java: ########## @@ -0,0 +1,231 @@ +/* + * 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.rocketmq; + +import java.util.Arrays; +import java.util.Optional; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.camel.AsyncCallback; +import org.apache.camel.Exchange; +import org.apache.camel.FailedToCreateProducerException; +import org.apache.camel.NoTypeConversionAvailableException; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.rocketmq.reply.ReplyManager; +import org.apache.camel.component.rocketmq.reply.RocketMQReplyManagerSupport; +import org.apache.camel.support.DefaultAsyncProducer; +import org.apache.camel.support.service.ServiceHelper; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.client.producer.SendCallback; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.client.producer.SendStatus; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.remoting.exception.RemotingException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RocketMQProducer extends DefaultAsyncProducer { + + public static final String GENERATE_MESSAGE_KEY_PREFIX = "camel-rocketmq-"; + + private static final Logger LOG = LoggerFactory.getLogger(RocketMQProducer.class); + + private final AtomicBoolean started = new AtomicBoolean(false); + + private DefaultMQProducer mqProducer; + + private ReplyManager replyManager; + + public RocketMQProducer(RocketMQEndpoint endpoint) { + super(endpoint); + } + + @Override + public RocketMQEndpoint getEndpoint() { + return (RocketMQEndpoint) super.getEndpoint(); + } + + @Override + public boolean process(Exchange exchange, AsyncCallback callback) { + if (!isRunAllowed()) { + if (exchange.getException() == null) { + exchange.setException(new RejectedExecutionException()); + } + callback.done(true); + return true; + } + try { + LOG.trace("Exchange Pattern {}", exchange.getPattern()); + if (exchange.getPattern().isOutCapable()) { + return processInOut(exchange, callback); + } else { + return processInOnly(exchange, callback); + } + } catch (Throwable e) { + exchange.setException(e); + callback.done(true); + return true; + } + } + + protected boolean processInOut(final Exchange exchange, final AsyncCallback callback) + throws RemotingException, MQClientException, InterruptedException, NoTypeConversionAvailableException { + org.apache.camel.Message in = exchange.getIn(); + Message message = new Message(); + message.setTopic(in.getHeader(RocketMQConstants.OVERRIDE_TOPIC_NAME, () -> getEndpoint().getTopicName(), String.class)); + message.setTags(in.getHeader(RocketMQConstants.OVERRIDE_TAG, () -> getEndpoint().getSendTag(), String.class)); + message.setBody(exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, exchange, in.getBody())); + message.setKeys(in.getHeader(RocketMQConstants.OVERRIDE_MESSAGE_KEY, "", String.class)); + initReplyManager(); + String generateKey = GENERATE_MESSAGE_KEY_PREFIX + getEndpoint().getCamelContext().getUuidGenerator().generateUuid(); + message.setKeys(Arrays.asList(Optional.ofNullable(message.getKeys()).orElse(""), generateKey)); + LOG.debug("RocketMQ Producer sending {}", message); + mqProducer.send(message, new SendCallback() { + + @Override + public void onSuccess(SendResult sendResult) { + if (!SendStatus.SEND_OK.equals(sendResult.getSendStatus())) { + exchange.setException(new SendFailedException(sendResult.toString())); + callback.done(false); Review Comment: return; ########## components/camel-rocketmq/src/main/java/org/apache/camel/component/rocketmq/RocketMQProducer.java: ########## @@ -0,0 +1,231 @@ +/* + * 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.rocketmq; + +import java.util.Arrays; +import java.util.Optional; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.camel.AsyncCallback; +import org.apache.camel.Exchange; +import org.apache.camel.FailedToCreateProducerException; +import org.apache.camel.NoTypeConversionAvailableException; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.rocketmq.reply.ReplyManager; +import org.apache.camel.component.rocketmq.reply.RocketMQReplyManagerSupport; +import org.apache.camel.support.DefaultAsyncProducer; +import org.apache.camel.support.service.ServiceHelper; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.client.producer.SendCallback; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.client.producer.SendStatus; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.remoting.exception.RemotingException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RocketMQProducer extends DefaultAsyncProducer { + + public static final String GENERATE_MESSAGE_KEY_PREFIX = "camel-rocketmq-"; + + private static final Logger LOG = LoggerFactory.getLogger(RocketMQProducer.class); + + private final AtomicBoolean started = new AtomicBoolean(false); + + private DefaultMQProducer mqProducer; + + private ReplyManager replyManager; + + public RocketMQProducer(RocketMQEndpoint endpoint) { + super(endpoint); + } + + @Override + public RocketMQEndpoint getEndpoint() { + return (RocketMQEndpoint) super.getEndpoint(); + } + + @Override + public boolean process(Exchange exchange, AsyncCallback callback) { + if (!isRunAllowed()) { + if (exchange.getException() == null) { + exchange.setException(new RejectedExecutionException()); + } + callback.done(true); + return true; + } + try { + LOG.trace("Exchange Pattern {}", exchange.getPattern()); + if (exchange.getPattern().isOutCapable()) { + return processInOut(exchange, callback); + } else { + return processInOnly(exchange, callback); + } + } catch (Throwable e) { + exchange.setException(e); + callback.done(true); + return true; + } + } + + protected boolean processInOut(final Exchange exchange, final AsyncCallback callback) + throws RemotingException, MQClientException, InterruptedException, NoTypeConversionAvailableException { + org.apache.camel.Message in = exchange.getIn(); + Message message = new Message(); + message.setTopic(in.getHeader(RocketMQConstants.OVERRIDE_TOPIC_NAME, () -> getEndpoint().getTopicName(), String.class)); + message.setTags(in.getHeader(RocketMQConstants.OVERRIDE_TAG, () -> getEndpoint().getSendTag(), String.class)); + message.setBody(exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, exchange, in.getBody())); + message.setKeys(in.getHeader(RocketMQConstants.OVERRIDE_MESSAGE_KEY, "", String.class)); + initReplyManager(); + String generateKey = GENERATE_MESSAGE_KEY_PREFIX + getEndpoint().getCamelContext().getUuidGenerator().generateUuid(); + message.setKeys(Arrays.asList(Optional.ofNullable(message.getKeys()).orElse(""), generateKey)); + LOG.debug("RocketMQ Producer sending {}", message); + mqProducer.send(message, new SendCallback() { + + @Override + public void onSuccess(SendResult sendResult) { + if (!SendStatus.SEND_OK.equals(sendResult.getSendStatus())) { + exchange.setException(new SendFailedException(sendResult.toString())); + callback.done(false); + } + if (replyManager == null) { + LOG.warn("replyToTopic not set! Will not wait for reply."); + callback.done(false); + return; + } + replyManager.registerReply(replyManager, exchange, callback, generateKey, + getEndpoint().getRequestTimeoutMillis()); + } + + @Override + public void onException(Throwable e) { + replyManager.cancelMessageKey(generateKey); Review Comment: maybe use try .. finally to ensure callback is called if replymanager for some strange reason throw exception as callback MUST be called -- 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]
