MCPcopy Index your code
hub / github.com/Trendyol/go-dcp-couchbase

github.com/Trendyol/go-dcp-couchbase @v1.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.1 ↗ · + Follow
128 symbols 270 edges 19 files 1 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Go Dcp Couchbase Go Reference Go Report Card OpenSSF Scorecard

Go Dcp Couchbase streams documents from Couchbase Database Change Protocol (DCP) and writes to Couchbase bucket in near real-time.

Features

  • Less resource usage and higher throughput.
  • Update multiple documents for a DCP event(see Example).
  • Handling different DCP events such as expiration, deletion and mutation(see Example).
  • Managing batch configurations such as maximum batch, batch bytes, batch ticker durations.
  • Scale up and down by custom membership algorithms(Couchbase, KubernetesHa, Kubernetes StatefulSet or Static, see examples).
  • Easily manageable configurations.
  • See example package for mutateIn value with primitive types see Example).

Concepts

General Concept general

Merge at target bucket merge-buckets

Example

Struct Config

package main

import (
  "github.com/Trendyol/go-dcp-couchbase"
  "time"

  "github.com/Trendyol/go-dcp-couchbase/config"
  dcpConfig "github.com/Trendyol/go-dcp/config"
)

func main() {
  c, err := dcpcouchbase.NewConnectorBuilder(&config.Config{
    Dcp: dcpConfig.Dcp{
      Hosts:      []string{"localhost:8091"},
      Username:   "user",
      Password:   "password",
      BucketName: "dcp-test",
      Dcp: dcpConfig.ExternalDcp{
        Group: dcpConfig.DCPGroup{
          Name: "groupName",
          Membership: dcpConfig.DCPGroupMembership{
            RebalanceDelay: 3 * time.Second,
          },
        },
      },
      Metadata: dcpConfig.Metadata{
        Config: map[string]string{
          "bucket":     "dcp-test-meta",
          "scope":      "_default",
          "collection": "_default",
        },
        Type: "couchbase",
      },
      Debug: true,
    },
    Couchbase: config.Couchbase{
      Hosts:          []string{"localhost:8091"},
      Username:       "user",
      Password:       "password",
      BucketName:     "dcp-test-backup",
      BatchSizeLimit: 10,
      RequestTimeout: 10 * time.Second,
    },
  }).SetMapper(dcpcouchbase.DefaultMapper).Build()
  if err != nil {
    panic(err)
  }

  defer c.Close()
  c.Start()
}

Configuration

Dcp Configuration

Check out on go-dcp

Couchbase Specific Configuration

Variable Type Required Default Description
couchbase.hosts []string yes Couchbase connection urls
couchbase.username string yes Defines Couchbase username
couchbase.password string yes Defines Couchbase password
couchbase.bucketName string yes Defines Couchbase bucket name
couchbase.scopeName string no _default Defines Couchbase scope name
couchbase.collectionName string no _default Defines Couchbase collection name
couchbase.batchSizeLimit int no 2048 Maximum message count for batch, if exceed flush will be triggered.
couchbase.batchTickerDuration time.Duration no 10s Batch is being flushed automatically at specific time intervals for long waiting messages in batch.
couchbase.batchByteSizeLimit int, string no 10mb Maximum size(byte) for batch, if exceed flush will be triggered. 10mb is default.
couchbase.maxInflightRequests int no $batchSizeLimit Maximum request count for Couchbase
couchbase.writePoolSizePerNode int no 1 Write connection pool size per node
couchbase.requestTimeout time.Duration no 1m Maximum request waiting time
couchbase.secureConnection bool no false Enables secure connection.
couchbase.rootCAPath string no false Defines root CA path.
couchbase.connectionBufferSize uint no 20971520 Defines connectionBufferSize.
couchbase.connectionTimeout time.Duration no 1m Defines connectionTimeout.

Exposed metrics

Metric Name Description Labels Value Type
cbgo_couchbase_connector_latency_ms_current The latency in milliseconds from mutation creation in Couchbase to the completion of adding actions into the batch N/A Gauge
cbgo_couchbase_connector_mapper_latency_ms_current The latency in milliseconds of the mapper function execution N/A Gauge
cbgo_couchbase_connector_bulk_request_process_latency_ms_current The latency in milliseconds of the bulk write operation to the target Couchbase bucket N/A Gauge
cbgo_couchbase_connector_bulk_request_size_current The number of documents in the latest bulk write request N/A Gauge
cbgo_couchbase_connector_bulk_request_byte_size_current The total byte size of documents in the latest bulk write request N/A Gauge

For DCP related metrics see also.

Breaking Changes

Date taking effect Date announced Change How to check
December 29, 2023 December 29, 2023 Mapper first arg changed to couchbase.EventContext Compile project
November 14, 2023 November 14, 2023 Creating connector via builder Compile project

Contributing

Go Dcp Couchbase is always open for direct contributions. For more information please check our Contribution Guideline document.

License

Released under the MIT License.

Extension points exported contracts — how you extend this code

Connector (Interface)
(no doc) [1 implementers]
connector.go
TargetClient (Interface)
(no doc) [1 implementers]
couchbase/target_client.go
SinkResponseHandler (Interface)
(no doc) [1 implementers]
couchbase/sink_response_handler.go
Client (Interface)
(no doc) [1 implementers]
couchbase/client.go
Mapper (FuncType)
(no doc)
mapper.go

Core symbols most depended-on inside this repo

Close
called by 10
connector.go
Start
called by 9
connector.go
SetMapper
called by 7
connector.go
Build
called by 7
connector.go
NewSetAction
called by 3
couchbase/document.go
NewMutateInAction
called by 3
couchbase/document.go
flushMessages
called by 3
couchbase/processor.go
Execute
called by 3
couchbase/client.go

Shape

Method 72
Function 31
Struct 19
Interface 4
FuncType 1
TypeAlias 1

Languages

Go100%

Modules by API surface

couchbase/client.go24 symbols
connector.go23 symbols
couchbase/processor.go15 symbols
couchbase/document.go15 symbols
dcp_event_handler.go9 symbols
config/config.go7 symbols
couchbase/target_client.go6 symbols
metric/collector.go4 symbols
example/simple/main.go4 symbols
couchbase/sink_response_handler.go4 symbols
couchbase/event.go4 symbols
test/integration/integration_test.go2 symbols

For agents

$ claude mcp add go-dcp-couchbase \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page