mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-22 14:55:16 +00:00
Commit from m3o/m3o action
This commit is contained in:
@@ -16,7 +16,13 @@ type EventService struct {
|
|||||||
client *client.Client
|
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) {
|
func (t *EventService) Publish(request *PublishRequest) (*PublishResponse, error) {
|
||||||
rsp := &PublishResponse{}
|
rsp := &PublishResponse{}
|
||||||
return rsp, t.client.Call("event", "Publish", request, rsp)
|
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)
|
return rsp, t.client.Call("event", "Read", request, rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe to messages for a given topic.
|
type ConsumeRequest struct {
|
||||||
func (t *EventService) Subscribe(request *SubscribeRequest) (*SubscribeResponse, error) {
|
// Optional group for the subscription
|
||||||
rsp := &SubscribeResponse{}
|
Group string `json:"group"`
|
||||||
return rsp, t.client.Call("event", "Subscribe", request, rsp)
|
// 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 {
|
type Ev struct {
|
||||||
@@ -66,23 +86,3 @@ type ReadResponse struct {
|
|||||||
// the events
|
// the events
|
||||||
Events []Ev `json:"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"`
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Endpoints:
|
|||||||
|
|
||||||
## Publish
|
## Publish
|
||||||
|
|
||||||
Publish a message to the event stream.
|
Publish a event to the event stream.
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/event/api#Publish](https://m3o.com/event/api#Publish)
|
[https://m3o.com/event/api#Publish](https://m3o.com/event/api#Publish)
|
||||||
@@ -21,8 +21,8 @@ import(
|
|||||||
"go.m3o.com/event"
|
"go.m3o.com/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Publish a message to the event stream.
|
// Publish a event to the event stream.
|
||||||
func PublishAmessage() {
|
func PublishAnEvent() {
|
||||||
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||||
rsp, err := eventService.Publish(&event.PublishRequest{
|
rsp, err := eventService.Publish(&event.PublishRequest{
|
||||||
Message: map[string]interface{}{
|
Message: map[string]interface{}{
|
||||||
@@ -36,12 +36,12 @@ Topic: "user",
|
|||||||
fmt.Println(rsp, err)
|
fmt.Println(rsp, err)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
## Subscribe
|
## Consume
|
||||||
|
|
||||||
Subscribe to messages for a given topic.
|
Consume events from a given topic.
|
||||||
|
|
||||||
|
|
||||||
[https://m3o.com/event/api#Subscribe](https://m3o.com/event/api#Subscribe)
|
[https://m3o.com/event/api#Consume](https://m3o.com/event/api#Consume)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package example
|
package example
|
||||||
@@ -53,10 +53,10 @@ import(
|
|||||||
"go.m3o.com/event"
|
"go.m3o.com/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Subscribe to messages for a given topic.
|
// Consume events from a given topic.
|
||||||
func SubscribeToAtopic() {
|
func ConsumeFromAtopic() {
|
||||||
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||||
rsp, err := eventService.Subscribe(&event.SubscribeRequest{
|
rsp, err := eventService.Consume(&event.ConsumeRequest{
|
||||||
Topic: "user",
|
Topic: "user",
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
17
examples/event/consume/consumeFromATopic.go
Executable file
17
examples/event/consume/consumeFromATopic.go
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Consume events from a given topic.
|
||||||
|
func ConsumeFromAtopic() {
|
||||||
|
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := eventService.Consume(&event.ConsumeRequest{
|
||||||
|
Topic: "user",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
22
examples/event/publish/publishAnEvent.go
Executable file
22
examples/event/publish/publishAnEvent.go
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
package example
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go.m3o.com/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Publish a event to the event stream.
|
||||||
|
func PublishAnEvent() {
|
||||||
|
eventService := event.NewEventService(os.Getenv("M3O_API_TOKEN"))
|
||||||
|
rsp, err := eventService.Publish(&event.PublishRequest{
|
||||||
|
Message: map[string]interface{}{
|
||||||
|
"id": "1",
|
||||||
|
"type": "signup",
|
||||||
|
"user": "john",
|
||||||
|
},
|
||||||
|
Topic: "user",
|
||||||
|
})
|
||||||
|
fmt.Println(rsp, err)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user