mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Merge branch 'master' of ssh://github.com/micro/services
This commit is contained in:
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -77,5 +77,5 @@
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"version": "1.0.611"
|
||||
"version": "1.0.612"
|
||||
}
|
||||
6
examples/event/read/curl/readEventsOnATopic.sh
Executable file
6
examples/event/read/curl/readEventsOnATopic.sh
Executable file
@@ -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"
|
||||
}'
|
||||
17
examples/event/read/go/readEventsOnATopic.go
Executable file
17
examples/event/read/go/readEventsOnATopic.go
Executable file
@@ -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)
|
||||
}
|
||||
12
examples/event/read/node/readEventsOnATopic.js
Executable file
12
examples/event/read/node/readEventsOnATopic.js
Executable file
@@ -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();
|
||||
Reference in New Issue
Block a user