2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
31 "oransc.org/nonrtric/dmaapmediatorproducer/internal/restclient"
34 var httpClient http.Client
37 httpClient = http.Client{
38 Timeout: time.Second * 5,
40 port := flag.Int("port", 40935, "The port this consumer will listen on")
42 http.HandleFunc("/jobs", handleData)
46 fmt.Println("Starting consumer on port: ", *port)
47 fmt.Println(http.ListenAndServe(fmt.Sprintf(":%v", *port), nil))
50 func registerJob(port int) {
52 JobOwner string `json:"job_owner"`
53 JobResultUri string `json:"job_result_uri"`
54 InfoTypeId string `json:"info_type_id"`
55 JobDefinition string `json:"job_definition"`
57 JobOwner: fmt.Sprintf("test%v", port),
58 JobResultUri: fmt.Sprintf("http://localhost:%v/jobs", port),
59 InfoTypeId: "STD_Fault_Messages",
62 fmt.Println("Registering consumer: ", jobInfo)
63 body, _ := json.Marshal(jobInfo)
64 putErr := restclient.Put(fmt.Sprintf("http://localhost:8083/data-consumer/v1/info-jobs/job%v", port), body, &httpClient)
66 fmt.Println("Unable to register consumer: ", putErr)
70 func handleData(w http.ResponseWriter, req *http.Request) {
71 defer req.Body.Close()
72 if reqData, err := io.ReadAll(req.Body); err == nil {
73 fmt.Println("Consumer received body: ", string(reqData))