Created
October 4, 2022 16:45
-
-
Save bbengfort/7bd668081109b76278e6b641e95ff6cf to your computer and use it in GitHub Desktop.
A quick ensign publisher routine.
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
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"log" | |
"time" | |
api "github.com/rotationalio/ensign/pkg/api/v1beta1" | |
mimetype "github.com/rotationalio/ensign/pkg/mimetype/v1beta1" | |
ensign "github.com/rotationalio/ensign/sdks/go" | |
) | |
func main() { | |
client, err := ensign.New(&ensign.Options{ | |
Endpoint: "flagship.rotational.dev:443", | |
}) | |
if err != nil { | |
log.Fatal(fmt.Errorf("could not create client: %s", err)) | |
} | |
pub, err := client.Publish(context.Background()) | |
if err != nil { | |
log.Fatal(fmt.Errorf("could not create publisher: %s", err)) | |
} | |
var seq uint64 | |
//Non blocking unless there is backpressure | |
ticker := time.NewTicker(750 * time.Millisecond) | |
for { | |
ts := <-ticker.C | |
seq++ | |
data := make(map[string]interface{}) | |
data["timestamp"] = ts | |
data["sequence"] = seq | |
e := &api.Event{ | |
TopicId: "test-topic", | |
Mimetype: mimetype.ApplicationJSON, | |
Type: &api.Type{ | |
Name: "Generic", | |
Version: 1, | |
}, | |
} | |
e.Data, _ = json.Marshal(data) | |
pub.Publish(e) | |
} | |
// sub, err := client.Subscribe(context.Background()) | |
// if err != nil { | |
// log.Fatal(err) | |
// } | |
// // Blocking will wait until next event comes | |
// event := sub.Subscribe() | |
// sub.Err() | |
// pub.Err() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment