-
Notifications
You must be signed in to change notification settings - Fork 14
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
NOISSUE - Add Readers and Consumers SDK #33
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f885f83
refactor: aligh bootstrap with new supermq architecture
felixgateru 5f7b12d
refactor: rename env variables
felixgateru 308325d
style: add empty line to config files and bootstrap docker compose file
felixgateru d66071d
refactor: add supermq sdk to magistrala sdk
felixgateru abcb21d
refactor: extend supermq sdk in magistrala sdk
felixgateru 48813b1
reafctor: update responses
felixgateru 197d241
feat: add readers and consumers sdk
felixgateru 8df4803
ci(messages.go): fix filename
felixgateru 3c24d99
feat: add readers sdk
felixgateru 4500290
refactor: remove notifier interface
felixgateru ebe52aa
refactor: remove notifier interface
felixgateru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Abstract Machines | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package notifiers | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/absmach/supermq/pkg/messaging" | ||
) | ||
|
||
// ErrNotify wraps sending notification errors. | ||
var ErrNotify = errors.New("error sending notification") | ||
|
||
// Notifier represents an API for sending notification. | ||
// | ||
//go:generate mockery --name Notifier --output=./mocks --filename notifier.go --quiet --note "Copyright (c) Abstract Machines" | ||
type Notifier interface { | ||
// Notify method is used to send notification for the | ||
// received message to the provided list of receivers. | ||
Notify(from string, to []string, msg *messaging.Message) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) Abstract Machines | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package sdk | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/absmach/supermq/pkg/errors" | ||
) | ||
|
||
const subscriptionEndpoint = "subscriptions" | ||
|
||
type Subscription struct { | ||
ID string `json:"id,omitempty"` | ||
OwnerID string `json:"owner_id,omitempty"` | ||
Topic string `json:"topic,omitempty"` | ||
Contact string `json:"contact,omitempty"` | ||
} | ||
|
||
func (sdk mgSDK) CreateSubscription(topic, contact, token string) (string, errors.SDKError) { | ||
sub := Subscription{ | ||
Topic: topic, | ||
Contact: contact, | ||
} | ||
data, err := json.Marshal(sub) | ||
if err != nil { | ||
return "", errors.NewSDKError(err) | ||
} | ||
|
||
url := fmt.Sprintf("%s/%s", sdk.usersURL, subscriptionEndpoint) | ||
|
||
headers, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated) | ||
if sdkerr != nil { | ||
return "", sdkerr | ||
} | ||
|
||
id := strings.TrimPrefix(headers.Get("Location"), fmt.Sprintf("/%s/", subscriptionEndpoint)) | ||
|
||
return id, nil | ||
} | ||
|
||
func (sdk mgSDK) ListSubscriptions(pm PageMetadata, token string) (SubscriptionPage, errors.SDKError) { | ||
url, err := sdk.withQueryParams(sdk.usersURL, subscriptionEndpoint, pm) | ||
if err != nil { | ||
return SubscriptionPage{}, errors.NewSDKError(err) | ||
} | ||
|
||
_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK) | ||
if sdkerr != nil { | ||
return SubscriptionPage{}, sdkerr | ||
} | ||
|
||
var sp SubscriptionPage | ||
if err := json.Unmarshal(body, &sp); err != nil { | ||
return SubscriptionPage{}, errors.NewSDKError(err) | ||
} | ||
|
||
return sp, nil | ||
} | ||
|
||
func (sdk mgSDK) ViewSubscription(id, token string) (Subscription, errors.SDKError) { | ||
url := fmt.Sprintf("%s/%s/%s", sdk.usersURL, subscriptionEndpoint, id) | ||
|
||
_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK) | ||
if err != nil { | ||
return Subscription{}, err | ||
} | ||
|
||
var sub Subscription | ||
if err := json.Unmarshal(body, &sub); err != nil { | ||
return Subscription{}, errors.NewSDKError(err) | ||
} | ||
|
||
return sub, nil | ||
} | ||
|
||
func (sdk mgSDK) DeleteSubscription(id, token string) errors.SDKError { | ||
url := fmt.Sprintf("%s/%s/%s", sdk.usersURL, subscriptionEndpoint, id) | ||
|
||
_, _, err := sdk.processRequest(http.MethodDelete, url, token, nil, nil, http.StatusNoContent) | ||
|
||
return err | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's OK to keep the Notifier service (CRUD for Subscriptions) in Magistrala, but please move the Notifier interface to SuperMQ
/consumers
package.