bossenti commented on code in PR #139: URL: https://github.com/apache/incubator-streampipes/pull/139#discussion_r1020866035
########## streampipes-extensions/streampipes-sinks-brokers-jvm/src/main/java/org/apache/streampipes/sinks/brokers/jvm/rocketmq/RocketMQPublisherSink.java: ########## @@ -0,0 +1,123 @@ +/* + * 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.streampipes.sinks.brokers.jvm.rocketmq; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientConfigurationBuilder; +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.message.Message; +import org.apache.rocketmq.client.apis.producer.Producer; +import org.apache.streampipes.commons.exceptions.SpRuntimeException; +import org.apache.streampipes.dataformat.SpDataFormatDefinition; +import org.apache.streampipes.dataformat.json.JsonDataFormatDefinition; +import org.apache.streampipes.model.DataSinkType; +import org.apache.streampipes.model.graph.DataSinkDescription; +import org.apache.streampipes.model.runtime.Event; +import org.apache.streampipes.sdk.builder.DataSinkBuilder; +import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder; +import org.apache.streampipes.sdk.helpers.EpRequirements; +import org.apache.streampipes.sdk.helpers.Labels; +import org.apache.streampipes.sdk.helpers.Locales; +import org.apache.streampipes.sdk.utils.Assets; +import org.apache.streampipes.wrapper.context.EventSinkRuntimeContext; +import org.apache.streampipes.wrapper.standalone.SinkParams; +import org.apache.streampipes.wrapper.standalone.StreamPipesDataSink; + +import java.io.IOException; +import java.util.Map; + +public class RocketMQPublisherSink extends StreamPipesDataSink { + + public static final String TOPIC_KEY = "rocketmq-topic"; + public static final String ENDPOINT_KEY = "rocketmq-endpoint"; + + private ClientServiceProvider provider; + private Producer producer; + + private SpDataFormatDefinition spDataFormatDefinition; + private RocketMQParameters params; + + public RocketMQPublisherSink() { + this.provider = ClientServiceProvider.loadService(); + } + + @VisibleForTesting + public RocketMQPublisherSink(ClientServiceProvider provider) { + this.provider = provider; + } + + @Override + public DataSinkDescription declareModel() { + return DataSinkBuilder.create("org.apache.streampipes.sinks.brokers.jvm.rocketmq") + .category(DataSinkType.MESSAGING) + .withLocales(Locales.EN) + .withAssets(Assets.DOCUMENTATION, Assets.ICON) Review Comment: If you add assets here you need to provide them in the `resources` directory, e.g., see here: https://github.com/apache/incubator-streampipes/tree/dev/streampipes-extensions/streampipes-processors-change-detection-jvm/src/main/resources/org.apache.streampipes.processors.changedetection.jvm.welford Or am I blind and just overlooked these files? ########## streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/protocol/stream/rocketmq/RocketMQProtocol.java: ########## @@ -0,0 +1,174 @@ +/* + * 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.streampipes.connect.iiot.protocol.stream.rocketmq; + +import org.apache.commons.io.IOUtils; +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.consumer.ConsumeResult; +import org.apache.rocketmq.client.apis.consumer.PushConsumer; +import org.apache.streampipes.connect.SendToPipeline; +import org.apache.streampipes.connect.api.IAdapterPipeline; +import org.apache.streampipes.connect.api.IFormat; +import org.apache.streampipes.connect.api.IParser; +import org.apache.streampipes.connect.api.IProtocol; +import org.apache.streampipes.connect.api.exception.AdapterException; +import org.apache.streampipes.connect.api.exception.ParseException; +import org.apache.streampipes.connect.iiot.protocol.stream.BrokerProtocol; +import org.apache.streampipes.messaging.InternalEventProcessor; +import org.apache.streampipes.model.AdapterType; +import org.apache.streampipes.model.connect.grounding.ProtocolDescription; +import org.apache.streampipes.sdk.builder.adapter.ProtocolDescriptionBuilder; +import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor; +import org.apache.streampipes.sdk.helpers.AdapterSourceType; +import org.apache.streampipes.sdk.helpers.Labels; +import org.apache.streampipes.sdk.helpers.Locales; +import org.apache.streampipes.sdk.utils.Assets; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; + +public class RocketMQProtocol extends BrokerProtocol { + + public static final String ID = "org.apache.streampipes.connect.iiot.protocol.stream.rocketmq"; + + public static final String TOPIC_KEY = "rocketmq-topic"; + public static final String ENDPOINT_KEY = "rocketmq-endpoint"; + public static final String CONSUMER_GROUP_KEY = "rocketmq-consumer-group"; + + private Logger logger = LoggerFactory.getLogger(RocketMQProtocol.class); + + private String consumerGroup; + + private Thread thread; + private RocketMQConsumer rocketMQConsumer; + + public RocketMQProtocol() { + } + + public RocketMQProtocol(IParser parser, IFormat format, String brokerUrl, String topic, String consumerGroup) { + super(parser, format, brokerUrl, topic); + this.consumerGroup = consumerGroup; + } + + @Override + public IProtocol getInstance(ProtocolDescription protocolDescription, IParser parser, IFormat format) { + StaticPropertyExtractor extractor = StaticPropertyExtractor.from(protocolDescription.getConfig()); + String endpoint = extractor.selectedSingleValue(ENDPOINT_KEY, String.class); + String topic = extractor.selectedSingleValue(TOPIC_KEY, String.class); + String consumerGroup = extractor.selectedSingleValue(CONSUMER_GROUP_KEY, String.class); + + return new RocketMQProtocol(parser, format, endpoint, topic, consumerGroup); + } + + @Override + public ProtocolDescription declareModel() { + return ProtocolDescriptionBuilder.create(ID) + .withAssets(Assets.DOCUMENTATION, Assets.ICON) Review Comment: same as commented at `RocketMQPublisherSink` applies here ########## streampipes-extensions/streampipes-sinks-brokers-jvm/src/main/java/org/apache/streampipes/sinks/brokers/jvm/rocketmq/RocketMQPublisherSink.java: ########## @@ -0,0 +1,123 @@ +/* + * 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.streampipes.sinks.brokers.jvm.rocketmq; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientConfigurationBuilder; +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.message.Message; +import org.apache.rocketmq.client.apis.producer.Producer; +import org.apache.streampipes.commons.exceptions.SpRuntimeException; +import org.apache.streampipes.dataformat.SpDataFormatDefinition; +import org.apache.streampipes.dataformat.json.JsonDataFormatDefinition; +import org.apache.streampipes.model.DataSinkType; +import org.apache.streampipes.model.graph.DataSinkDescription; +import org.apache.streampipes.model.runtime.Event; +import org.apache.streampipes.sdk.builder.DataSinkBuilder; +import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder; +import org.apache.streampipes.sdk.helpers.EpRequirements; +import org.apache.streampipes.sdk.helpers.Labels; +import org.apache.streampipes.sdk.helpers.Locales; +import org.apache.streampipes.sdk.utils.Assets; +import org.apache.streampipes.wrapper.context.EventSinkRuntimeContext; +import org.apache.streampipes.wrapper.standalone.SinkParams; +import org.apache.streampipes.wrapper.standalone.StreamPipesDataSink; + +import java.io.IOException; +import java.util.Map; + +public class RocketMQPublisherSink extends StreamPipesDataSink { + + public static final String TOPIC_KEY = "rocketmq-topic"; + public static final String ENDPOINT_KEY = "rocketmq-endpoint"; + + private ClientServiceProvider provider; + private Producer producer; + + private SpDataFormatDefinition spDataFormatDefinition; + private RocketMQParameters params; + + public RocketMQPublisherSink() { + this.provider = ClientServiceProvider.loadService(); + } + + @VisibleForTesting + public RocketMQPublisherSink(ClientServiceProvider provider) { + this.provider = provider; + } + + @Override + public DataSinkDescription declareModel() { + return DataSinkBuilder.create("org.apache.streampipes.sinks.brokers.jvm.rocketmq") + .category(DataSinkType.MESSAGING) + .withLocales(Locales.EN) + .withAssets(Assets.DOCUMENTATION, Assets.ICON) + .requiredStream(StreamRequirementsBuilder + .create() + .requiredProperty(EpRequirements.anyProperty()) + .build()) + .requiredTextParameter(Labels.withId(ENDPOINT_KEY)) Review Comment: It would be great if you could provide the corresponding labels and descriptions in a `strings.en` file, see here: https://github.com/apache/incubator-streampipes/blob/dev/streampipes-extensions/streampipes-processors-change-detection-jvm/src/main/resources/org.apache.streampipes.processors.changedetection.jvm.welford/strings.en I'm happy to assist if this is not self-explaining :) -- 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]
