subscribe()
Subscribe to realtime changes in your service.
- Javascript
- Go
kontenbase.realtime.subscribe('posts', { event: '*' }, (message) => {
if (message.error) {
console.log(message.error)
return
}
console.log(message.event, message.payload)
})
func onMessage (event string, payload map[string]interface{}) error {
fmt.Println(event)
return nil
}
func onError (event string, payload map[string]interface{}) error {
fmt.Println(payload)
return nil
}
func main() {
key, err := client.Realtime.Subscribe("Movies", options.SubscribeOptions{
Event: options.RealtimeAll,
OnMessage: onMessage,
OnError: onError,
})
}
Parameters
- Javascript
- Go
Name | Type | Required | Description |
serviceName | string | true | The service name to be subscribed |
condition | object | true | Condition consists of event and where |
condition.event | string | true | The event can be * , CREATE_RECORD , UPDATE_RECORD , DELETE_RECORD |
condition.where | object | false | Refering to filters docs |
Name | Type | Required | Description |
serviceName | string | true | The service name to be SubscribeOptions |
SubscribeOptions | struct | true | Subscribe Options consists of Event , Where , OnMessage , and OnError |
SubscribeOptions.Event | string | true | The event can be RealtimeAll , RealtimeCreate , RealtimeUpdate , RealtimeDelete , RealtimeError |
SubscribeOptions.Where | interface | false | Refering to filters docs |
SubscribeOptions.OnMessage | callback | false | Callback when receiving the message |
SubscribeOptions.OnError | callback | false | Callback when an error occurred |