In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to use Serverless services to quickly build IoT applications in the 5G era, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
On October 31, at the 2019 China International Information and Communications Exhibition, the Ministry of Industry and Information Technology announced the official launch of 5G commercial. The 5G commercial era is coming!
With the commercial application of 5G, the data transmission speed, response speed, connection data, data transmission volume, transmission reliability and other aspects have been significantly improved. The breakthrough of this technology makes the application scenarios in many fields truly implemented into the lives of ordinary people, including the Internet of things.
Although the concept of the Internet of things is very simple, which is to connect things with the Internet and exchange information and communicate, so as to realize the intelligence of everything, due to various reasons, commercial applications have not landed on a large scale. On the one hand, it is due to the limitations of network transmission and other reasons. Nowadays, with the advent of 5G, the application of the Internet of things is no longer limited at the network level, which better promotes the development of the Internet of things. For enterprises, it is particularly important to quickly build a commercial Internet of things service and seize the opportunity.
Serverless's series of product ecology allows users to be business-oriented, regardless of underlying server deployment and hosting capacity, with a short implementation cycle and no prepaid price to pay by usage. These characteristics are the only choice to adapt to the rapid construction of the Internet 5G era, and solve the technical problems while saving costs for enterprises.
Taking the following vehicle networking data as an example, let's take a look at how to use queue services to build a highly available and reliable non-service application. In vehicle networking applications, the client load may be expanded / reduced by 3 or 4 orders of magnitude within 24 hours. these features are naturally suitable for dynamic expansion and contraction of Serverless services and pay by quantity.
Case scenario: cars equipped with data collection sensors in the car network transmit driving data to the cloud, which uses the ability of queue service to cut peaks and fill valleys and dynamically expand and shrink to receive data, and then transfer it to Elasticsearch for better data retrieval and application, so as to provide users with better service or provide more business value for the company.
Requirements: queue service SDK, queue service access point address, Elasticsearch access point address (ES instance has been created), JD.com Cloud user AK/SK
Code language: GoStep1
Create queue service client and resource creation
1func CreateClient () * sqs.SQS {2 ses, _: = session.NewSession (& aws.Config {3 Region: aws.String ("cn-north-1"), 4 Credentials: credentials.NewStaticCredentials ("your AccessKey", 5 "your SecretKey", ""), 6 Endpoint: aws.String ("http://jqs.cn-north-1.jdcloud.com"), 7 DisableSSL: aws.Bool (true), 8}) 9 _ Err: = ses.Config.Credentials.Get () 10 if err! = nil {11 log.Fatal ("credential creation failed", err) 12} 13 client: = sqs.New (ses) 14 return client15} 1617func CreateQueueTask (name string) string {18 resp, err: = sqsClient.CreateQueue (& sqs.CreateQueueInput {19 QueueName: aws.String (name), 20}) 21 if err! = nil {22 log.Println ("CreateQueue Failed:" Err) 23 return "" 24} 25 return * resp.QueueUrl26} Step2
Each vehicle device sends a message
1func SendTask (url string, message interface {}) {2 body, _: = json.Marshal (message) 3 _, err: = sqsClient.SendMessage (& sqs.SendMessageInput {4 MessageBody: aws.String (string (body)), 5 QueueUrl: aws.String (url), 6}) 7 if err! = nil {8 log.Println ("SendMessage Failed:", err) 9 return10} 11 return12}
Test data:
Configuration of the test machine: CPU64, 256g memory, bandwidth 100Mbps (JD.com CVM)
Scenario: public network; single send- (JQS)
Step3
Pull messages from the queue service and transfer them to Elasticsearch
1func ReceiveMessageTask (url string) interface {} {2 result, err: = sqsClient.ReceiveMessage (& sqs.ReceiveMessageInput {3 AttributeNames: aws.StringSlice ([] string {"All"}), 4 MaxNumberOfMessages: aws.Int64 (1), 5 MessageAttributeNames: aws.StringSlice ([] string {"All"}), 6 QueueUrl: aws.String (url), 7 VisibilityTimeout: aws.Int64 (30) 8 WaitTimeSeconds: aws.Int64 (0), 9}) 10 log.Println (* result.Messages [0] .body) 11 if err! = nil {12 log.Println ("Receive Message Failed:", err) 13 return "14} 1516 if len (result.Messages) > 0 {17 _, delErr: = sqsClient.DeleteMessage (& sqs.DeleteMessageInput {18 QueueUrl: aws.String (url)) 19 ReceiptHandle: result.Messages [0] .ReceiptHandle, 20}) 21 if err! = nil {22 log.Println ("Delete Message Failed:", delErr) 23} 2425 message: = new (gpsMessage) 26 Err: = json.Unmarshal ([] byte (* result.Messages [0] .body), message) 27 if Err! = nil {28 log.Println ("Receive Message Unmarshal Failed") Err) 29 return "" 30} 31 return message32} 33 return "" 34} 3536func Build (url string, method string, body interface {}) [] byte {37 client: = & http.Client {} 38 / / sends a get request 39 bodyData, _: = json.Marshal (body) 40 request, _: = http.NewRequest (method, url, bytes.NewReader (bodyData)) 4142 request.Header.Set ("Accept") "application/json") 43 request.Header.Set ("Content-Type", "application/json") 44 / / receive the information returned by the server to the client 45 response, _: = client.Do (request) 46 r, _: = ioutil.ReadAll (response.Body) 47 return R48} 4950func PostMessageToES (p string, body interface {}) string {51 postReturn: = new (postRes) 52 postResponse: = Build (p, "POST") Body) 53 err: = json.Unmarshal (postResponse, postReturn) 54 if err! = nil {55 log.Println ("Unmarshal Failed", err) 56} 57 jsonS, _: = json.Marshal (postReturn) 58 log.Println ("postResult:", string (jsonS)) 59 return postReturn.Id60} Step4
Search for information by demand index from Elasticsearch
1func GetMessageFromES (p string) {2 message: = new (esMessage) 3 getResponse: = Build (p, "GET", nil) 4 log.Println ("getPath:", p) 5 Err: = json.Unmarshal (getResponse, message) 6 if Err! = nil {7 log.Println ("Unmarshal Failed", Err) 8} 9 jsonM, _: = json.Marshal (message) 10 log.Println ("getResult:", string (jsonM)) 11}
Example of the result:
We can retrieve the data according to the vehicle information and draw a dynamic map of the car, which can be used to help realize a variety of scenarios such as autopilot, dynamic navigation, vehicle health analysis and so on.
The above content is how to use Serverless services to quickly build IoT applications in the 5G era. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.