TeslaCN commented on code in PR #8820: URL: https://github.com/apache/camel/pull/8820#discussion_r1038985863
########## 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: I've refactored methods of RocketMQMessageConverter to static. Before I created a new instance every time because I thought the JVM could allocate instance of this class on stack. -- 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: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org