Skip to content

Commit

Permalink
NOISSUE - Add Readers and Consumers SDK (#33)
Browse files Browse the repository at this point in the history
* refactor: aligh bootstrap with new supermq architecture

Signed-off-by: Felix Gateru <[email protected]>

* refactor: rename env variables

Signed-off-by: Felix Gateru <[email protected]>

* style: add empty line to config files and bootstrap docker compose file

Signed-off-by: Felix Gateru <[email protected]>

* refactor: add supermq sdk to magistrala sdk

Signed-off-by: Felix Gateru <[email protected]>

* refactor: extend supermq sdk in magistrala sdk

Signed-off-by: Felix Gateru <[email protected]>

* reafctor: update responses

Signed-off-by: Felix Gateru <[email protected]>

* feat: add readers and consumers sdk

Signed-off-by: Felix Gateru <[email protected]>

* ci(messages.go): fix filename

Signed-off-by: Felix Gateru <[email protected]>

* feat: add readers sdk

Signed-off-by: Felix Gateru <[email protected]>

* refactor: remove notifier interface

Signed-off-by: Felix Gateru <[email protected]>

* refactor: remove notifier interface

Signed-off-by: Felix Gateru <[email protected]>

---------

Signed-off-by: Felix Gateru <[email protected]>
  • Loading branch information
felixgateru authored Jan 13, 2025
1 parent ec71a5e commit cd528e7
Show file tree
Hide file tree
Showing 35 changed files with 5,365 additions and 273 deletions.
6 changes: 3 additions & 3 deletions apidocs/openapi/notifiers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ info:
license:
name: Apache 2.0
url: https://github.com/absmach/magistrala/blob/main/LICENSE
version: 0.14.0
version: 0.15.1

servers:
- url: http://localhost:9014
Expand Down Expand Up @@ -44,7 +44,7 @@ paths:
"400":
description: Failed due to malformed JSON.
"401":
description: Missing or invalid access token provided.
description: Missing or invalid access token provided.
"403":
description: Failed to perform authorization over the entity.
"409":
Expand Down Expand Up @@ -278,7 +278,7 @@ components:
content:
application/health+json:
schema:
$ref: "./schemas/HealthInfo.yml"
$ref: "./schemas/health_info.yml"

securitySchemes:
bearerAuth:
Expand Down
4 changes: 2 additions & 2 deletions apidocs/openapi/readers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ info:
license:
name: Apache 2.0
url: https://github.com/absmach/magistrala/blob/main/LICENSE
version: 0.14.0
version: 0.15.1

servers:
- url: http://localhost:9003
Expand Down Expand Up @@ -292,7 +292,7 @@ components:
content:
application/health+json:
schema:
$ref: "./schemas/HealthInfo.yml"
$ref: "./schemas/health_info.yml"

securitySchemes:
bearerAuth:
Expand Down
2 changes: 1 addition & 1 deletion cmd/postgres-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"

chclient "github.com/absmach/callhome/pkg/client"
httpapi "github.com/absmach/magistrala/readers/api"
"github.com/absmach/magistrala/readers/postgres"
"github.com/absmach/supermq"
smqlog "github.com/absmach/supermq/logger"
Expand All @@ -23,7 +24,6 @@ import (
httpserver "github.com/absmach/supermq/pkg/server/http"
"github.com/absmach/supermq/pkg/uuid"
"github.com/absmach/supermq/readers"
httpapi "github.com/absmach/supermq/readers/api"
"github.com/caarlos0/env/v11"
"github.com/jmoiron/sqlx"
"golang.org/x/sync/errgroup"
Expand Down
2 changes: 1 addition & 1 deletion cmd/timescale-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"

chclient "github.com/absmach/callhome/pkg/client"
httpapi "github.com/absmach/magistrala/readers/api"
"github.com/absmach/magistrala/readers/timescale"
"github.com/absmach/supermq"
smqlog "github.com/absmach/supermq/logger"
Expand All @@ -23,7 +24,6 @@ import (
httpserver "github.com/absmach/supermq/pkg/server/http"
"github.com/absmach/supermq/pkg/uuid"
"github.com/absmach/supermq/readers"
httpapi "github.com/absmach/supermq/readers/api"
"github.com/caarlos0/env/v11"
"github.com/jmoiron/sqlx"
"golang.org/x/sync/errgroup"
Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package api
import (
"context"

notifiers "github.com/absmach/magistrala/consumers/notifiers"
apiutil "github.com/absmach/supermq/api/http/util"
notifiers "github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/supermq/pkg/errors"
"github.com/go-kit/kit/endpoint"
)
Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"strings"
"testing"

"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers/api"
"github.com/absmach/magistrala/consumers/notifiers/mocks"
"github.com/absmach/magistrala/internal/testsutil"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/consumers/notifiers"
smqlog "github.com/absmach/supermq/logger"
svcerr "github.com/absmach/supermq/pkg/errors/service"
"github.com/absmach/supermq/pkg/uuid"
Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"log/slog"
"time"

"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers"
)

var _ notifiers.Service = (*loggingMiddleware)(nil)
Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"context"
"time"

"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers"
"github.com/go-kit/kit/metrics"
)

Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"net/http"
"strings"

"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/supermq"
api "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/supermq/pkg/errors"
"github.com/go-chi/chi/v5"
kithttp "github.com/go-kit/kit/transport/http"
Expand Down
47 changes: 0 additions & 47 deletions consumers/notifiers/mocks/notifier.go

This file was deleted.

2 changes: 1 addition & 1 deletion consumers/notifiers/mocks/repository.go

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

2 changes: 1 addition & 1 deletion consumers/notifiers/mocks/service.go

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

2 changes: 1 addition & 1 deletion consumers/notifiers/postgres/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"strings"

"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/supermq/pkg/errors"
repoerr "github.com/absmach/supermq/pkg/errors/repository"
"github.com/jackc/pgerrcode"
Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/postgres/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"testing"

"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers/postgres"
"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/supermq/pkg/errors"
repoerr "github.com/absmach/supermq/pkg/errors/repository"
"github.com/stretchr/testify/assert"
Expand Down
9 changes: 4 additions & 5 deletions consumers/notifiers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/absmach/supermq"
"github.com/absmach/supermq/consumers"
notif "github.com/absmach/supermq/consumers/notifiers"
smqauthn "github.com/absmach/supermq/pkg/authn"
"github.com/absmach/supermq/pkg/errors"
svcerr "github.com/absmach/supermq/pkg/errors/service"
Expand Down Expand Up @@ -47,13 +46,13 @@ type notifierService struct {
authn smqauthn.Authentication
subs SubscriptionsRepository
idp supermq.IDProvider
notifier notif.Notifier
notifier consumers.Notifier
errCh chan error
from string
}

// New instantiates the subscriptions service implementation.
func New(authn smqauthn.Authentication, subs SubscriptionsRepository, idp supermq.IDProvider, notifier notif.Notifier, from string) Service {
func New(authn smqauthn.Authentication, subs SubscriptionsRepository, idp supermq.IDProvider, notifier consumers.Notifier, from string) Service {
return &notifierService{
authn: authn,
subs: subs,
Expand Down Expand Up @@ -132,7 +131,7 @@ func (ns *notifierService) ConsumeBlocking(ctx context.Context, message interfac
if len(to) > 0 {
err := ns.notifier.Notify(ns.from, to, msg)
if err != nil {
return errors.Wrap(notif.ErrNotify, err)
return errors.Wrap(consumers.ErrNotify, err)
}
}

Expand Down Expand Up @@ -166,7 +165,7 @@ func (ns *notifierService) ConsumeAsync(ctx context.Context, message interface{}
}
if len(to) > 0 {
if err := ns.notifier.Notify(ns.from, to, msg); err != nil {
ns.errCh <- errors.Wrap(notif.ErrNotify, err)
ns.errCh <- errors.Wrap(consumers.ErrNotify, err)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions consumers/notifiers/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"fmt"
"testing"

"github.com/absmach/magistrala/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers/mocks"
"github.com/absmach/magistrala/internal/testsutil"
"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/supermq/consumers"
smqmocks "github.com/absmach/supermq/consumers/mocks"
smqauthn "github.com/absmach/supermq/pkg/authn"
authnmocks "github.com/absmach/supermq/pkg/authn/mocks"
"github.com/absmach/supermq/pkg/errors"
Expand All @@ -32,7 +34,7 @@ const (
func newService() (notifiers.Service, *authnmocks.Authentication, *mocks.SubscriptionsRepository) {
repo := new(mocks.SubscriptionsRepository)
auth := new(authnmocks.Authentication)
notifier := new(mocks.Notifier)
notifier := new(smqmocks.Notifier)
idp := uuid.NewMock()
from := "exampleFrom"
return notifiers.New(auth, repo, idp, notifier, from), auth, repo
Expand Down Expand Up @@ -346,7 +348,7 @@ func TestConsume(t *testing.T) {
{
desc: "test fail",
msg: &errMsg,
err: notifiers.ErrNotify,
err: consumers.ErrNotify,
},
}

Expand Down
6 changes: 3 additions & 3 deletions consumers/notifiers/smpp/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package smpp
import (
"time"

"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/supermq/consumers"
"github.com/absmach/supermq/pkg/messaging"
"github.com/absmach/supermq/pkg/transformers"
"github.com/absmach/supermq/pkg/transformers/json"
Expand All @@ -15,7 +15,7 @@ import (
"github.com/fiorix/go-smpp/smpp/pdu/pdutext"
)

var _ notifiers.Notifier = (*notifier)(nil)
var _ consumers.Notifier = (*notifier)(nil)

type notifier struct {
transmitter *smpp.Transmitter
Expand All @@ -27,7 +27,7 @@ type notifier struct {
}

// New instantiates SMTP message notifier.
func New(cfg Config) notifiers.Notifier {
func New(cfg Config) consumers.Notifier {
t := &smpp.Transmitter{
Addr: cfg.Address,
User: cfg.Username,
Expand Down
6 changes: 3 additions & 3 deletions consumers/notifiers/smtp/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"

"github.com/absmach/magistrala/internal/email"
"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/supermq/consumers"
"github.com/absmach/supermq/pkg/messaging"
)

Expand All @@ -16,14 +16,14 @@ const (
contentTemplate = "A publisher with an id %s sent the message over %s with the following values \n %s"
)

var _ notifiers.Notifier = (*notifier)(nil)
var _ consumers.Notifier = (*notifier)(nil)

type notifier struct {
agent *email.Agent
}

// New instantiates SMTP message notifier.
func New(agent *email.Agent) notifiers.Notifier {
func New(agent *email.Agent) consumers.Notifier {
return &notifier{agent: agent}
}

Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/tracing/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package tracing
import (
"context"

"github.com/absmach/supermq/consumers/notifiers"
"github.com/absmach/magistrala/consumers/notifiers"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ require (
github.com/0x6flab/namegenerator v1.4.0
github.com/absmach/callhome v0.14.0
github.com/absmach/certs v0.0.0-20241209153600-91270de67b5a
github.com/absmach/supermq v0.16.1-0.20250110085603-df5d752c4b50
github.com/absmach/supermq v0.16.1-0.20250113091433-3a11b54394b2
github.com/authzed/authzed-go v1.2.1
github.com/authzed/grpcutil v0.0.0-20240123194739-2ea1e3d2d98b
github.com/caarlos0/env/v11 v11.3.1
github.com/eclipse/paho.mqtt.golang v1.5.0
github.com/fiorix/go-smpp v0.0.0-20210403173735-2894b96e70ba
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-chi/chi/v5 v5.2.0
github.com/go-kit/kit v0.13.0
github.com/gofrs/uuid/v5 v5.3.0
Expand All @@ -37,7 +36,7 @@ require (
go.opentelemetry.io/otel/trace v1.33.0
golang.org/x/sync v0.10.0
gonum.org/v1/gonum v0.15.1
google.golang.org/grpc v1.69.2
google.golang.org/grpc v1.69.4
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
moul.io/http2curl v1.0.0
)
Expand Down
Loading

0 comments on commit cd528e7

Please sign in to comment.