diff --git a/clients/go/event/event.go b/clients/go/event/event.go index 7ea3117..6579b6c 100755 --- a/clients/go/event/event.go +++ b/clients/go/event/event.go @@ -22,12 +22,27 @@ func (t *EventService) Publish(request *PublishRequest) (*PublishResponse, error return rsp, t.client.Call("event", "Publish", request, rsp) } +// Read stored events +func (t *EventService) Read(request *ReadRequest) (*ReadResponse, error) { + rsp := &ReadResponse{} + return rsp, t.client.Call("event", "Read", request, rsp) +} + // Subscribe to messages for a given topic. func (t *EventService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) { rsp := &SubscribeResponse{} return rsp, t.client.Call("event", "Subscribe", request, rsp) } +type Ev struct { + // event id + Id string `json:"id"` + // event message + Message map[string]interface{} `json:"message"` + // event timestamp + Timestamp string `json:"timestamp"` +} + type PublishRequest struct { // The json message to publish Message map[string]interface{} `json:"message"` @@ -38,16 +53,36 @@ type PublishRequest struct { type PublishResponse struct { } +type ReadRequest struct { + // number of events to read; default 25 + Limit int32 `json:"limit"` + // offset for the events; default 0 + Offset int32 `json:"offset"` + // topic to read from + Topic string `json:"topic"` +} + +type ReadResponse struct { + // the events + Events []Ev `json:"events"` +} + type SubscribeRequest struct { // Optional group for the subscription Group string `json:"group"` + // Optional offset to read from e.g "2006-01-02T15:04:05.999Z07:00" + Offset string `json:"offset"` // The topic to subscribe to Topic string `json:"topic"` } type SubscribeResponse struct { + // Unique message id + Id string `json:"id"` // The next json message on the topic Message map[string]interface{} `json:"message"` + // Timestamp of publishing + Timestamp string `json:"timestamp"` // The topic subscribed to Topic string `json:"topic"` } diff --git a/clients/ts/package.json b/clients/ts/package.json index 535d358..038030d 100644 --- a/clients/ts/package.json +++ b/clients/ts/package.json @@ -77,5 +77,5 @@ "prepare": "npm run build" }, "types": "index.d.ts", - "version": "1.0.611" + "version": "1.0.612" } \ No newline at end of file diff --git a/examples/event/read/curl/readEventsOnATopic.sh b/examples/event/read/curl/readEventsOnATopic.sh new file mode 100755 index 0000000..5ca4f77 --- /dev/null +++ b/examples/event/read/curl/readEventsOnATopic.sh @@ -0,0 +1,6 @@ +curl "https://api.m3o.com/v1/event/Read" \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer $MICRO_API_TOKEN" \ +-d '{ + "topic": "user" +}' \ No newline at end of file diff --git a/examples/event/read/go/readEventsOnATopic.go b/examples/event/read/go/readEventsOnATopic.go new file mode 100755 index 0000000..356f91f --- /dev/null +++ b/examples/event/read/go/readEventsOnATopic.go @@ -0,0 +1,17 @@ +package example + +import ( + "fmt" + "os" + + "github.com/micro/services/clients/go/event" +) + +// Read stored events +func ReadEventsOnAtopic() { + eventService := event.NewEventService(os.Getenv("MICRO_API_TOKEN")) + rsp, err := eventService.Read(&event.ReadRequest{ + Topic: "user", + }) + fmt.Println(rsp, err) +} diff --git a/examples/event/read/node/readEventsOnATopic.js b/examples/event/read/node/readEventsOnATopic.js new file mode 100755 index 0000000..89561ac --- /dev/null +++ b/examples/event/read/node/readEventsOnATopic.js @@ -0,0 +1,12 @@ +const { EventService } = require("m3o/event"); + +// Read stored events +async function readEventsOnAtopic() { + let eventService = new EventService(process.env.MICRO_API_TOKEN); + let rsp = await eventService.read({ + topic: "user", + }); + console.log(rsp); +} + +readEventsOnAtopic();