Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add set connections options functions #9

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

jobs:
ci:
name: Vet, lint and test
name: Vet, Lint, Test and Vulnerability Check
runs-on: ubuntu-latest
steps:
- name: Checkout repo
Expand All @@ -36,18 +36,17 @@ jobs:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
golangci-lint run --out-format=github-actions

- name: Vulnerability Check
uses: golang/govulncheck-action@v1
with:
go-package: ./...
go-version-input: ">=1.21.0"
check-latest: true

- name: Integration Tests
run: make test_integration

- name: Recovery Tests
run: make test_recovery

govulncheck:
runs-on: ubuntu-latest
name: Run govulncheck
steps:
- id: govulncheck
uses: golang/govulncheck-action@v1
with:
go-package: ./...
check-latest: true

2 changes: 1 addition & 1 deletion clarimq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ func Test_Integration_DeadLetterRetry(t *testing.T) {
handler := func(delivery *clarimq.Delivery) clarimq.Action {
requireEqual(t, testMessage, string(delivery.Body))

retryCount, _ := delivery.Headers["x-retry-count"].(int32)
retryCount, _ := delivery.Headers["x-retry-count"].(int32) //nolint:revive // test code

if retryCount < 2 {
return clarimq.NackDiscard
Expand Down
49 changes: 49 additions & 0 deletions connection_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,52 @@ func WithConnectionOptionMaxRecoveryRetries(maxRetries int) ConnectionOption {
func WithConnectionOptionBackOffFactor(factor int) ConnectionOption {
return func(options *ConnectionOptions) { options.BackOffFactor = factor }
}

// SetLoggers provides possibility to add loggers.
func (c *Connection) SetLoggers(loggers []*slog.Logger) {
if len(loggers) > 0 {
c.options.loggers = loggers
}
}

// SetReturnHandler provides possibility to set the json encoder.
func (c *Connection) SetEncoder(encoder JSONEncoder) {
if encoder != nil {
c.options.codec.Encoder = encoder
}
}

// SetReturnHandler provides possibility to set the json decoder.
func (c *Connection) SetDecoder(decoder JSONDecoder) {
if decoder != nil {
c.options.codec.Decoder = decoder
}
}

// SetReturnHandler provides possibility to add a return handler.
func (c *Connection) SetReturnHandler(returnHandler ReturnHandler) {
if returnHandler != nil {
c.returnHandler = returnHandler
}
}

// SetRecoveryInterval sets the recovery interval.
//
// Default: 1s.
func (c *Connection) SetRecoveryInterval(interval time.Duration) {
c.options.RecoveryInterval = interval
}

// SetMaxRecoveryRetries sets the limit for maximum retries.
//
// Default: 10.
func (c *Connection) SetMaxRecoveryRetries(maxRetries int) {
c.options.MaxRecoveryRetries = maxRetries
}

// SetBackOffFactor sets the exponential back-off factor.
//
// Default: 2.
func (c *Connection) SetBackOffFactor(factor int) {
c.options.BackOffFactor = factor
}
2 changes: 1 addition & 1 deletion publish_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type (
// could not be published due to a missing broker connection.
PublishingCache interface {
// Put adds a publishing to the cache.
Put(Publishing) error
Put(p Publishing) error
// PopAll gets all publishing's from the cache and removes them.
PopAll() ([]Publishing, error)
// Len returns the number of publishing in the cache.
Expand Down