You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by GitBox <gi...@apache.org> on 2022/09/15 12:20:33 UTC

[GitHub] [incubator-eventmesh] horoc opened a new pull request, #1289: [ISSUE #1288] add go server RocketMQ consumer

horoc opened a new pull request, #1289:
URL: https://github.com/apache/incubator-eventmesh/pull/1289

   ### Motivation
   
   #1288 
   
   add go server RocketMQ consumer
   
   
   ### Modifications
   
   add go server RocketMQ consumer
   
   
   
   ### Documentation
   
   None
   


-- 
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: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] codecov[bot] commented on pull request #1289: [ISSUE #1288] add go server RocketMQ consumer

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #1289:
URL: https://github.com/apache/incubator-eventmesh/pull/1289#issuecomment-1248083985

   # [Codecov](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#1289](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (0f92381) into [eventmesh-server-go](https://codecov.io/gh/apache/incubator-eventmesh/commit/e5c57fa608d0b3e8fd053fb30216264e7f61c921?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (e5c57fa) will **decrease** coverage by `0.09%`.
   > The diff coverage is `n/a`.
   
   > :exclamation: Current head 0f92381 differs from pull request most recent head 6a3b4b7. Consider uploading reports for the commit 6a3b4b7 to get more accurate results
   
   ```diff
   @@                   Coverage Diff                    @@
   ##             eventmesh-server-go   #1289      +/-   ##
   ========================================================
   - Coverage                   9.99%   9.89%   -0.10%     
   + Complexity                   644     638       -6     
   ========================================================
     Files                        382     382              
     Lines                      23640   23636       -4     
     Branches                    2619    2615       -4     
   ========================================================
   - Hits                        2362    2338      -24     
   - Misses                     21057   21076      +19     
   - Partials                     221     222       +1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...tandalone/broker/task/HistoryMessageClearTask.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL3Rhc2svSGlzdG9yeU1lc3NhZ2VDbGVhclRhc2suamF2YQ==) | `29.41% <0.00%> (-17.65%)` | :arrow_down: |
   | [...mesh/connector/standalone/broker/MessageQueue.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbm5lY3Rvci1wbHVnaW4vZXZlbnRtZXNoLWNvbm5lY3Rvci1zdGFuZGFsb25lL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9ldmVudG1lc2gvY29ubmVjdG9yL3N0YW5kYWxvbmUvYnJva2VyL01lc3NhZ2VRdWV1ZS5qYXZh) | `32.46% <0.00%> (-7.80%)` | :arrow_down: |
   | [...ava/org/apache/eventmesh/common/utils/IPUtils.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZXZlbnRtZXNoL2NvbW1vbi91dGlscy9JUFV0aWxzLmphdmE=) | `33.33% <0.00%> (-6.49%)` | :arrow_down: |
   | [...g/apache/eventmesh/runtime/util/EventMeshUtil.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL3V0aWwvRXZlbnRNZXNoVXRpbC5qYXZh) | `58.08% <0.00%> (-5.89%)` | :arrow_down: |
   | [...rg/apache/eventmesh/runtime/trace/LogExporter.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL3RyYWNlL0xvZ0V4cG9ydGVyLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...l/tcp/client/recommend/EventMeshRecommendImpl.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvdGNwL2NsaWVudC9yZWNvbW1lbmQvRXZlbnRNZXNoUmVjb21tZW5kSW1wbC5qYXZh) | `0.00% <0.00%> (ø)` | |
   | [.../tcp/client/session/push/DownStreamMsgContext.java](https://codecov.io/gh/apache/incubator-eventmesh/pull/1289/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2NvcmUvcHJvdG9jb2wvdGNwL2NsaWVudC9zZXNzaW9uL3B1c2gvRG93blN0cmVhbU1zZ0NvbnRleHQuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] github-code-scanning[bot] commented on a diff in pull request #1289: [ISSUE #1288] add go server RocketMQ consumer

Posted by GitBox <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #1289:
URL: https://github.com/apache/incubator-eventmesh/pull/1289#discussion_r971965488


##########
eventmesh-server-go/plugin/connector/rocketmq/client/rocketmq_consumer.go:
##########
@@ -0,0 +1,159 @@
+// 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 client
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"github.com/apache/incubator-eventmesh/eventmesh-server-go/plugin/connector/rocketmq/constants"
+	"github.com/apache/rocketmq-client-go/v2"
+	"github.com/apache/rocketmq-client-go/v2/consumer"
+	"github.com/apache/rocketmq-client-go/v2/primitive"
+	"strconv"
+	"strings"
+)
+
+type SubscribeFunc func(context.Context, ...*primitive.MessageExt) (consumer.ConsumeResult, error)
+
+// RocketMQConsumer RocketMQ consumer interface
+type RocketMQConsumer interface {
+	Start() error
+	Shutdown() error
+	Subscribe(topic string, selector consumer.MessageSelector, f SubscribeFunc) error
+	Unsubscribe(topic string) error
+	Suspend()
+	Resume()
+	IsBroadCasting() bool
+}
+
+// RocketMQConsumerWrapper consumer wrapper of RocketMQ client
+type RocketMQConsumerWrapper struct {
+	options      []consumer.Option
+	consumer     rocketmq.PushConsumer
+	messageModel consumer.MessageModel
+}
+
+// NewRocketMQConsumerWrapper get a consumer wrapper of RocketMQ client
+func NewRocketMQConsumerWrapper(properties map[string]string) (RocketMQConsumer, error) {
+	consumerWrapper := &RocketMQConsumerWrapper{messageModel: consumer.Clustering}
+
+	options, err := consumerWrapper.getConsumerOptionsFromProperties(properties)
+	if err != nil {
+		return nil, err
+	}
+
+	rocketMQConsumer, err := rocketmq.NewPushConsumer(options...)
+	if err != nil {
+		return nil, err
+	}
+	consumerWrapper.consumer = rocketMQConsumer
+
+	return consumerWrapper, nil
+}
+
+// Start wrapper start function
+func (r *RocketMQConsumerWrapper) Start() error {
+	return r.consumer.Start()
+}
+
+// Shutdown wrapper shutdown function
+func (r *RocketMQConsumerWrapper) Shutdown() error {
+	return r.consumer.Shutdown()
+}
+
+// Subscribe wrapper subscribe function
+func (r *RocketMQConsumerWrapper) Subscribe(topic string, selector consumer.MessageSelector, f SubscribeFunc) error {
+	return r.consumer.Subscribe(topic, selector, f)
+}
+
+// Unsubscribe wrapper unsubscribe function
+func (r *RocketMQConsumerWrapper) Unsubscribe(topic string) error {
+	return r.consumer.Unsubscribe(topic)
+}
+
+// Suspend wrapper suspend function
+func (r *RocketMQConsumerWrapper) Suspend() {
+	r.consumer.Suspend()
+}
+
+// Resume wrapper resume function
+func (r *RocketMQConsumerWrapper) Resume() {
+	r.consumer.Resume()
+}
+
+// IsBroadCasting check if consumer mode is broadcasting
+func (r *RocketMQConsumerWrapper) IsBroadCasting() bool {
+	return r.messageModel == consumer.BroadCasting
+}
+
+// getConsumerOptionsFromProperties convert properties map to client options
+func (r *RocketMQConsumerWrapper) getConsumerOptionsFromProperties(properties map[string]string) ([]consumer.Option, error) {
+	clientConfig, err := getClientConfigFromProperties(properties)
+	if clientConfig == nil {
+		return nil, err
+	}
+	options := make([]consumer.Option, 0)
+
+	accessPoints := clientConfig.AccessPoints
+	if len(accessPoints) == 0 {
+		return nil, errors.New("fail to parse rocketmq consumer config, invalid access points")
+	}
+
+	// name server address
+	options = append(options, consumer.WithNameServer(strings.Split(accessPoints, ",")))
+
+	// max reconsume times
+	if len(clientConfig.MaxReconsumeTimes) != 0 {
+		maxReconsumeTimes, err := strconv.Atoi(clientConfig.MaxReconsumeTimes)
+		if err == nil {
+			options = append(options, consumer.WithMaxReconsumeTimes(int32(maxReconsumeTimes)))

Review Comment:
   ## Incorrect conversion between integer types
   
   Incorrect conversion of an integer with architecture-dependent bit size from [strconv.Atoi](1) to a lower bit size type int32 without an upper bound check.
   
   [Show more details](https://github.com/apache/incubator-eventmesh/security/code-scanning/6)



-- 
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: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


[GitHub] [incubator-eventmesh] walleliu1016 merged pull request #1289: [ISSUE #1288] add go server RocketMQ consumer

Posted by GitBox <gi...@apache.org>.
walleliu1016 merged PR #1289:
URL: https://github.com/apache/incubator-eventmesh/pull/1289


-- 
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: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org