NOISSUE - Add Readers and Consumers SDK (#33)

* refactor: aligh bootstrap with new supermq architecture

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* refactor: rename env variables

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

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

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* refactor: add supermq sdk to magistrala sdk

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* refactor: extend supermq sdk in magistrala sdk

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* reafctor: update responses

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* feat: add readers and consumers sdk

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* ci(messages.go): fix filename

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* feat: add readers sdk

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* refactor: remove notifier interface

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

* refactor: remove notifier interface

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>

---------

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
Felix Gateru
2025-01-13 12:31:45 +03:00
committed by GitHub
parent ec71a5edfd
commit cd528e75d3
35 changed files with 5353 additions and 261 deletions
+1 -1
View File
@@ -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"
)
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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"
)
+1 -1
View File
@@ -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"
-47
View File
@@ -1,47 +0,0 @@
// Code generated by mockery v2.43.2. DO NOT EDIT.
// Copyright (c) Abstract Machines
package mocks
import (
messaging "github.com/absmach/supermq/pkg/messaging"
mock "github.com/stretchr/testify/mock"
)
// Notifier is an autogenerated mock type for the Notifier type
type Notifier struct {
mock.Mock
}
// Notify provides a mock function with given fields: from, to, msg
func (_m *Notifier) Notify(from string, to []string, msg *messaging.Message) error {
ret := _m.Called(from, to, msg)
if len(ret) == 0 {
panic("no return value specified for Notify")
}
var r0 error
if rf, ok := ret.Get(0).(func(string, []string, *messaging.Message) error); ok {
r0 = rf(from, to, msg)
} else {
r0 = ret.Error(0)
}
return r0
}
// NewNotifier creates a new instance of Notifier. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewNotifier(t interface {
mock.TestingT
Cleanup(func())
}) *Notifier {
mock := &Notifier{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
+1 -1
View File
@@ -7,7 +7,7 @@ package mocks
import (
context "context"
notifiers "github.com/absmach/supermq/consumers/notifiers"
notifiers "github.com/absmach/magistrala/consumers/notifiers"
mock "github.com/stretchr/testify/mock"
)
+1 -1
View File
@@ -7,7 +7,7 @@ package mocks
import (
context "context"
notifiers "github.com/absmach/supermq/consumers/notifiers"
notifiers "github.com/absmach/magistrala/consumers/notifiers"
mock "github.com/stretchr/testify/mock"
)
@@ -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"
@@ -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"
+4 -5
View File
@@ -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"
@@ -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,
@@ -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)
}
}
@@ -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)
}
}
}
+5 -3
View File
@@ -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"
@@ -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
@@ -346,7 +348,7 @@ func TestConsume(t *testing.T) {
{
desc: "test fail",
msg: &errMsg,
err: notifiers.ErrNotify,
err: consumers.ErrNotify,
},
}
+3 -3
View File
@@ -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"
@@ -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
@@ -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,
+3 -3
View File
@@ -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"
)
@@ -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}
}
+1 -1
View File
@@ -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"
)