Skip to content

Commit

Permalink
update 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
guidfort committed Apr 6, 2023
1 parent 88a5b2b commit 12b7308
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
39 changes: 19 additions & 20 deletions pkg/sseclient/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Before we create SseClient, two things are needed:
1) Get authorization token
The token is a Bearer token, which is provied by ctrlX Identity Manager Component.
2) Create SSE subscription on the SSE Server on the Data Layer
The subscriptionID is generated at first on client side by using for example package uuid, this id then will be sent to the
server together with other SSE parameters especially nodelist by sending a POST request to the ctrlX Data Layer. The subscription
Expand All @@ -41,17 +40,17 @@ then will be created on the server side, and it can be accessed by using the sub
Let us now create a SseClient:
The function NewSseClient needs three parameters:
* the url is like "/automation/api/v2/events/<subscriptionID>",
* the token is like "Bearer eyJhbGciOiJIUxxx"
* the flag insecureSkipVerify has to be set to true if no corresponding certificate has been installed on the ctrlX CORE, which is usually not the case in delivery state.
* the url is like "/automation/api/v2/events/<subscriptionID>",
* the token is like "Bearer eyJhbGciOiJIUxxx"
* the flag insecureSkipVerify has to be set to true if no corresponding certificate has been installed on the ctrlX CORE, which is usually not the case in delivery state.
client := sseclient.NewSseClient(url, token, true)
Reading event data:
The function Subscribe starts GET request and then reads the event data continuouslly.
* The paramter context is used to cancell the reading loop
* The callback function of type SseReceiverFunc is used to handle the incoming event data.
* The paramter context is used to cancell the reading loop
* The callback function of type SseReceiverFunc is used to handle the incoming event data.
This function will only terminate in case of connection errors (err != nil) or if the subscription is terminated
by the main program side (err == nil).
Expand All @@ -62,20 +61,20 @@ by the main program side (err == nil).
The SSE Server sends following types of event and data
"event: update\n"
"id: ...\n"
"data: {"node":".....","timestamp":....,"type":"...","value":...}\n"
"\n"
"event: error\n"
"id: ...\n"
"data: {"type":".....","title":....,"status":...,"instance":"...","severity":""}\n"
"\n"
"event: keepalive\n"
"id: ...\n"
"data: {"timestamp":....}\n"
"\n"
"event: update\n"
"id: ...\n"
"data: {"node":".....","timestamp":....,"type":"...","value":...}\n"
"\n"
"event: error\n"
"id: ...\n"
"data: {"type":".....","title":....,"status":...,"instance":"...","severity":""}\n"
"\n"
"event: keepalive\n"
"id: ...\n"
"data: {"timestamp":....}\n"
"\n"
The new subscription should be created and the connection should be restablished if it is broken, the SSE Server on the
ctrlX Data Layer will delete the inactive existing subscription after a time period.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sseclient/sseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *SseClient) Subscribe(ctx context.Context, receiver SseReceiverFunc) err
for {
select {
case <-ctx.Done():
return nil
return ctx.Err()
default:
bytesRead, err := br.ReadBytes('\n')
if err == io.EOF {
Expand Down

0 comments on commit 12b7308

Please sign in to comment.