mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Commit from GitHub Actions (Generate Clients & Examples)
This commit is contained in:
@@ -16,7 +16,13 @@ type EventService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
// Publish a message to the event stream.
|
||||
// Consume events from a given topic.
|
||||
func (t *EventService) Consume(request *ConsumeRequest) (*ConsumeResponse, error) {
|
||||
rsp := &ConsumeResponse{}
|
||||
return rsp, t.client.Call("event", "Consume", request, rsp)
|
||||
}
|
||||
|
||||
// Publish a event to the event stream.
|
||||
func (t *EventService) Publish(request *PublishRequest) (*PublishResponse, error) {
|
||||
rsp := &PublishResponse{}
|
||||
return rsp, t.client.Call("event", "Publish", request, rsp)
|
||||
@@ -28,10 +34,24 @@ func (t *EventService) Read(request *ReadRequest) (*ReadResponse, error) {
|
||||
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 ConsumeRequest 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 ConsumeResponse 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"`
|
||||
}
|
||||
|
||||
type Ev struct {
|
||||
@@ -66,23 +86,3 @@ 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.612"
|
||||
"version": "1.0.613"
|
||||
}
|
||||
6
examples/event/consume/curl/consumeFromATopic.sh
Executable file
6
examples/event/consume/curl/consumeFromATopic.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
curl "https://api.m3o.com/v1/event/Consume" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"topic": "user"
|
||||
}'
|
||||
17
examples/event/consume/go/consumeFromATopic.go
Executable file
17
examples/event/consume/go/consumeFromATopic.go
Executable file
@@ -0,0 +1,17 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/micro/services/clients/go/event"
|
||||
)
|
||||
|
||||
// Consume events from a given topic.
|
||||
func ConsumeFromAtopic() {
|
||||
eventService := event.NewEventService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := eventService.Consume(&event.ConsumeRequest{
|
||||
Topic: "user",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
12
examples/event/consume/node/consumeFromATopic.js
Executable file
12
examples/event/consume/node/consumeFromATopic.js
Executable file
@@ -0,0 +1,12 @@
|
||||
const { EventService } = require("m3o/event");
|
||||
|
||||
// Consume events from a given topic.
|
||||
async function consumeFromAtopic() {
|
||||
let eventService = new EventService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await eventService.consume({
|
||||
topic: "user",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
consumeFromAtopic();
|
||||
11
examples/event/publish/curl/publishAnEvent.sh
Executable file
11
examples/event/publish/curl/publishAnEvent.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
curl "https://api.m3o.com/v1/event/Publish" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $MICRO_API_TOKEN" \
|
||||
-d '{
|
||||
"message": {
|
||||
"id": "1",
|
||||
"type": "signup",
|
||||
"user": "john"
|
||||
},
|
||||
"topic": "user"
|
||||
}'
|
||||
22
examples/event/publish/go/publishAnEvent.go
Executable file
22
examples/event/publish/go/publishAnEvent.go
Executable file
@@ -0,0 +1,22 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/micro/services/clients/go/event"
|
||||
)
|
||||
|
||||
// Publish a event to the event stream.
|
||||
func PublishAnEvent() {
|
||||
eventService := event.NewEventService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := eventService.Publish(&event.PublishRequest{
|
||||
Message: map[string]interface{}{
|
||||
"id": "1",
|
||||
"type": "signup",
|
||||
"user": "john",
|
||||
},
|
||||
Topic: "user",
|
||||
})
|
||||
fmt.Println(rsp, err)
|
||||
}
|
||||
17
examples/event/publish/node/publishAnEvent.js
Executable file
17
examples/event/publish/node/publishAnEvent.js
Executable file
@@ -0,0 +1,17 @@
|
||||
const { EventService } = require("m3o/event");
|
||||
|
||||
// Publish a event to the event stream.
|
||||
async function publishAnEvent() {
|
||||
let eventService = new EventService(process.env.MICRO_API_TOKEN);
|
||||
let rsp = await eventService.publish({
|
||||
message: {
|
||||
id: "1",
|
||||
type: "signup",
|
||||
user: "john",
|
||||
},
|
||||
topic: "user",
|
||||
});
|
||||
console.log(rsp);
|
||||
}
|
||||
|
||||
publishAnEvent();
|
||||
@@ -12,9 +12,9 @@ func PublishAmessage() {
|
||||
mqService := mq.NewMqService(os.Getenv("MICRO_API_TOKEN"))
|
||||
rsp, err := mqService.Publish(&mq.PublishRequest{
|
||||
Message: map[string]interface{}{
|
||||
"id": "1",
|
||||
"type": "signup",
|
||||
"user": "john",
|
||||
"id": "1",
|
||||
},
|
||||
Topic: "events",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user