Skip to content

Commit

Permalink
Rewrite async workflow queue provider component
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll committed Feb 8, 2024
1 parent be20d12 commit d2f6104
Show file tree
Hide file tree
Showing 26 changed files with 1,679 additions and 481 deletions.
3 changes: 1 addition & 2 deletions cmd/server/cadence/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/uber/cadence/common/archiver"
"github.com/uber/cadence/common/archiver/provider"
"github.com/uber/cadence/common/asyncworkflow/queue"
asyncworkflowprovider "github.com/uber/cadence/common/asyncworkflow/queue/provider"
"github.com/uber/cadence/common/blobstore/filestore"
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/config"
Expand Down Expand Up @@ -286,7 +285,7 @@ func (s *server) startService() common.Daemon {
params.BlobstoreClient = nil
}

params.AsyncWorkflowQueueProvider, err = queue.NewAsyncQueueProvider(s.cfg.AsyncWorkflowQueues, &asyncworkflowprovider.Params{Logger: params.Logger, MetricsClient: params.MetricsClient})
params.AsyncWorkflowQueueProvider, err = queue.NewAsyncQueueProvider(s.cfg.AsyncWorkflowQueues)
if err != nil {
log.Fatalf("error creating async queue provider: %v", err)
}
Expand Down
11 changes: 7 additions & 4 deletions common/asyncworkflow/queue/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

package queue

import "github.com/uber/cadence/common/messaging"
import (
"github.com/uber/cadence/common/asyncworkflow/queue/provider"
"github.com/uber/cadence/common/types"
)

type (
// Provider is used to get a queue for a given domain
// Provider is used to get a queue
Provider interface {
GetAsyncQueueProducer(domain string) (messaging.Producer, error)
GetAsyncQueueConsumer(domain string) (messaging.Consumer, error)
GetPredefinedQueue(string) (provider.Queue, error)
GetQueue(string, *types.DataBlob) (provider.Queue, error)
}
)
31 changes: 16 additions & 15 deletions common/asyncworkflow/queue/interface_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions common/asyncworkflow/queue/kafka/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package kafka

import (
"fmt"
"strings"

"github.com/Shopify/sarama"

Expand All @@ -32,18 +33,22 @@ import (
)

type (
QueueConfig struct {
Connection ConnectionConfig `yaml:"connection"`
queueConfig struct {
Connection connectionConfig `yaml:"connection"`
Topic string `yaml:"topic"`
}

ConnectionConfig struct {
connectionConfig struct {
Brokers []string `yaml:"brokers"`
TLS config.TLS `yaml:"tls"`
SASL config.SASL `yaml:"sasl"`
}
)

func (c *queueConfig) ID() string {
return fmt.Sprintf("kafka::%s/%s", c.Topic, strings.Join(c.Connection.Brokers, ","))
}

func newSaramaConfigWithAuth(tls *config.TLS, sasl *config.SASL) (*sarama.Config, error) {
saramaConfig := sarama.NewConfig()

Expand Down
83 changes: 83 additions & 0 deletions common/asyncworkflow/queue/kafka/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 Uber Technologies Inc.

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package kafka

import "testing"

func TestQueueConfigID(t *testing.T) {
tests := []struct {
name string
config queueConfig
expected string
}{
{
name: "single broker",
config: queueConfig{
Connection: connectionConfig{
Brokers: []string{"broker1:9092"},
},
Topic: "topic1",
},
expected: "kafka::topic1/broker1:9092",
},
{
name: "multiple brokers",
config: queueConfig{
Connection: connectionConfig{
Brokers: []string{"broker1:9092", "broker2:9092"},
},
Topic: "topic2",
},
expected: "kafka::topic2/broker1:9092,broker2:9092",
},
{
name: "no brokers",
config: queueConfig{
Connection: connectionConfig{
Brokers: []string{},
},
Topic: "topic3",
},
expected: "kafka::topic3/",
},
{
name: "empty topic",
config: queueConfig{
Connection: connectionConfig{
Brokers: []string{"broker1:9092"},
},
Topic: "",
},
expected: "kafka::/broker1:9092",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.config.ID()
if got != tt.expected {
t.Errorf("queueConfig.ID() = %v, want %v", got, tt.expected)
}
})
}
}
70 changes: 0 additions & 70 deletions common/asyncworkflow/queue/kafka/consumer.go

This file was deleted.

Loading

0 comments on commit d2f6104

Please sign in to comment.