Skip to content
Snippets Groups Projects
Commit 6282bc51 authored by Manuel Heß's avatar Manuel Heß
Browse files

initial version

parent 142ec0bd
No related branches found
No related tags found
No related merge requests found
.idea
\ No newline at end of file
protocol: nats
nats:
url: http://localhost:4222
timeoutInSec: 10
kafka:
url: localhost:9092
groupId: test
clientId: bugger
http:
url: http://localhost:8081/event
port: 8081
path: event
\ No newline at end of file
go.mod 0 → 100644
module bugger
go 1.20
require (
github.com/Azure/go-amqp v0.17.0 // indirect
github.com/Shopify/sarama v1.38.1 // indirect
github.com/cloudevents/sdk-go/protocol/amqp/v2 v2.14.0 // indirect
github.com/cloudevents/sdk-go/protocol/kafka_sarama/v2 v2.14.0 // indirect
github.com/cloudevents/sdk-go/protocol/mqtt_paho/v2 v2.0.0-20231030012137-0836a524e995 // indirect
github.com/cloudevents/sdk-go/protocol/nats/v2 v2.14.0 // indirect
github.com/cloudevents/sdk-go/protocol/nats_jetstream/v2 v2.14.0 // indirect
github.com/cloudevents/sdk-go/v2 v2.14.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/eapache/go-resiliency v1.4.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/eclipse/paho.golang v0.11.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nats-io/nats.go v1.31.0 // indirect
github.com/nats-io/nkeys v0.4.5 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.17.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
gitlab.eclipse.org/eclipse/xfsc/libraries/messaging/cloudeventprovider v0.0.7 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
go.sum 0 → 100644
This diff is collapsed.
main.go 0 → 100644
package main
import (
"gitlab.eclipse.org/eclipse/xfsc/libraries/messaging/cloudeventprovider"
"log"
"sync"
"time"
)
func publishExceptionMessage(c *cloudeventprovider.CloudEventProviderClient, tickDuration time.Duration, wg *sync.WaitGroup) {
for _ = range time.Tick(tickDuration) {
now := time.Now()
data := map[string]any{"exception": true, "error": "NullPointerException", "time": now}
event, err := cloudeventprovider.NewEvent("bugger/exception", "exception.v1", data)
if err != nil {
log.Fatal(err)
}
err = c.Pub(event)
if err != nil {
log.Fatalf("failed to send, %v", err)
} else {
log.Printf("published exception event")
}
}
wg.Done()
}
func publishSuccessMessage(c *cloudeventprovider.CloudEventProviderClient, tickDuration time.Duration, wg *sync.WaitGroup) {
for _ = range time.Tick(tickDuration) {
now := time.Now()
data := map[string]any{"success": true, "message": "permission granted", "time": now}
event, err := cloudeventprovider.NewEvent("bugger/success", "success.v1", data)
if err != nil {
log.Fatal(err)
}
if err := c.Pub(event); err != nil {
log.Fatalf("failed to send, %v", err)
} else {
log.Printf("published success event")
}
}
wg.Done()
}
func publishOfferMessage(c *cloudeventprovider.CloudEventProviderClient, tickDuration time.Duration, wg *sync.WaitGroup) {
for _ = range time.Tick(tickDuration) {
now := time.Now()
data := map[string]any{"twoFactor": map[string]any{"enabled": true, "recipientType": "email", "recipientAddress": "test@gmail.com"}, "ttl": 10 * time.Hour, "time": now}
event, err := cloudeventprovider.NewEvent("bugger/offer", "offer.v1", data)
if err != nil {
log.Fatal(err)
}
reply, err := c.Request(event, 30*time.Second)
if err != nil {
log.Fatalf("failed to send, %v", err)
} else {
log.Printf("published offer event and got reply: %v", reply)
}
}
wg.Done()
}
func main() {
cReq, err := cloudeventprovider.NewClient(cloudeventprovider.Req, "offers")
if err != nil {
log.Fatal(err)
}
defer cReq.Close()
cPub, err := cloudeventprovider.NewClient(cloudeventprovider.Pub, "events")
if err != nil {
log.Fatal(err)
}
defer cPub.Close()
var wg sync.WaitGroup
wg.Add(1)
go publishOfferMessage(cReq, 5*time.Second, &wg)
//go publishExceptionMessage(cPub, 10*time.Second, &wg)
//go publishSuccessMessage(cPub, 5*time.Second, &wg)
wg.Wait()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment