I am trying to implement a case where a client sends a POST request to subscribe to some service to a server.
The server has to respond with the subscription data, however after some time if there is a change in the subscription information in the server, the server has to send a notification to the client about the changes using the "nfStatusNotificationUri" in the request body ("nfStatusNotificationUri" in the JSON data below).
I do not know how to do this.
I have implemented the POST subscription part but have no idea how to implement the notification part.
Can anyone help me or give me some guidance onenter code here
how to do this.
This what I have done so far:
// server // functions
func (m *NfInstanceDataAccess) Insertsub(nfinstancesub Subscriptions) error {
err := db.C(COLLECTION).Insert(&nfinstancesub)
return err
}
func CreateNewSubscriptionPost(w http.ResponseWriter, r *http.Request) {
var nfinstancesub Subscriptions
id := uuid.New()
subscriptionID := id.String()
if r.Header.Get("Accept") != "application/json" {
WriteError(w, ErrNotAcceptable)
return
}
if err := json.NewDecoder(r.Body).Decode(&nfinstancesub); err != nil {
respondWithError(w, http.StatusBadRequest, "Invalid request payload")
return
}
nfinstancesub.ID = bson.NewObjectId()
nfinstancesub.SubscriptionID = subscriptionID
if err := da.Insertsub(nfinstancesub); err != nil {
respondWithError(w, http.StatusInternalServerError, err.Error())
return
}
w.Header().Set("Response-Code", "201")
w.Header().Set("Response-Desc", "Success")
w.Header().Set("Cache-Control", "max-age=2592000") // 30 days
respondWithJson(w, http.StatusCreated, nfinstancesub)
}
// Main function
func main() {
http.HandleFunc("/nnrf-nfm/v1/subscriptions, CreateNewSubscriptionPost)
log.Fatal(http.ListenAndServe(":8080", nil))
}
The JSON data to request subscription including the notification uri "nfStatusNotificationUri" field. Am using mongodb to store this JSON data request is sent.
{
"nfStatusNotificationUri": "string",
"subscriptionID": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"validityTime": "2019-02-11T09:45:52.015Z",
"reqNotifEvents": [
"NF_REGISTERED",
"string"
],
"plmnId": {
"mcc": "string",
"mnc": "string"
},
"notifCondition": {
"monitoredAttributes": [
"string"
],
"unmonitoredAttributes": [
"string"
]
},
"reqNfFqdn": "string"
}