-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for rabbitmq broker (#56)
* rename nats url Signed-off-by: SammyOina <[email protected]> * use pubsub interface Signed-off-by: SammyOina <[email protected]> * add id Signed-off-by: SammyOina <[email protected]> * remove debug statement Signed-off-by: SammyOina <[email protected]> * update make Signed-off-by: SammyOina <[email protected]> * update deps Signed-off-by: SammyOina <[email protected]> * remove subject from msg Signed-off-by: SammyOina <[email protected]> * add example file and change topic Signed-off-by: SammyOina <[email protected]> * update documentation Signed-off-by: SammyOina <[email protected]> * minor fixes Signed-off-by: SammyOina <[email protected]> --------- Signed-off-by: SammyOina <[email protected]>
- Loading branch information
Showing
51 changed files
with
10,413 additions
and
84 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"log" | ||
"os" | ||
|
||
mflog "github.com/mainflux/mainflux/logger" | ||
"github.com/mainflux/mainflux/pkg/messaging" | ||
"github.com/mainflux/mainflux/pkg/messaging/brokers" | ||
"github.com/nats-io/nats.go" | ||
) | ||
|
||
func main() { | ||
var urls = flag.String("s", nats.DefaultURL, "The nats server URLs (separated by comma)") | ||
var showHelp = flag.Bool("h", false, "Show help message") | ||
|
||
log.SetFlags(0) | ||
flag.Usage = usage | ||
flag.Parse() | ||
|
||
if *showHelp { | ||
showUsageAndExit(0) | ||
} | ||
|
||
args := flag.Args() | ||
if len(args) != 2 { | ||
showUsageAndExit(1) | ||
} | ||
|
||
subj, msg := args[0], []byte(args[1]) | ||
|
||
logger, err := mflog.New(os.Stdout, "info") | ||
if err != nil { | ||
log.Fatalf("failed to init logger: %s", err) | ||
} | ||
|
||
ps, err := brokers.NewPublisher(*urls) | ||
if err != nil { | ||
logger.Error(err.Error()) | ||
return | ||
} | ||
defer ps.Close() | ||
|
||
if err := ps.Publish(context.Background(), subj, &messaging.Message{ | ||
Channel: subj, | ||
Payload: msg, | ||
}); err != nil { | ||
logger.Error(err.Error()) | ||
return | ||
} | ||
logger.Info("Message published") | ||
} | ||
|
||
func usage() { | ||
log.Printf("Usage: publish [-s server] <channel> <msg>\n") | ||
flag.PrintDefaults() | ||
} | ||
|
||
func showUsageAndExit(exitcode int) { | ||
usage() | ||
os.Exit(exitcode) | ||
} |
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
Oops, something went wrong.