Overview
The Event Service allows you to receive alerts for certain events in the backend. You can subscribe to existing events that trigger based on things such as specific data being retrieved from an equipment or a timer event. You can also publish custom events that can be used by not only you but other plugins and drivers as well.
Protocol Documentation
Event RPC services and messages
Services
Messages
- CancelTimedPublishReply
- CancelTimedPublishRequest
- PublishReply
- PublishRequest
- SubscribeReply
- SubscribeRequest
- TimedPublishReply
- TimedPublishRequest
How To
- Creating a Client
Services
Method Name | Request Type | Response Type | Description |
Publish | PublishRequest | PublishReply |
Publish an event and alert all subscribers to the channel |
TimedPublish | TimedPublishRequest | TimedPublishReply |
TimedPublish an timed event and alert all subscribers to the channel |
CancelTimedPublish | CancelTimedPublishRequest | CancelTimedPublishReply |
TimedPublish an timed event and alert all subscribers to the channel |
Subscribe | SubscribeRequest stream | SubscribeReply stream |
Listen for an event on a specific channel |
Messages
CancelTimedPublishReply
Field | Type | Label | Description |
status | bool |
cancel status |
|
timed_publish_id | uint32 |
The unique ID of the timed publish event ID |
CancelTimedPublishRequest
Used to publish an timed event
Field | Type | Label | Description |
channel | string |
The channel to publish an event for. Ex. escalation-timeout |
|
id | uint32 |
The unique ID of the element to which the event is associated with. Ex. 5 |
PublishReply
Does not contain data
PublishRequest
Used to publish an event
Field | Type | Label | Description |
channel | string |
The channel to publish an event for. Ex. equipment-create |
|
id | uint64 |
The unique ID of the element to which the event is associated with. Ex. 5 |
|
data | string |
Data associated with this publish as a JSON string, (id, create, update, delete) |
SubscribeReply
Field | Type | Label | Description |
channel | string |
The channel to publish an event for. Ex. equipment-create |
|
id | uint64 |
The unique ID of the element to which the event is associated with. Ex. 5 |
|
data | string |
Data associated with this publish as a JSON string, (id, create, update, delete) |
SubscribeRequest
Used to subscribe to the event service and listen for an event to be published
Field | Type | Label | Description |
channels | string | repeated |
TimedPublishReply
Field | Type | Label | Description |
channel | string |
The channel to publish an event for. Ex. equipment-create |
|
id | uint32 |
The unique ID of the element to which the event is associated with. Ex. 5 |
TimedPublishRequest
Used to publish an timed event
Field | Type | Label | Description |
channel | string |
The channel to publish an event for. Ex. escalation-timeout |
|
id | uint32 |
The unique ID of the element to which the event is associated with. Ex. 5 |
|
event_time | string |
event publish timestamp |
|
repeat_at | string |
repeat publish event at |
|
interval | int64 |
interval time (seconds) |
|
repeat_count | int32 |
pubilish count |
How To
Creating a Client
A parameter client must be created to access the above RPC methods in the Parameters service. This section assumes you’ve created a basic client with the?Client Example?tutorial.
1 | <!--?php // Include the file that is generated from compiling the .proto files require 'alerts.php'; // Assumes the DAL docker container is running // Create a client that connects to the DAL server $client = new \services\AlertsClient("127.0.0.1:10000", array( 'credentials' => \Grpc\ChannelCredentials::createInsecure(),<br ?--> )); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | package main import ( "log" "fmt" // grpc is required to dial into the gRPC DAL server "google.golang.org/grpc" // Our compiled .proto files are in the services directory "github.com/gigaphoton/client/services" ) const ( // Local connection string to DAL, docker container needs to be running address = "127.0.0.1:10000" ) // Entry point for Go func main() { // Create a connection to the server conn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { grpclog.Fatalf("did not connect: %v", err) } defer conn.Close() // This automatically closes the connection at the end of the function // Create a client to use for RPC methods client := services.NewAlertsClient(conn) } |
Note that the client is named AlertsClient. For Go, this client will be created by calling the NewAlertsClient method and passing in the connection. This same pattern is used for all services. To get Users, the client will be UsersClient. The namespace will be based on the package directive in the .proto files.
You can now use the client object to call RPC methods on.